I would like to create a higher level function that wrap a mutate. I want to give an expression parameter to my function and being able to use this expression in mutate :
datas <- data.frame(x = sample(100))
fn <- function(datas, expr) {
mutate(datas, flag = eval(substitute(expr), datas))
}
fn(datas[1], x > 50)
Error in mutate_impl(.data, dots) : object 'x' not found
But I don't understand why it fails since mutate(datas, flag = eval(substitute(x > 50), datas))
works.
What am I doing wrong ?
Thanks
Try this:
or (preferably) this: