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

25,788

Solution 1

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.

Solution 2

Under Options in Tools, choose the options for R Markdown, change the tick for "Show output inline...." to "untick". Good luck!

Share:
25,788

Related videos on Youtube

Nova
Author by

Nova

I'm an analytical biologist working in the terrestrial ecology field, mainly with large mammals. R makes me happy. Pronouns: she/her/hers

Updated on July 09, 2022

Comments

  • Nova
    Nova almost 2 years

    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

    • GGA
      GGA over 7 years
      Can you copy and paste here your code?
    • Nova
      Nova over 7 years
      It's pretty basic, but here it is, plus a screenshot! See how the calls, executed from the notebook, do not produce output in the console?
  • Nova
    Nova over 7 years
    Well, that's embarrassing. I swear I've tried this option before and it didn't work... but maybe updating RStudio worked and I hadn't tried it again after updating. Thanks @cadair, I will be much happier now!
  • Nova
    Nova over 7 years
    Hmm... after a day of trying this, I've noticed that it seems to often "default" back to the output appearing inline, even within the same session. Strange.
  • geneorama
    geneorama about 7 years
    I feel like R Studio is becoming slightly more like Apple who is constantly forcing their evolving product and design choices on you. I can't help but wonder if it's the tidyverse influence.
  • Tom Roth
    Tom Roth almost 7 years
    The setting seems to flip from "Chunk Output in Console" to "Chunk Output Inline" whenever I save the RNotebook
  • RTbecard
    RTbecard over 6 years
    I think both this and @cadair answers are complimentary. My understanding is that this answer changes the default behavior for all new rmd docs, while cadair's will only change the chunk output for a specific document you are currently editing.
  • Jonno Bourne
    Jonno Bourne over 6 years
    Is there a line of code you can put in that does this? It is annoying having to manually do it every time. Also sharing code with people not used to R you have to tell them what to do.
  • Jonno Bourne
    Jonno Bourne over 6 years
    I realised myself it is an option in the setup editor_options: chunk_output_type: console
  • RTD
    RTD over 3 years
    When I change the chunk_output_type to console, the notebook's HTML output never gets updated. I am on version 1.3.1056. Any lead why?