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
Related
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.
I am using the most recent version of R (3.3.2), running in the most recent version of RStudio (1.0.136) on MacOS Sierra (10.12.3). I am running into an issue in which my working directory corresponds, and is stuck on, the directory that contains the .RMD file I currently have open in RStudio. Upon opening the file, the working directory is correctly set to the directory holding the .Rproj file. When I go to load in a file with a path relative to that directory, however, I get an error that there is no such file in the current working directory, and the error returns the location of the .RMD file as that working directory.
The working directory, however (using getwd()) still reads where the working directory is supposed to be, and no matter where I try to set it, I still get the same error message when I try to read in a file. Notably, I do NOT get an error message that the working directory cannot be changed--R tells me that the working directory has been changed, and that directory is allegedly the current working directory...but it's not.
I have tried fully (as far as I am aware) uninstalling R and R studio and reinstalling them, to no avail. Does anyone have a solution? This is frustrating the heck out of me right now, since I have to revise all the relative paths in the notebooks that I have defined to do my work in the interim.
Extra information in case it's relevant: I restored from a Time Machine backup that I suspect may have been corrupted somehow; some contents of my Applications folder were missing that I had to move over manually. Could this be causing the issue? Are there other system files that R depends on when interacting with the filesystem that I might look to? I'm trying to avoid doing a clean OS install or a piecemeal rebuilding of my files, since I don't know if that's actually the issue.
Thanks in advance!
This is a known feature/bug of RStudio notebooks (Working Directory about halfway down). Notebooks are executed in the same directory as the file. As #Simon Jackson noted, you can change this using knitr::opts_knit$set(root.dir = normalizePath()).
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)
I'm using a Windows 7 x64 machine with R-3.1.0. I installed the Rserve package through Rstudio.
The start of Rserve is successful with the following code in Rstudio:
library(Rserve)
Rserve()
I got the following output:
Starting Rserve...
"C:\R\R-31~1.0\library\Rserve\libs\x64\Rserve.exe"
My problem is that I couldn't locate the configuration file. Apparently it can't be "/etc/Rserv.conf".
I did come across a webpage saying that the config file is Rserv.cfg in the working directory (unless changed at compile-time). But which working directory? I have checked the working directory of the current R project as well as the Rserve library directory, but it was not there...Could someone help me with this please? Thank you.
Rserve does not automatically come with a config file, you must make one. Best steps for doing so:
Navigate to the file where you just installed Rserve.exe (C:\R\R-31~1.0\library\Rserve\libs\x64\R, based on the message you copied here)
Find Rserve.exe, Reserve_d.exe, and Rserve.dll there. Copy these files.
Navigate to where R.dll is on your computer. This is probably C:\Program Files\R\R-3.1.3\bin\x64, but may be different depending on where you installed R to.
Copy the 3 files mentioned above to this location.
Create a text file here named "Rserv.cfg" with the arguments you are looking for, such as port 6312 or library(mvoutlier). Yes, I know that this is different from the documentation, but if you start Rserve_d.exe you will see that this is the file it is looking for. I have not had success naming it anything else.
You can start Rserve by specifying the location of the config file. In R instead of just Rserve() try the following:
Rserve(args="--RS-conf C:\\folder\\Rserv.cfg")
If path is more complicated you need to massage it a little bit:
Rserve(args="--RS-conf C:\\PROGRA~1\\R\\R-215~1.2\\library\\Rserve\\Rserv.cfg")
Look in the $RHOME/bin directory
If you can't find it here is a different way to approach it:
Download Rserve at [http://rforge.net/snapshot/Rserve_.tar.gz], and save it in your desired directory
Run R CMD INSTALL Rserve_.tar.gz
This allows you to leave Rserve where you want it.
After looking at the Rserve source code and making some test I found that on Windows platform Rserve try to load the configuration file from the current working directory. Also pay attention because on Windows the file name is RServ.cfg and not Rserv.conf as documented.
The current working directory depends of the process, for example using RStudio by default it is your Documents and Settings folder:
C:\Users\[username]\Documents
but can be changed in the "Global Options" of the IDE
So you can create an "RServ.cfg" text file in that directory with your needed options and starting RServe in the usual way in RStudio
Rserve()
will load your configuration.
I have entered some codes on R in a MAC and before closing R, it asks "Save workspace image?" and I clicked "Save", thinking it would save my codes. But I cannot find where is my codes? So where is the R default path for MAC and how can I find my codes?
Thanks in advance
If you just executed save.image() and then hit yes, your data was saved to a file called .Rdata
In terminal, type ls -alh in the same working directory and you'll see it.
If you're not sure what dir you're in, in R type getwd()
save.image will not save the commands that created the data objects in the .Rdata file. Instead you need to look at the .Rhistory file that is automatically saved at the end of a session. The default path is the working directory. If you were using the R.app or R64.app GUI working environment then the name of the file is ".Rapp.history", but if it was a Terminal session it is named ".history". In an R session you can get the last 25 lines by typing history(). If you put a numerical argument in that history call, you can change the number of lines displayed.
?history
?getwd
Also look at the R Mac FAQ. It describes how the R.app GUI is different than what you might read in ?loadhistory. You probably also need to learn how to see "dot-files" or "system files". This has long been possible by opening Terminal and typing at the command line:
machine-name:dir username$ defaults write com.apple.finder AppleShowAllFiles YES:
Reboot or relaunch Finder. I keep my .Rhistory (those saved from a Terminal launch of R) and .Rhistory.history (those from an R-GUI launched session) files in the "root" of my User folder.