I am working on a loop over a number of spss datasets. The loop needs to open each dataset and give it a specific object name. What I cannot get right is to move a value that is string to become the object's/dataset's name.
# # # # # # # # # # # # # # # # # # # # # #
#how to name an object out of a string in R
list_of_dataset_names <- list.files(path = folder)
for (dataset in list_of_dataset_names) {
# dataset name = my_dataset_june2016.sav
temp_name <- read.spss(dataset)
new_R_object_name <- grepl('.sav', '', dataset)
# new_R_object_name is 'my_dataset_june2016'
# how do I make the string contained by 'new_R_object_name', the object name of the temp_name ?
}
I have tried this https://www.r-bloggers.com/converting-a-string-to-a-variable-name-on-the-fly-and-vice-versa-in-r/ but it is about taking the object's name and converting it into a string rather than attaching a string value as the new name of an existing object.
Thank you in advance.
------ EDIT ------
It is indeed a duplicate, I was not able to find that link.
The code tha resolved the issue on my end is:
assign(new_R_object_name, temp_name)