I had written a function that creates lag transformation for variables in data frame. Now as dplyr has soft depreciated funs_ argument, it's giving me warning to use list in place of funs_. below given is my lag transformation function which is working fine but I want to modify it using updated argument list.
lagTransformation<- function(ds,n)
{
# this function creats lag transformation of dataframe
# args:
# ds : Dataset
# n : number of lags
require(dplyr)
lags <- seq(n)
lag_names <- paste("lag", formatC(lags, width = nchar(max(lags)), flag = "0"), sep = "")
lag_functions <- setNames(paste("dplyr::lag(., ", lags, ")"), lag_names)
ds <-ds %>% mutate_at(vars(names(ds)), funs_(lag_functions)) %>% select(contains("_lag"))
return(ds)
}
Tried replacing funs_ with list but got an error
lagTransformation<- function(ds,n)
{
# this function creats lag transformation of dataframe
# args:
# ds : Dataset
# n : number of lags
require(dplyr)
lags <- seq(n)
lag_names <- paste("lag", formatC(lags, width = nchar(max(lags)), flag = "0"), sep = "")
lag_functions <- setNames(paste("dplyr::lag(., ", lags, ")"), lag_names)
ds <-ds %>% mutate_at(vars(names(ds)), list(~.lag_functions)) %>% select(contains("_lag"))
return(ds)
}
Error in get(.x, .env, mode = "function") : object 'dplyr::lag(., 1 )' of mode 'function' was not found
referred below question but not able to rectify the error
Create new variables with mutate_at while keeping the original ones
what modification I need?