I know the deparse+substitute trick to get the name from an object passed as argument to a function, but the same trick inside a loop does no work.
My code (just for testing):
mylist <- list(first = c("lawyer","janitor"), second = c("engineer","housewife"))
for (element in names(mylist)){
print(deparse(substitute(mylist[[element]])))
}
[1] "mylist[[element]]"
[1] "mylist[[element]]"
is there any way of getting the result?:
first
second
print(element)..names(mylist)?