I'm creating variables based on certain string combinations.
Each variable would store some values. In this example, to make it simple, they store a numerical value.
However, in actual problem, each would store a tibble.
I need to store each tibble as RData and they have to be created using unique combinations of the string.
The problem is when I use save() on this variable, it couldn't find it so the save would fail.
res <- 12345
sku = 'sku_a'
index = '1'
# create variable based on string combination
# assign variable value with res
assign(paste0(index,'_arima_',sku), res)
# return the value of the created variable
get(paste0(index,'_arima_',sku))
# save created variable as RData
save(paste0(index,'_arima_',sku), file = paste0(index,'_arima_',sku,'.RData'))
Error in save(paste0(index, "_arima_", sku), file = paste0(index, "_arima_", :
object ‘paste0(index, "_arima_", sku)’ not found
save(get(paste0(index,'_arima_',sku)), file = paste0(index,'_arima_',sku,'.RData'))
Error in save(get(paste0(index, "_arima_", sku)), file = paste0(index, :
object ‘get(paste0(index, "_arima_", sku))’ not found
save(eval(paste0(index,'_arima_',sku)), file = paste0(index,'_arima_',sku,'.RData'))
Error in save(eval(paste0(index, "_arima_", sku)), file = paste0(index, :
object ‘eval(paste0(index, "_arima_", sku))’ not found
getin yoursavecommand. Even better, forgetassign(for now) and learn to use lists instead of thisassign/getcoding nightmare.getin the save command doesn't help here. The first argument ofsaveseems to be captured without being evaluated at all. Your second point is of course spot on.assignin R unless you need fine-control regarding the environment objects are assigned to. You do not have such a case.