I have a question, I am making a package in R (just for me).
So I am scripting my function sets and inside sets I use a lot of dplyr functions.
How can I make that if you're gonna use my package you must have dplyr.
I think is with require() inside the function? I was reading about this function and got more confused.
I was thinking it should go like this:
sets <- function(base, start, end, f_hor, freq=12){
require(dplyr, lubridate)
train <- base %>%
filter(year(date)>=as.Date(start)) %>%
filter(year(date)<=as.Date(end)) %>% select(-date)
train <- ts(train,
start=c(year(as.Date(start)),month(as.Date(start))),
end=c(year(as.Date(end)),month(as.Date(end))),
frequency = freq)
test <- base %>%
filter(year(date)<as.Date(end)) %>% select(-date)
test <- head(test, f_hor)
list <- list(train, test)
names(list) <- c("train", "test")
return(list)
}
Am I right?
Thanks in advance!