Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RStudio: Save data from Viewer

Tags:

r

rstudio

Due to a stupid mistake and a defective USB stick I lost a bunch of data and I am now trying to recover it.

Some of the the data is still displayed in the Viewer tabs when I open RStudio. However, I can only save R Scripts and R Markdownfiles out of the Viewer. The displayed data frames are nice and complete, I can sort and filter them in the Viewer, however, I cannot find a "save" option. Is there a possibility to save this displayed data into Rdata or csv or something similar?

like image 533
Julian Avatar asked Aug 24 '16 11:08

Julian


2 Answers

I would suggest three different approaches, but none of them will necessarily work. I sort them according to my prior expectations of success.

1) You can copy all your data frame from the viewer and paste it into an external spreadsheet software to obtain a .csv file. E.g. through the "convert text to columns" button in MS Excel.
2) You can copy and paste the character string into an object that is passed to the text option of read.table or to dput(). Check out the "Copy your data" section of this famous SO question
3) Finally, you can get google Chrome's "Inspect Element" function to inspect the html code of the object in the viewer. Once you find the table you can copy paste and scrape with an html parser, e.g. using the rvest package. Good luck!

like image 152
000andy8484 Avatar answered Oct 19 '22 10:10

000andy8484


Thanks everybody, there is a way to access the data as Rdata files, which was kindly explained to me here

I used the second method and located the files in %localappdata%\RStudio-Desktop\viewer-cache.

like image 29
Julian Avatar answered Oct 19 '22 09:10

Julian