Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show output in console when writing an RMarkdown notebook?

I have a simple question, and I think I'm just not looking in the right place, or RStudio is not acting as expected. I'd like to know if there is an option to output the results of all my markdown code chunks to go to the plots window or the console.

I'm starting to use R Notebooks to write in R Markdown. Say I type the command

head(cars) 

into my .Rmd document. I press Ctrl + Enter, and the line is run. Up pops the first 6 lines of the cars dataframe into my script. I see that the line has been run in the console, but the output is not in the console.

Why does this bug me? Sometimes my code chunks are long. Then, I have to annoyingly scroll to the end of the chunk to see my results. Or, I type head(car), run the line, then decide I want to see tail(car) and run that line. In the console, I'd be able to see both results (head and tail of the dataframe) but in the .Rmd file, because I didn't run them both at once, the results of my "head" call disappear. These seem like small problems but when they happen over and over it's frustrating! I know that if I type directly into the console, I can see the results, but this interrupts my workflow.

What I've tried: Besides googling, I've gone into RStudio --> tools --> R Markdown, and made sure that the option "show output inline for all markdown documents" is unchecked - doesn't make a difference.

Am I missing an option here? I'm using R Studio Version 1.0.136.

Thanks!

Here is the code (using an .Rmd notebook file)

--- title: "R Notebook" output: html_notebook ---   ```{r} # run just this line head(cars)  # run just this line tail(cars)  # Both show up below (here in the file) but do not go to console ``` 

And a screenshot: output does not go to console

like image 335
Nova Avatar asked Jan 25 '17 19:01

Nova


People also ask

How do I show output in RStudio?

By default, the RStudio IDE opens a preview window to display the output of your . Rmd file. However, you can choose to display the output in a dedicated viewer pane. To do this, select “View in Pane” for m the drop down menu that appears when you click on the “Run Document” button (or “Knit HTML” button).

How not show output of code in R Markdown?

You use results="hide" to hide the results/output (but here the code would still be displayed). You use include=FALSE to have the chunk evaluated, but neither the code nor its output displayed.

How do I write a script in R Markdown?

To create an R Markdown report, open a plain text file and save it with the extension . Rmd. You can open a plain text file in your scripts editor by clicking File > New File > Text File in the RStudio toolbar. Be sure to save the file with the extension .


1 Answers

From the official website (emphasis by me):

By default, RStudio enables inline output (notebook mode) on all R Markdown documents, so you can interact with any R Markdown document as though it were a notebook. If you have a document with which you prefer to use the traditional console method of interaction, you can disable notebook mode by clicking the gear in the editor toolbar and choosing Chunk Output in Console.

This sets the chunk_output_type option in the YAML front-matter of your R Markdown document to console:

--- editor_options:   chunk_output_type: console --- 

Adding those lines to the YAML front-matter without clicking any GUI option will of course lead to the same result.

like image 97
cadair Avatar answered Sep 20 '22 19:09

cadair