Skip to content

Commit 03ca1cd

Browse files
Zülal BekerecioğluZülal Bekerecioğlu
authored andcommitted
Update files
1 parent 95fd460 commit 03ca1cd

3 files changed

Lines changed: 23 additions & 23 deletions

File tree

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ Imports:
5959
childsds,
6060
purrr,
6161
tibble,
62-
tidyselect
62+
tidyselect,
63+
stats,
64+
lubridate
6365
Suggests:
6466
testthat
6567
RoxygenNote: 7.3.3

R/dateDS.R

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
dateDS <- function(x=NULL, type=NULL,
3030
newobj=NULL, unit=NULL, add.column=NULL) {
3131

32-
library(lubridate)
3332
add.column <- as.logical(add.column)
3433

3534
# If argument not in c("extractdate", "makedate", "timebetween") throw an error
@@ -119,9 +118,9 @@ dateDS <- function(x=NULL, type=NULL,
119118

120119
# Extract the requested component
121120
result <- switch(unit,
122-
days = day(date_input),
123-
months = month(date_input),
124-
years = year(date_input),
121+
days = lubridate::day(date_input),
122+
months = lubridate::month(date_input),
123+
years = lubridate::year(date_input),
125124
stop("Invalid unit. Must be one of: days, months, years"))
126125
}
127126

@@ -141,7 +140,7 @@ dateDS <- function(x=NULL, type=NULL,
141140
}
142141

143142
if (any(year_vec < 1000 | year_vec > 3000, na.rm = TRUE)) {
144-
stop("The 'year' input in 'makedate' must contain plausible 4-digit years (10003000).
143+
stop("The 'year' input in 'makedate' must contain plausible 4-digit years (1000-3000).
145144
Check that year, month, and day are given in the correct order (year, month, day).", call. = FALSE)
146145
}
147146
if (any(month_vec < 1 | month_vec > 12, na.rm = TRUE)) {
@@ -154,9 +153,9 @@ dateDS <- function(x=NULL, type=NULL,
154153
}
155154

156155

157-
result <- make_date(year = year_vec,
158-
month = month_vec,
159-
day = day_vec)
156+
result <- lubridate::make_date(year = year_vec,
157+
month = month_vec,
158+
day = day_vec)
160159
}
161160

162161

@@ -166,12 +165,12 @@ dateDS <- function(x=NULL, type=NULL,
166165

167166
# inputs[[1]] = start date, inputs[[2]] = end date
168167
units <- list(
169-
years = years(1),
170-
months = months(1),
171-
days = days(1)
168+
years = lubridate::years(1),
169+
months = lubridate::months(1),
170+
days = lubridate::days(1)
172171
)
173172

174-
result <- interval(inputs[[1]], inputs[[2]]) %/% units[[unit]]
173+
result <- lubridate::interval(inputs[[1]], inputs[[2]]) %/% units[[unit]]
175174
}
176175

177176
# Save result based on add.column

R/predictDS.R

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ predictDS <- function(newdataname, traindataname, type = c("response", "link"),
7171

7272
# SPECIAL CASE HANDLING: y ~ 1, intercept only ######################
7373
# A numeric vector will be created wit the mean, with the same length as the row number in newdataname
74-
special_case <- length(attr(terms(formula(model_formula)), "term.labels")) == 0
74+
special_case <- length(attr(stats::terms(stats::formula(model_formula)), "term.labels")) == 0
7575

7676
if(special_case){
7777
intercept <- coefficients
7878

7979
# If the input is just a numeric vector, get the length
80-
if(class(newdf)=="numeric"){
80+
if(all(c("numeric") %in% class(newdf))){
8181
predictions.f <- rep(intercept, length(newdf))
82-
} else if(class(newdf)=="data.frame"){
82+
} else if(all(c("data.frame") %in% class(newdf))){
8383
predictions.f <- rep(intercept, nrow(newdf)) # Otherwise use the number of rows
8484
} else {
8585
stop("Invalid input: The object called 'newdataname' must be either a numeric vector or a data.frame.",, call. = FALSE)
@@ -95,7 +95,7 @@ predictDS <- function(newdataname, traindataname, type = c("response", "link"),
9595
predictions.f <- exp(predictions.f)
9696
} else if (family_name == "binomial") {
9797
# logit
98-
predictions.f <- plogis(predictions.f)
98+
predictions.f <- stats::plogis(predictions.f)
9999
} else {
100100
stop("Unsupported family for intercept-only prediction: Family must be either Gaussian, Poisson, or Binomial.", call. = FALSE)
101101
}
@@ -121,18 +121,17 @@ predictDS <- function(newdataname, traindataname, type = c("response", "link"),
121121
na.action.fun <- match.fun(na.action)
122122

123123
# Use a dummy glm object with the correct formula and family
124-
dummy_fit <- glm(model_formula,
125-
data = traindata,
126-
family = family_obj,
127-
control = glm.control(maxit = 1))
124+
dummy_fit <- stats::glm(model_formula,
125+
data = traindata,
126+
family = family_obj,
127+
control = stats::glm.control(maxit = 1))
128128

129129
# Change its coefficients with the correct ones
130130
names(coefficients) <- names(dummy_fit$coefficients)
131131
dummy_fit$coefficients <- coefficients
132132

133133
# New predictions
134-
prediction <- predict(dummy_fit, newdata = newdf, type = type, na.action = na.action.fun)
134+
prediction <- stats::predict(dummy_fit, newdata = newdf, type = type, na.action = na.action.fun)
135135

136136
return(prediction)
137137
}
138-

0 commit comments

Comments
 (0)