Search code examples
rworkspace

Opening Workspace in R and rename it


I'm pretty new with R and have a basic issue.

I am trying to open multiple Workspaces in Rstudio to merge them. Unfortunately, every time I'm opening a Workspace, it takes the name "x" (instead of its file's name). Then when I want to open another workspace it overwrites on the previous one and also takes the name "x".

Can anyone help me with this pretty easy issue?

Thanks a lot in advance!


Solution

  • You can try something like this:

    myvalue1 <- get(load("YourWorkspace1.RData"))
    myvalue2 <- get(load("YourWorkspace2.RData"))
    

    So that if YourWorkspace1 and YourWorkspace2 contains a variable that has the same name, myvalue1 will take the value of your variable stored in YourWorkspace1 and same for myvalue2.

    But if the workspace you want to save only contains one variable, I suggest you store it using saveRDS:

    saveRDS(x, file = "x.rds")
    

    And then load it like that :

    myvalue <- readRDS("x.rds")
    

    I hope this is clear.