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

Nova picture Nova · Jan 25, 2017 · Viewed 17k times · Source

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

Answer

cadair picture cadair · Jan 25, 2017

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.