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

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.

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. GitHub - tidyverse/reprex: Render bits of R code for sharing, e.g., on GitHub or StackOverflow. 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. 3.2 Notebook | R Markdown: The Definitive Guide

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

1 Like

If you just want to save code and console output sink() should be the easiest approach for this:

1 Like

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

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)

1 Like

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"

1 Like