编写RMarkdown笔记本时如何在控制台中显示输出? [英] How to show output in console when writing an RMarkdown notebook?

查看:614
本文介绍了编写RMarkdown笔记本时如何在控制台中显示输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题,我想我只是去找对地方了,否则RStudio的运行不正常. 我想知道是否可以将我所有降价代码块的结果输出到绘图窗口或控制台.

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.

我开始使用R Notebooks在R Markdown中进行书写.说我输入命令

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

head(cars)

进入我的.Rmd文件.我按Ctrl + Enter,然后运行该行. Up将汽车数据框的前6行弹出到我的脚本中.我看到该行已在控制台中运行,但是输出不在控制台中.

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.

为什么会打扰我?有时我的代码块很长.然后,我必须烦人地滚动到该块的末尾才能看到我的结果.或者,我键入head(car),运行该行,然后决定我要查看tail(car)并运行该行.在控制台中,我可以看到两个结果(数据帧的开头和结尾),但是在.Rmd文件中,因为我没有一次运行它们,所以"head"调用的结果消失了.这些看似很小的问题,但是当它们反复发生时,令人沮丧!我知道,如果我直接在控制台中输入内容,就可以看到结果,但这会中断我的工作流程.

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.

我尝试过的操作:除了进行谷歌搜索外,我还进入了RStudio->工具-> R Markdown,并确保显示所有Markdown文档的内联输出"选项未被选中-没什么区别.

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.

我在这里错过选项了吗?我正在使用 R Studio版本1.0.136 .

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

谢谢!

这是代码(使用.Rmd笔记本文件)

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
```

和屏幕截图:

推荐答案

来自官方网站(我强调):

默认情况下,RStudio在所有R Markdown文档上启用内联输出(笔记本模式),因此您可以与任何R Markdown文档进行交互,就好像它是笔记本一样.如果您有喜欢使用传统控制台交互方式的文档,则可以通过单击编辑器工具栏中的齿轮并选择控制台中的块输出 来禁用笔记本模式. >.

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.

这会将R Markdown文档的YAML正面的chunk_output_type选项设置为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
---

在不单击任何GUI选项的情况下将这些行添加到YAML前端当然会得到相同的结果.

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

这篇关于编写RMarkdown笔记本时如何在控制台中显示输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆