When I save and load RDA files the name changes?

450 Views Asked by At

I have a parameter called country_name that reflects the name of a country I am interested in and which I change sometimes when I run my code, I would like my RDA file to reflect that name change once saved and loaded back into the environment.

Currently what happens is this:

Name the country:

country_name <- "Ireland"

Create a simple data frame:

x <- 10

vars_2_keep <- data.frame(x)

vars_2_keep

It contains x=10

x
1 10

I save it, renaming the data frame with the country name so that when I do this with a different country I will have country specific information:

save(vars_2_keep, file=paste("my_data_", country_name[1], ".rda", sep = ""))

I delete everything, and load it back in:

rm(list=ls())

load(file='my_data_Ireland.rda')

Unfortunately, in the environment instead of my data frame being called "my_data_Ireland", it is still called vars_2_keep.

How can I update the name of this data frame to my_data_country_name[1] (which in this example would be my_data_Ireland)

Thank you

0

There are 0 best solutions below