I\'m struggling to understand why does this doesn\'t work.
df <- data.frame(a=1:10, b=1:10)
foo <- function(obj, col) {
with(obj, ls())
with(obj
Anything that is passed to a function must be an object, a string or a number. There are two problems with this:
What you want is more like:
foo <- function(obj, col) {
print(with(obj, ls()))
with(obj, print(obj[[col]]))
}
foo(df, "a")
Or if you're only looking for the one column to be printed:
foo <- function(obj, col) {
with(obj, print(obj[[col]]))
}
foo(df, "a")