I saw the info on finding the name of my temp directory in this question.
The problem I'm having is that my Appdata/Local/temp/[Rtmpxxxx] directory is being deleted during an R session longer than 1 or 2 days. I have turned off all automatic temp deletion actions that Windows 10 can take. There's nothing in Rprofile.site or .Renviron related to temp directory or files.
Any ideas what I need to turn off or modify to keep the Rtmp directory from being deleted?
You could move your temp directory to another folder (outside the win10 temp folder)
e.g. with write("TMP = '<your-desired-tempdir>'", file=file.path(Sys.getenv('R_USER'), '.Renviron'))
If it is still being deleted, it is rather unlikely that Win10 deletes it.
edit by the OP
Depending on [something mysterious], the same command above should be used to create TEMP and TMPDIR as discussed here
Related
I would like to change where RStudio saves the r.snippets file that stores my code snippets. According to this site, RStudio should save to ~/.R/snippets/r.snippets. I use R_USER=C:/Users/JT/R in my Renviron.site file to set the location of ~. I think this code works, because when I check the location of ~ in RStudio I get:
> path.expand("~")
[1] "C:/Users/JT/R"
However, when I edit the snippets in RStudio it creates the r.snippets file in the folder C:\Users\JT\Documents\.R\snippets\. I want the r.snippets file to be saved in the folder C:\Users\JT\R\.R\snippets\.
Any ideas what I'm doing wrong? Thanks.
Over on the RStudio Community site this same question was asked as Can you change the directory the Rstudio looks for the r.snippets file?
Very helpful answer by RStudio employee kevinushey was:
While that directory isn't currently configurable, you might have luck
creating a symbolic link (or, on Windows, a junction point) to
re-route the snippets directory to another location.
tom_greenwood, the user who asked the question followed up with details of the steps he used:
1. Put you existing r.snippets file in the new directory on the shared drive. I called mine 'snippet files'
2. Delete the snippets directory which is inside the .R directory
3. Run cdm as an administrator.
4. Enter the command mklink /D "C:\Users\name.surname\Documents\.R\snippets" "T:\shared directory\snippet files"
5. Restart Rstudio.
I am trying to move about 1000 files that all begin with "simulation." into one directory entitled "simulations." I am using a remote server, and the files are currently in my home directory on the server. I need to move them to a separate directory because I need to, ultimately, append all the "simulation." files into one file. Is there a way to either append only the files in my home directory that begin with "simulation." or move only these files into a new directory?
Thank you.
Assuming you can change directories to the desired path on the remote server... and the simulations are located in /currentPath ... then....
cd desiredPath
mkdir simulations
mv /currentPath/simulation* simulations
(to futher answer your question... if you wanted to append all the files together, you could type cat simulation* > allSimulations.txt
I was using R installed on a Linux server using SSH. Everything was fine, but now I have been denied access to temp folder and if I am loading R it is giving error cannot create 'R_TempDir', as it can't create the temp folder.
Can you please tell me how to create own local temp folder so that R can create temporary directory there ?
You can try to set one of these environment variable :
TMPDIR, TMP, TEMP:
Consulted (in that order) when setting the temporary directory for the session: see tempdir. TMPDIR is also used by some of the utilities see the help for build
by doing for instance :
export TMPDIR=/tmp
source
Hope this answers.
From what I understand,
I just thought that you could use .bashrc files in your /home/username/ directory
~# nano /home/username/.bashrc
You can put the command to create the folder inside this .bashrc file by just adding this line mkdir /your/dir/path/yourDir
This file is just like an autorun file which run everytime you upstart your linux server
But this is just working per user setting
I'm wondering
does launching R.exe on windows create temporary files and
does interpreting something like x <- 5 write to those temporary files?
If temporary files are created where are they stored and what happens if I launch several instances of R.exe? Will they share and overwrite each others temporary files?
Each instance of R gets its own temporary directory. You can see that pretty easily below the default temporary directory on your system (eg /tmp for me; on Windows I usually set TEMPDIR and TMPDIR to C:\TMP and find them there; I forget where they go otherwise). But when you invoke tempfile() or tempdir() you can infer the path:
R> tempfile()
[1] "/tmp/RtmpDVDtmj/file6a27612c4c83"
R>
So the R session in which I typed this uses /tmp/RtmpDVDtmj/.
The directory name is randomized and safe from other R instances running at the same time.
At exit of R, the directory is purged.
And no, the simple assignment x <- 5 will not involve a temporary file.
How do I start a new .R file default in a new session for new objects in that session?
Workspaces are .RData files, not .R files. .R files are source files, i.e. text files containing code.
It's a bit tricky. If you saved the workspace, then R saves two files in the current working directory : an .RData file with the objects and a .RHistory file with the history of commands. In earlier versions of R, this was saved in the R directory itself. With my version 2.11.1, it uses the desktop.
If you start up your R and it says : "[Previously saved workspace restored]", then it loaded the file ".RData" and ".RHistory" from the default working directory. You find that one by the command
getwd()
If it's not a desktop or so, then you can use
dir()
to see what's inside. For me that doesn't work, as I only have the file "desktop.ini" there (thank you, bloody Windoze).
Now there are 2 options : you manually rename the workspace, or use the command:
save.image(file="filename.RData")
to save the workspaces before you exit. Alternatively, you can set those options in the file Rprofile.site. This is a text file containing the code R has to run at startup. The file resides in the subdirectory /etc of your R directory. You can add to the bottom of the file something like :
fn <- paste("Wspace",Sys.Date(),sep="")
nfiles <- length(grep(paste(fn,".*.RData",sep=""),dir()))
fn <- paste(fn,"_",nfiles+1,".RData",sep="")
options(save.image.defaults=list(file=fn))
Beware: this doesn't do a thing if you save the workspace by clicking "yes" on the message box. You have to use the command
save.image()
right before you close your R-session. If you click "yes", it will still save the workspace as ".RData", so you'll have to rename it again.
I believe that you can save your current workspace using save.image(), which will default to the name ".RData". You can load a workspace simply using load().
If you're loading a pre-existing workspace and you don't want that to happen, rename or delete the .RData file in the current working directory.
If you want to have different projects with different workspaces, the easiest thing to do is create multiple directories.
There is no connection between sessions, objects and controlling files .R. In short: no need to.
You may enjoy walking through the worked example at the end of the Introduction to R - A Sample Session.
Fire up R in your preferred environment and execute the commands one-by-one.