Say I want to write a function that returns the name of the object passed into it.
The below works fine, returning the string "testlist":
testlist<-c("a","b","c")
H<-function(x){
name<-deparse(substitute(x))
return(name)
}
H(testlist)
> H(testlist)
[1] "testlist"
However, when using map (or lapply) with the list input:
map(testlist,H)
> map(testlist,H)
[[1]]
[1] ".x[[i]]"
[[2]]
[1] ".x[[i]]"
[[3]]
[1] ".x[[i]]"
What I was hoping to see was:
map(testlist,H)
> map(testlist,H)
[[1]]
[1] "testlist"
[[2]]
[1] "testlist"
[[3]]
[1] "testlist"