r - plyr functions and standard evaluation -
i wrap plyr functions in own functions. want pass function object , variable (unquoted) on apply cut function.
x <- data.frame(time = seq(sys.date() - 99, sys.date(), 1)) dlply(x, .(week = cut(time, "1 week")), "[") f <- function(datas, var) { var <- deparse(substitute(var)) dlply(x, .(week = cut(var, "1 week")), "[") } f(x, time) # fail
i don't know how use object var specify variable value , not "var" variable, within ddply.
unlike in dplyr there no standard evaluation versions of plyr functions ? read can use strings, example dlply(x, .(week = cut("time", "1 week")), "[")
fails
i tried lazyeval, i'm lost in standard/non standard evaluation universe.
you seem have unnecessary deparse
in code , don't evaluate var
in right place. works following.
f <- function(datas, var) { var <- substitute(var) dlply(datas, .(week = cut(eval(var), "1 week")), "[") }
Comments
Post a Comment