代码之家  ›  专栏  ›  技术社区  ›  C8H10N4O2

Rstudio正在更改默认的R笔记本输出

  •  0
  • C8H10N4O2  · 技术社区  · 7 年前

    我从RStudio中的一个新R笔记本开始:

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

    提交此 微基准() 控制台提供合理的输出,如:

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

    这真的把输出搞砸了--现在看起来是这样的:

    enter image description here

    如果我回去把标题改回 output: html_notebook

    enter image description here

    编织

    我使用的是适用于Windows的RStudio1.1.419版本。

    1 回复  |  直到 7 年前
        1
  •  2
  •   user2554330    7 年前

    有两个变化正在发生。首先,你的 html_notebook 格式正在更改为 html_document: df_print 正在添加选项。

    基本上第一个是什么 Knit to HTML 是在要求。 html_document html\U笔记本

    一旦你进去了 html文档 格式,你可能想要 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 ).
    这对大多数人来说都不太实际。

    当然,在你拿到 如果选择了输出格式,您可以更改选项(或删除它)。