I've browsed around other questions and know that in most cases, I can just directly pass the column name as a string and then use d[,column] to access the values. However, I'm unable to get it to work in my function that uses piped statements (the function takes the given column and rounds values to the nearest 20):
fun = function(mydata, column) {
new = mydata %>%
mutate(time = plyr::round_any(column, #also tried mydata[,column]
20, f = floor))
return(new)
}
Any suggestions on how to do this?
In reference to joran's answer below: how might I be able to add in column names passed as arguments between column names that remain constant? What function does quote have?
E.g.
fun2 = function(d, column, column2) {
d %>%
mutate_(time = interp(quote(plyr::round_any(var,20,f = floor)),
var = as.name(column))) %>%
count_(CONSTANT_COL_NAME, interp(var, var=as.name(column2)), CONSTANT_COL_NAME2) #Line in question
}