6

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?

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
Julian
  • 111
  • 1
  • 6
  • Is the data visible when we run `ls()`? – zx8754 Aug 24 '16 at 11:29
  • It returns `character(0)` – Julian Aug 24 '16 at 11:32
  • Maybe copy paste? – zx8754 Aug 24 '16 at 11:34
  • 2
    Can you retrieve your code from the History and thereby recreate the data? – PhiSeu Aug 24 '16 at 11:37
  • 2
    By "viewer" do you mean the Viewer tab? And, if that's what you mean, are you sorting/filtering a rendered `datatable` inside a rendered RMarkdown document? And, if that's what you mean, can you find the HTML file for that RMarkdown document? And, if you can do that, can you put that HTML document somewhere you can share it in a link? – hrbrmstr Aug 24 '16 at 11:37
  • 1
    If you right click on viewer window and click on "Open Frame", there is an option of print, not ideal maybe as PDF? – zx8754 Aug 24 '16 at 11:45
  • Have a look at @Jonathan's comment [here](http://stackoverflow.com/questions/30600153/save-view-output-of-rstudio-as-html). – lukeA Aug 24 '16 at 11:47
  • 1
    @zx8754 I was thinking the same. There is an R package `pdftools` that has a function `pdf_text()` which can open the resulting PDF file and extract it to a regular text string (which would still need some manipulation to get back to a data frame, but should be doable). – John Coleman Aug 24 '16 at 11:48
  • In any event -- it is probably a good idea to print the data to a PDF file before trying other approaches. That way if worst comes to worst and you accidentally delete or damage the view you have a permanent record to fall back on. – John Coleman Aug 24 '16 at 11:55

2 Answers2

5

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!

Community
  • 1
  • 1
000andy8484
  • 563
  • 3
  • 16
5

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.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
Julian
  • 111
  • 1
  • 6