I have multiple RData images saved. Each file contains the same number of objects with identical names across each file. How can I prepend the names of every object in every file so that I can load every file into my global environment without overwriting the objects from the previously loaded file?
For example, if I load "image1.RData", I get two objects in my global environment:
| Object name | Value |
|---|---|
| object1 | a |
| object2 | b |
If I load "image2.RData", I get another two objects in my global environment:
| Object name | Value |
|---|---|
| object1 | c |
| object2 | d |
The values for object1 and object2 given by "image1.RData" have been overwritten by the values from "image2.RData".
My goal is to be able to load each RData file and preserve the values for each object given by their respective file. Ideally, the object names from each file would be prepended with the name of their data file, such that my global environment would look something like this:
| Object name | Value |
|---|---|
| image1_object1 | a |
| image1_object2 | b |
| image2_object1 | c |
| image2_object2 | d |
Is there a feasible way to make this happen? Prepending the object names isn't a necessary requirement as long as my goal is obtained, that's just what I thought made the most sense but I can't figure out how to do it.
Thanks in advance for the help.
Here is one solution. I'm sure there is a simpler approach out there, but this does the job nicely. It's based on the simple idea of:
Here's my setup of your situation.
Here is my solution:
Hope this helps.