Search code examples
rrstudioenvironment

Work in multiple environments in RStudio and R


This question is hard to ask but I will try to make it as clear as possible. Also I am not really sure if this should be asked here or on the Meta Stackoverflow, so experienced programmers, please advise if it should be asked there.

How can I work in multiple environments in R and RStudio?

What I mean is that, for example, when you try to solve Stackoverflow question and you run the reproducible example, you will find so many objects in your environment that do not belong to your own work and removing it after every question is not that easy and sometimes you miss some objects in your environment.

Another part of the story is that when I am writing my code, most of the times I do some trials and compare the results of each trial to pick the required one. After all these trials, I found my environment is full of objects that I do not use. I normally use rm(list=ls()) to clear every thing and rerun my code so I make sure that only the required objects are in the environment not the ones I used in my trials.

Is there any way to have, let's say in RStudio, two different environment windows which you can use one for trials and errors and the other one for the proper code results in which one does not affect the other?

There might be a direct answer to this question which will solve my issue OR some good practices in writing and running codes that I should follow to handle this problem with less hassle.


Solution

  • You are looking at workspace. http://www.statmethods.net/interface/workspace.html

    I tend to create a folder for each of my projects. In each project, It will have its own .Rdata which I will load before I start.

    Also, for many applications in bioinfomatics, it is common for people to print out their session info at the end

    sessionInfo()