Permanently removing objects in RStudio Mac OS? - r

Every time I started RStudio, I have seen this my working environment.
I can use rm(list=ls()) to remove them temporarily, but every time I restarted RStudio, they showed up again.
I use getwd() to see my working directory, but in the working directory, I did not see any .Rdata file. How can I get rid of these things ?
Your kind help will be well regarded.
I use Mac OS 10.10.

Click on RStudio in the menu bar and go to Preferences.
In the R General section, unclick the Restore .RData into workspace at startup option.
The default is to reload the working environment when you restart RStudio.

I think that you, at some point, chose to save your environment to your working directory (most likely ~, i.e. your home directory, which is the default RStudio working directory).
The easier way to clear your default environment is to remove the .RData file from your home directory. It will not appear in any Finder window, because in a Unix-like OS (like OS X), files starting with . are hidden. So do the following:
Open a terminal window
If not already there, go to your home folder: cd ~
Check if there's an .RData file: ls -lA .RData
If the file exists delete it: rm .RData (if you want, create a backup: `cp .RData ./RData_backup)

Related

How to change the default working directory in RStudio

I am trying to change the default working directory in RStudio (Version 1.4.1103) in mac ("Wax Begonia" (458706c3, 2021-01-06) for macOS). And I followed the instruction here (How do you change the default directory in RStudio (or R)?). After I change the directory under Tools | Global Options, however, the working directory stay the same even though I restarted RStudio. Is there anything else I could try.
Thank you!
You can set the working directory using setwd(). Inside of setwd() you need to provide the path to the folder you want to be your working directory, such as setwd("C:/Desktop"). I typically set the working directory everytime I open R studio.

Is it safe to move .Renviron & .Rhistory into different directories?

Scenario
I read here it was a good idea to make a working directory for R by making a new folder called "R" in the "Documents" folder, so I did exactly that: C:\Users\jsmit\Documents\R.
When I installed R (v4.0.0) to my Windows 10 PC, it installed here: C:\Program Files\R\R-4.0.0.
After installing and running R with RStudio, .Renviron and .Rhistory appeared here: C:\Users\jsmit\Documents.
There is a different .Rhistory in C:\Users\jsmit\Documents\R that updates each time I use R (the files in C:\Users\jsmit\Documents have not updated themselves since installation day).
Questions
Without rendering R and/or RStudio useless...
(1) can I move .Renviron from C:\Users\jsmit\Documents into C:\Users\jsmit\Documents\R?
(2) can I move/delete .Rhistory (a possible unused copy) from C:\Users\jsmit\Documents since there appears to be another updated file by the same name in C:\Users\jsmit\Documents\R?
If not, why not, and how can I clean up my C:\Users\jsmit\Documents directory?
It is safe to move/delete either file.
.Renviron only contained the text: PATH="${RTOOLS40_HOME}\usr\bin;${PATH}"
.Rhistory contained all of the commands used up to the last time you issued a command (in my case, the up-to-date version in the working directory C:\Users\jsmit\Documents\R contained all the commands used to download new R packages and some Rscript and the non-updated version in the C:\Users\jsmit\Documents folder contained only a single command used to download devtools).
I deleted .Renviron from C:\Users\jsmit\Documents and it did not reappear after restarting R/RStudio nor affect R/RStudio use.
I moved .Rhistory from C:\Users\jsmit\Documents into C:\Users\jsmit\Documents\R and in doing so replaced the old version there. It did not reappear after restarting R/RStudio nor affect R/RStudio use.

Where is the default .RData workspace saved in a Linux environment?

I am running RStudio on a compute cluster, and every time I launch an RStudio instance it immediately crashes. I suspect there is something wrong with the workspace that loads by default. However, I can't actually find where this workspace is stored. How do I delete this file?
I found a hidden file named .Rdata in the /usr/ directory. But when I rename this file and boot up an instance of RStudio, the old workspace still boots up.
I resolved the problem by renaming the folder in the RStudio-Desktop Directory:
~/.rstudio-desktop/sources/
If you're not using Linux, you can find the location of your RStudio-Desktop Directory here:
https://support.rstudio.com/hc/en-us/articles/200534577-Resetting-RStudio-Desktop-s-State

Cannot permanently Change R Working Directory - Windows 10

I am running R 3.5.0 64 bit on my Windows 10 laptop.
I can set the Working directory fine for my work space but I am unable to make a permanent change. Each time I reload it, it does not stick.
I changed my Start In file path to the new directory under properties when right clicking the icon.
I have also added setwd() with my file path in the Rprofile.site file
No matter what I do, it continues to revert back to documents when I run getwd() in R when I open it new.
Anyone have any ideas on what I can do to make it stick?
Thanks in advance
You could go the route of using an .Rprofile which is a way to run scripts / commands on startup.
Read about .Rprofile files here in Efficient R Programming
Also, has has been mentioned by #r2evans, if you're using RStudio, there is an option for setting the default working directory. It's under the General section of the Tools -> Global Options menu.

remove r workspace in ubuntu

folks
I just installed ubuntu R, but when I saved my R work space, it loaded automatically every time when i launch R from the terminal. This had disabled couple of functions in the package i wanted to use.
My questions is how to remove my r work space in ubuntu? any idea where the location of the file is ?
I tried suggestions from this site: http://r.789695.n4.nabble.com/How-to-permanently-remove-Previously-saved-workspace-restored-td3041515.html
, but i did not really give a clear solution to it.
Best.
Its a file called .RData in your working directory:
> getwd()
[1] "/home/rowlings"
> system("ls .RData")
.RData
Because it starts with a dot its not visible in the unix shell unless you do ls -a.
Try removing ~/.RData
In case that is hard for you to understand, ~/ is the Unix way of saying "your home directory", and the ~/.RData file is the "default" workspace if you didn't explicitly set a different working directory.

Resources