lapply and the save function in R -


i have created list of objects in work environment

data <- c("variable1", "variable2", "variable3") 

i save files different directories variable name directory... did give me list of file names pass save function via lapply..

paste0(data,"/",data,".rda")   lapply(data,fun=save,file = paste0(data,"/",data,".rda")) 

i error

error in fun(x[[i]], ...) : object ‘x[[i]]’ not found 

i'm not sure i'm doing wrong here..

do have list of objects, or list of names of objects? have former, code give latter.

also, if have 1 object per file, it's better use saverds function (and loadrds load it).

lapply(data, function(x) saverds(get(x), paste0(x, "/", x, ".rds"))) 

if have use save:

lapply(data, function(x) save(list=x, file=paste0(x, "/", x, ".rds")))