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

谁都会走 提交于 2019-12-03 15:09:54

问题


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:


回答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.




回答2:


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



来源:https://stackoverflow.com/questions/41860203/how-to-show-output-in-console-when-writing-an-rmarkdown-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!