Dear list member,

I think that I have detected a strange behavior of the save() command:

> year <- "2000"
> assign(paste0("Var_", year), list(A=10, B=20))
> get(paste0("Var_", year))
[1] 10

[1] 20

# At this point all is ok, I have created a list of name Var_2000

> save(paste0("Var_", year), file=paste0("Var_", year, ".Rdata"))
Error in save(paste0("Var_", year), file = paste0("Var_", year, ".Rdata")) :
  objet ‘paste0("Var_", year)’ introuvable

(introuvable=cannot be found)


> save("Var_2000", file=paste0("Var_", year, ".Rdata"))

When I read the help for save: ?save

...    the names of the objects to be saved (as symbols or character strings).

I checked if paste0("Var_", year) produced a character string:

> str("Var_2000")
 chr "Var_2000"
> str(paste0("Var_", year))
 chr "Var_2000"

The solution was to include the name in the list argument:

> save(list=paste0("Var_", year), file=paste0("Var_", year, ".Rdata"))

But I don't understand what is the difference between "Var_2000" and paste0("Var_", year) as both produced the same output.

Thanks for your help,


R Under development (unstable) (2018-03-23 r74448) -- "Unsuffered Consequences"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

______________________________________________ mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.

Reply via email to