How to save the console in R studio (input+output)


#1

Hi I am new (with Rstudio too)!

I was wondering if there is any function in Rstudio to save in a txt file both the input and output of the console. I want to save everything.

In R you can save it in File->save to file, but I haven't found any option such that in Rstudio.

Thank you for your help.


#2

A few options to consider;

  1. You can copy and paste your console to a text file.
  2. In your History pane (next to Environment), you can select the save icon. This however won't save your output, just your input.
  3. If the purpose is to create a reproducible example, the reprex package is the way to go. https://github.com/tidyverse/reprex This is great for short bits of r code and output.
  4. You should also check our rmarkdown notebooks. Note that even with R's file >> save feature, you won't save plots etc. With rmarkdown or rmarkdown notebooks, you can intermix markdown formatted text, code, and code output (including tables and plots). You then also may knit that into html or pdf documents. https://rmarkdown.rstudio.com/r_notebooks.html

And this is the most recent RStudio IDE support question I could find,


#3

If you just want to save code and console output sink() should be the easiest approach for this: https://stat.ethz.ch/R-manual/R-devel/library/base/html/sink.html


#4

Ok, thanlk you. The markdown seems interesting...
Unluckily the sink() function save only output.


#5

Just out of interest I looked a bit around and it‘s really a bit more complicated than it should.

So here is another solution (in the comments) https://stackoverflow.com/questions/7096989/how-to-save-all-console-output-to-file-in-r?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa


#6

I think rmarkdown notebooks are the way to go, but you could also fill out a feature frequest for the IDE team - RStudio Github Issues: "Writing Good Feature Requests"