Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does RStudio store the temporary R script files before saved?

Tags:

r

rstudio

I've just had RStudio crash on me unexpectedly, and on re-starting, contrary to what I've come to expect, the R script I had been tinkering around with was nowhere to be found.

I've managed to track down the Rhistory file so I'll be able to piece together all the commands, which is reassuring.

However, I am curious if there's somewhere I might try looking to find the temporary unsaved file on the off chance that might be cached somewhere (after all, it is usually cached somewhere that RStudio apparently knows to look). Is there a particular file extension/format I should be searching for?

Currently running R 3.3.1 through RStudio 0.99.903 on Linux Mint 17.3 (over Ubuntu 14.04.3 LTS).


I've tried running grep on the command line to find some of the more recently updated lines of code; I may be out of luck. I found two files:

~/.rstudio-desktop/history_database

Which appears to basically be a more centralized .Rhistory for RStudio

and

~/.rstudio-desktop/sdb/s-9CD2C698/D7986B2A

This looks JSON-like and also appears to basically be an Rhistory. Please correct me if I'm wrong.

like image 754
MichaelChirico Avatar asked Oct 10 '16 19:10

MichaelChirico


People also ask

How do I recover an unsaved file in RStudio?

If you are a Windows user, take a look at this folder that contains the folder that starts with “s-“. RStudio should be open. There are usually files that end with “-contents”. Open some of them in a text editor and restore unsaved source code.

Where are RStudio files stored?

The default location for the RStudio Connect data directory is /var/lib/rstudio-connect . This can be customized by specifying an alternate DataDir in the Server section of your configuration file.

What is a temp directory in R?

That is, using a temporary directory or file allows you to write data, read it, manipulate it, or what-have-you, and delete all evidence when you're done. In R, temporary directories are created with the function tempdir() , and temporary files with tempfile() .

Where do I find R scripts?

You can open a new empty script by clicking the New File icon in the upper left of the main RStudio toolbar. This icon looks like a white square with a white plus sign in a green circle. Clicking the icon opens the New File Menu. Click the R Script menu option and the script editor will open with an empty script.


1 Answers

As indicated by @KevinUshey from RStudio:

RStudio stores autosave data as part of the JSON 'blobs' within the sdb folder. You should see the document serialized as a long 'string', with newlines embedded.

Use packages such as jsonlite to parse this and best of luck.

like image 200
MichaelChirico Avatar answered Sep 21 '22 08:09

MichaelChirico