简体   繁体   English

“Knit HTML”在Rstudio 0.98中做了什么?

[英]What does “Knit HTML” do in Rstudio 0.98?

I am trying to figure out what command and default options RStudio uses when pressing the "knit HTML" button in RStudio version 0.98.1091 because I get a slightly different intermediate markdown file when I run the knit() function from the console. 我试图找出RStudio在按下RStudio版本0.98.1091中的“编织HTML”按钮时使用的命令和默认选项,因为当我从控制台运行knit()函数时,我得到一个稍微不同的中间降价文件。

Specifically, when I use the following header for the R markdown file: 具体来说,当我对R markdown文件使用以下标题时:

---
title: "Report Title"
author: Daddy the Runner
date:  "`r format(Sys.time(), '%A, %B %d, %Y')`"
output: 
  html_document:
    keep_md: true
---

I get the following markdown file when pressing the "Knit HTML" button: 按下“编织HTML”按钮时,我得到以下markdown文件:

# Report Title
Daddy the Runner  
`r format(Sys.time(), '%A, %B %d, %Y')`

When I execute the following command: knit("myReport.Rmd") , I get the following markdown file: 当我执行以下命令: knit("myReport.Rmd") ,我得到以下markdown文件:

---
title: "Report Title"
author: Daddy the Runner
date:  "Saturday, January 10, 2015"
output: 
  html_document:
    keep_md: true
---

Clearly the RStudio button is generating the intermediate markdown file using some other options but I can't find any information about it in the RStudio docs. 显然,RStudio按钮正在使用其他一些选项生成中间降价文件,但我无法在RStudio文档中找到有关它的任何信息。

The key issue is the date line. 关键问题是日期线。 For some reason, RStudio doesn't execute the inline r chunk in the header when making the markdown file. 出于某种原因,RStudio在制作markdown文件时不会在标题中执行内联r块。 (However, it does get executed before generating the final HTML.) Whereas, the knit() function call does execute the inline chunk while generating the markdown file. (但是,它会在生成最终HTML之前执行。)然而, knit()函数调用会在生成markdown文件时执行内联块。

The only other difference I noticed in the two markdown files is related to the generation of plots. 我在两个降价文件中注意到的唯一其他差异与图的生成有关。 The two methods generate different sized graphics (command line: 504 x 504) versus (button: 672 x 480) and place them in different directories. 这两种方法生成不同大小的图形(命令行:504 x 504)与(按钮:672 x 480)并将它们放在不同的目录中。

I tried the recommendation in this What commands are run when pressing "Knit HTML" on an R Markdown file in Rstudio 0.96? 在Rstudio 0.96的R Markdown文件中按“Knit HTML”时,我尝试了这个命令的运行方式。 question to insert a Sys.sleep(30) call but that did not provide any information about what call RStudio used to knit the document. 问题是插入一个Sys.sleep(30)调用但是没有提供任何关于RStudio用于编织文档的调用的信息。 It did pause the output in the R Markdown console window which was unnecessary because RStudio keeps all of the output anyway. 它确实暂停了R Markdown控制台窗口中的输出,这是不必要的,因为RStudio始终保留所有输出。 What I didn't see in the output was the command RStudio issued. 我在输出中没有看到的是RStudio发出的命令。

Any insight to the nature of these differences would be greatly appreciated. 任何洞察这些差异的性质将不胜感激。 While I like using IDE environments and the conveniences they provide, I really like to understand what it is they are doing so I can better anticipate their behavior. 虽然我喜欢使用IDE环境和它们提供的便利,但我真的很想了解它们正在做什么,这样我就能更好地预测它们的行为。

As @rawr pointed out in the comments: 正如@rawr在评论中指出的那样:

rmarkdown::render('your_document.Rmd', 'html_document', 'new_titel.html')

works and creates the same document as the Knit HTML button. Knit HTML按钮一起工作并创建相同的文档。

When I look at the RMarkdown tab (right of Console tab) it looks like they run knitr::knit and then a fairly involved pandoc shell line 当我查看RMarkdown选项卡(Console选项卡右侧)时,看起来他们运行knitr::knit然后是一个相当pandoc shell行

/usr/local/lib/rstudio/bin/pandoc/pandoc filename.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output filename.html --smart --email-obfuscation none --self-contained --standalone --section-divs --table-of-contents --toc-depth 3 --template /home/me/R/i686-pc-linux-gnu-library/3.1/rmarkdown/rmd/h/default.html --variable 'theme:flatly' --include-in-header /tmp/user/1001/RtmpKz5GnI/rmarkdown-str3bba3848bd7b.html --mathjax --variable 'mathjax-url:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --no-highlight --variable highlightjs=/home/cd/R/i686-pc-linux-gnu-library/3.1/rmarkdown/rmd/h/highlight

From the very first /usr/local/lib/rstudio/bin/pandoc/pandoc I infer that they bring their own pandoc , probably figuring duplication is better than debugging to play nice with everyone's idiosyncratic pandoc versions. 从第一个/usr/local/lib/rstudio/bin/pandoc/pandoc我推断它们带有自己的pandoc ,可能认为重复比调试更好,可以与每个人的特殊pandoc版本一起玩。


So to me it looks like RStudio is doing the following: 所以对我来说,看起来RStudio正在做以下事情:

  1. knit 针织
  2. pandoc with their special pandoc version and a lot of flags pandoc与他们特殊的pandoc版本和很多标志

and step #2 is where the interpretation of your header 和步骤#2是你的标题的解释

---
title: "Report Title"
author: Daddy the Runner
date:  "`r format(Sys.time(), '%A, %B %d, %Y')`"
output: 
  html_document:
    keep_md: true
---

happens. 发生。

HTH. HTH。

我相信它目前在RMarkdown包中使用html_document函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM