Using a parameter as a variable name inside a function in R

r

Solution

Use the `list` argument of `save()`:

save(list=substr(month,1,3), file="data.rda")

Problem

I am trying to incorporate the name of the month in the name of the variable being stored. ``` import <- function(month) { dataobj <- letters assign("x", dataobj) save("x", file="data.rda") } ``` works. But the following doesn't work - ``` import <- function(month) { dataobj <- letters assign(substr(month, 1, 3), dataobj) save(substr(month, 1, 3), file="data.rda") } ``` It seems that save() will accept "x" but not substr(month, 1, 3). Any ideas how to fix this?

Original source