【问题标题】:Rstudio is changing my default R Notebook outputRstudio 正在更改我的默认 R Notebook 输出
【发布时间】:2019-03-29 02:27:23
【问题描述】:

我从 RStudio 中的新 R Notebook 开始:

---
title: "R Notebook"
output: html_notebook
---

This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. Etc Etc Etc.

然后我修改它来做我想做的事——例如,我正在尝试使用microbenchmark()

---
title: "R Notebook"
output: html_notebook
---

Let's compare the sort methods on a set of shuffled integers.

```{r}
library(microbenchmark)
n <- 100000L
microbenchmark(
  sort(sample.int(n),method='radix'),
  sort(sample.int(n),method='quick'),
  sort(sample.int(n),method='shell')
)
```

将此microbenchmark() 提交到控制台会给出合理的输出,例如:

Unit: milliseconds
                                  expr       min        lq      mean    median        uq       max neval cld
 sort(sample.int(n), method = "radix")  4.685707  4.914925  6.559412  5.619257  7.539383  16.66746   100 a  
 sort(sample.int(n), method = "quick")  8.169732  8.534512 10.490920  9.333782 11.008653  21.44854   100  b 
 sort(sample.int(n), method = "shell") 10.766820 11.144858 15.479061 12.408976 14.519405 133.87898   100   c

但是,当我尝试 knit 它时(单击从“预览”到“编织到 HTML”的下拉菜单,它会自动将我的标题更改为:

---
title: "R Notebook"
output:
  html_document:
    df_print: paged
---

这真的把输出弄乱了——现在它看起来像这样:

如果我返回并将标题改回output: html_notebook 并再次单击“Knit”按钮,现在它看起来正确:

有没有办法防止 RStudio 弄乱我的第一个 knit

我正在使用适用于 Windows 的 RStudio 版本 1.1.419。

【问题讨论】:

标签: r rstudio knitr microbenchmark rnotebook


【解决方案1】:

发生了两个变化。首先,您的html_notebook 格式将更改为html_document:。其次,正在添加df_print 选项。

基本上第一个是Knit to HTML 所要求的。 html_documenthtml_notebook 是不同的格式,您要求更改格式。

一旦您采用html_document 格式,您可能需要df_print: default 而不是df_print: paged。或者您可以忽略该选项。

据我所知,除了更改 RStudio 的源代码(在此文件中的第 118 行附近:https://github.com/rstudio/rstudio/blob/8af730409bb6d651cc8f6816d136bea91441e7a4/src/gwt/src/org/rstudio/studio/client/rmarkdown/model/RmdTemplateData.java)之外,没有办法要求这个。
这对大多数人来说不是很实用。

当然,在您选择了html_document 输出格式之后,您可以更改该选项(或直接删除它)。

【讨论】:

    猜你喜欢
    • 2014-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 2018-08-12
    • 1970-01-01
    • 2010-11-29
    • 2015-07-24
    相关资源
    最近更新 更多