There are simple solutions such as:
> deparse(substitute(data))
[1] "data"
But it does not quite work when I want to extract name from a list:
> deparse(substitute(names(data)[1]))
[1] "names(data)[1]"
So the problem is that I want this as a general solution for every variable in a list/data frame/numeric that I feed into some function. And I want to see names of those variables as column names for output data frame.
Such as:
foo <- function(...) {
data <- list(...)
## some magic here ##
names(output_df) <- ??
output_df
}
And keep in mind that some numerics that are fed into ... don't come with names attribute. This is probably the whole reason why I want to use their environment name as column name in output data frame.
data <- list( "hello" , "world" )or whatevername()function ? If you don't, you should provide an example, as Simon says.