@[toc]( <center> knitr 01)
title: "Untitled"
author: "ks_c"
date: "2021/1/30"
output: html_document
近日正研究r markdown,見(jiàn)作者有一knitr包的解釋?zhuān)鞠敕喴欢魏斡⒄Z(yǔ)令人頭大得緊俱恶,故作罷。
由于缺乏閱讀經(jīng)驗(yàn)锐涯,英文文章總是看完下句忘上句。本想直接機(jī)翻阶牍,可終究也是信不過(guò)蠻夷機(jī)器的亏拉。于是只好借助谷歌翻譯,躬身譯yihui xie坐桩,Options:Chunk options and package options至中文尺棋,如此。
事先聲明绵跷,鄙人英文是漏洞百出膘螟,預(yù)估本文也是掛一漏萬(wàn)。姑妄言之抖坪,若有大方之家光臨"寒舍"萍鲸,萬(wàn)請(qǐng)不吝賜教。
侵刪擦俐。
目錄(可以點(diǎn)擊各章節(jié)查看原文)
-
Chunk Options #代碼塊的設(shè)置
- Code evaluation #代碼的運(yùn)算
- Text output #文本輸出
- Code decoration #代碼裝飾
- Cache #緩存
- Plots #圖
- Animation #動(dòng)畫(huà)
- Code chunk #代碼塊
- Child documents #子文件(?)
- Language engines #語(yǔ)言引擎
- Option templates #選項(xiàng)模板
- Extracting source code #提取源碼
- Other chunk options # 其他設(shè)置
- Package Options # 包的設(shè)置
The knitr package provides a lot of chunk options for customizing nearly all components of code chunks, such as the source code, text output, plots, and the language of the chunk.
It also offers some options at the package level to customize the knitting process.
This page documents all chunk options and package options available in knitr.
The default values of these options are in parentheses in the list items.
Knitr軟件包提供了許多自定義選項(xiàng)塊,幾乎可以用于所有代碼塊的組件握侧,例如源代碼蚯瞧,文本輸出嘿期,圖表和塊的語(yǔ)言。
它還在包裝級(jí)別提供了一些選項(xiàng)以自定義輸出過(guò)程埋合。
此頁(yè)面記錄了knitr包中所有可用的模塊選項(xiàng)和軟件包選項(xiàng)备徐。
這些選項(xiàng)的默認(rèn)值在列表項(xiàng)的括號(hào)中。
Chunk Options
Chunk options are written in chunk headers.
The syntax for chunk headers depends on the document format, e.g., for .Rnw documents (R + LaTeX), chunk headers are written with << >>=, and for .Rmd documents, chunk headers are written with {r}. The examples below are primarily for .Rmd documents (R Markdown), but in most cases, the chunk options can be used with any document format. 塊選項(xiàng)寫(xiě)在塊頭中甚颂。 塊頭的語(yǔ)法取決于文檔格式蜜猾。例如,對(duì)于.Rnw文檔(R + LaTeX)振诬,塊頭用<< >> =編寫(xiě)蹭睡,對(duì)于.Rmd文檔,塊頭用
{r }赶么。
以下示例主要用于.Rmd文檔(R Markdown)肩豁,但是在大多數(shù)情況下,塊選項(xiàng)可以與任何文檔格式一起使用辫呻。
Chunk options are written in the form tag=value like this:
模塊選項(xiàng)以 tag = value 的形式編寫(xiě)清钥,如下所示:
print("hello,world")
#my-chunk :該代碼塊的名稱(chēng)
#echo=F :沒(méi)有回聲,即不現(xiàn)實(shí)代碼
#fig.height=4 :高度為4(英寸)
#dev='jpeg' :
A special chunk option is the chunk label (e.g., my-chunk in the above example). Only the chunk label does not need a tag (i.e., you only provide the value).
If you prefer the form tag=value, you could also use the chunk option label explicitly, e.g.,
代碼塊名稱(chēng)是一個(gè)特殊的塊選項(xiàng)(例如放闺,上例中的my-chunk)祟昭。僅塊標(biāo)簽不需要標(biāo)簽(即,您僅提供值)怖侦。
如果您希望使用tag = value的形式从橘,則還可以顯式使用塊選項(xiàng)標(biāo)簽,例如:
#label可以省略
The chunk label for each chunk is assumed to be unique within the document.
This is especially important for cache and plot filenames, because these filenames are based on chunk labels.
Chunks without labels will be assigned labels like unnamed-chunk-i, where i is an incremental number.
每個(gè)塊的塊名稱(chēng)在文檔中都是唯一的础钠。
這對(duì)于緩存和繪圖文件名特別重要恰力,因?yàn)檫@些文件名基于塊名。
沒(méi)有名的塊將被分配標(biāo)簽旗吁,例如unnamed-chunk-i踩萎,其中i是一個(gè)遞增數(shù)字。
You may use knitr::opts_chunk$set() to change the default values of chunk options in a document. For example, you may put this in the first code chunk of your document:
您可以使用knitr :: opts_chunk $ set()更改文檔中塊選項(xiàng)的默認(rèn)值很钓。 例如香府,您可以將其放在文檔的第一個(gè)代碼塊中:
(新建一個(gè)rmd文件時(shí)都會(huì)有第一個(gè)代碼塊默認(rèn)為該代碼塊。)
knitr::opts_chunk$set(
comment = '', fig.width = 6, fig.height = 6
)
Below are a few more tips about chunk options:
The chunk header must be written on one line. You must not break the line.
1.塊頭必須寫(xiě)在一行上码倦。 不要分行企孩。Try to avoid spaces, periods (.), and underscores () in chunk labels and paths. If you need separators, you are recommended to use hyphens (-) instead. For example, setup-options is a good label, whereas setup.options and chunk 1 are bad; fig.path = 'figures/mcmc-' is a good path for figure output, and fig.path = 'markov chain/monte carlo' is bad.
2.盡量避免在塊標(biāo)簽和路徑中出現(xiàn)空格,句點(diǎn)(袁稽。)和下劃線()勿璃。 如果需要分隔符,建議改用連字符(-)。 例如补疑,setup-options是一個(gè)很好的標(biāo)簽歧沪,而setup.options和塊1是不好的標(biāo)簽; fig.path ='figures / mcmc-'是輸出圖形的好路徑莲组,而fig.path ='markov chain / monte carlo'是不好的诊胞。-
All option values must be valid R expressions. You may think of them as values to be passed to function arguments.
3.所有選項(xiàng)值必須是有效的R表達(dá)式。 您可能會(huì)將它們視為要傳遞給函數(shù)參數(shù)的值锹杈。For example, options that take character values must be quoted, e.g., results = 'asis' and out.width = '\textwidth' (remember that a literal backslash needs double backslashes).例如撵孤,必須使用帶字符值的選項(xiàng)加引號(hào),例如竭望,結(jié)果='asis'和out.width ='\ textwidth'(請(qǐng)記住邪码,文字反斜杠需要雙反斜杠)
In theory, the chunk label should be quoted, too. However, for the sake of convenience, it will be automatically quoted if you did not (e.g., ```{r, 2a} will parsed as ```{r, '2a'}).從理論上講,塊標(biāo)簽也應(yīng)加引號(hào)市框。 但是霞扬,為方便起見(jiàn),如果您未將其自動(dòng)引用(例如枫振,```{r喻圃,2a}將被解析為`''{r,'2a'}.塊名可以加""也可以不加粪滤。
You can write arbitrarily complicated expressions as long as they are valid R code.您可以編寫(xiě)任意復(fù)雜的表達(dá)式斧拍,只要它們是有效的R代碼即可。
Below is a list of chunk options in knitr documented in the format “option: (default value; type of value)“.以下是knitr中存儲(chǔ)的選項(xiàng)杖小,這些選項(xiàng)在option:(default value; type of value)這種格式下肆汹。
Code evaluation
eval: (TRUE; logical or numeric) Whether to evaluate the code chunk.
It can also be a numeric vector to choose which R expression(s) to evaluate, e.g., eval = c(1, 3, 4) will evaluate the first, third, and fourth expressions, and eval = -(4:5) will evaluate all expressions except the fourth and fifth.
eval(默認(rèn)為T(mén),邏輯或數(shù)值型)是否呈現(xiàn)出該代碼塊予权。
也可以是數(shù)值型昂勉,eval =c(1,3,4)為第1,3,4行輸出,eval =-(4:5)第4:5行不輸出扫腺。
如果設(shè)置為{r "1", eval=c(1,2,5,6)}岗照,那么將運(yùn)算1,2行和5,6行,沒(méi)有被選中的行則在前邊加兩個(gè)##:
a <- 1
a
b <- 2
b
c <- 3
c
輸出:
a <- 1
a
## [1] 1
## b <- 2
## b
c <- 3
c
## [1] 3
Text output
-
echo: (TRUE; logical or numeric) Whether to display the source code in the output document.
Besides TRUE/FALSE, which shows/hides the source code, we can also use a numeric vector to choose which R expression(s) to echo in a chunk, e.g., echo = 2:3 means to echo only the 2nd and 3rd expressions, and echo = -4 means to exclude the 4th expression.
echo(默認(rèn)為T(mén)笆环,邏輯或數(shù)值)是否在文檔中呈現(xiàn)源代碼攒至。
除了T/F之外,也可以用數(shù)字向量來(lái)決定那幾行會(huì)呈現(xiàn)躁劣。例如echo=2:3將呈現(xiàn)2到3行的內(nèi)容(由于本文是直接在簡(jiǎn)書(shū)編輯器中編輯的迫吐,so沒(méi)有辦法完美模仿出rstudio的輸出結(jié)果。)
#全部計(jì)算账忘,但是文檔中只輸出1,2行源碼志膀。
a <- 1
a
b <- 2
b
c <- 3
c
輸出:
a <- 1
a
## [1] 1
#這里本應(yīng)有一個(gè)b<-2熙宇,由于echo而沒(méi)有顯示,但是結(jié)果卻輸出了梧却。
## [1] 2
c <- 3
c
## [1] 3
和eval的區(qū)別:eval是決定源碼是否運(yùn)算奇颠,eval為evaluate的縮寫(xiě)败去。而echo為是否在輸出文檔中呈現(xiàn)這段代碼(如果不設(shè)置eval就是全部運(yùn)算放航,顯示出echo設(shè)定的部分)。
-
results: ('markup'; character) Controls how to display the text results.
Note that this option only applies to normal text output (not warnings, messages, or errors). The possible values are as follows:
result(默認(rèn)為markup圆裕,字符串):控制如何呈現(xiàn)結(jié)果广鳍。
注意:此選項(xiàng)僅適用于普通文本(不適用于警告,消息或錯(cuò)誤)
result的值有四種吓妆,分別如下赊时。-
markup: Mark up text output with the appropriate environments depending on the output format.
For example, for R Markdown, if the text output is a character string "[1] 1 2 3", the actual output that knitr produces will be: [1] 1 2 3。 In this case, results='markup' means to put the text output in fenced code blocks (```).
markup:根據(jù)輸出格式用適當(dāng)?shù)沫h(huán)境中標(biāo)記文本輸出行拢。
如果文本輸出是字符串“ [1] 1 2 3”祖秒,則knitr產(chǎn)生的實(shí)際輸出將是:[1] 1 23。在這種情況下舟奠,results ='markup'的意思是 將文本輸出放在單獨(dú)的代碼塊中竭缝。
-
markup: Mark up text output with the appropriate environments depending on the output format.
a <- 1
a
b <- 2
b
輸出:
a <- 1
a
## [1] 1
b
## [1] 2
-
asis: Write text output as-is, i.e., write the raw text results directly into the output document without any markups.
直接按原樣輸出文本,即沼瘫,將原始文本結(jié)果直接寫(xiě)入輸出文檔中抬纸,而無(wú)需任何標(biāo)記。
a <- 1
a
[1] 1b
[1] 2
- hold: Hold all pieces of text output in a chunk and flush them to the end of the chunk.
將所有文本輸出保留在末尾的一個(gè)塊中耿戚,
輸出:
- hide (or FALSE): Hide text output.
隱藏輸出結(jié)果湿故。
-
collapse: (FALSE; logical) Whether to, if possible, collapse all the source and output blocks from one code chunk into a single block (by default, they are written to separate blocks). This option only applies to Markdown documents.
collapse:(F;邏輯)如果可能的話膜蛔,是否將所有源碼和輸出從不同的代碼塊collapse(折疊)到一個(gè)塊中(默認(rèn)情況下坛猪,它們被寫(xiě)入單獨(dú)的塊中)。 此選項(xiàng)僅適用于Markdown文檔皂股。
輸出:
print()函數(shù)塊的collapse=F
warning: (TRUE; logical) Whether to preserve warnings (produced by warning()) in the output. If FALSE, all warnings will be printed in the console instead of the output document.
It can also take numeric values as indices to select a subset of warnings to include in the output. Note that these values reference the indices of the warnings themselves (e.g., 3 means “the third warning thrown from this chunk”) and not the indices of which expressions are allowed to emit warnings.error: (TRUE; logical) Whether to preserve errors (from stop()). By default, the code evaluation will not stop even in case of errors! If we want to stop on errors, we need to set this option to FALSE. Note that R Markdown has changed this default value to FALSE. When the chunk option include = FALSE, knitr will stop on error, because it is easy to overlook potential errors in this case.
message: (TRUE; logical) Whether to preserve messages emitted by message() (similar to the option warning).
warning墅茉、error、message為是否呈現(xiàn)這三種信息屑墨,不再贅述躁锁。
7.** include**: (TRUE; logical) Whether to include the chunk output in the output document. If FALSE, nothing will be written into the output document, but the code is still evaluated and plot files are generated if there are any plots in the chunk, so you can manually insert figures later.
(默認(rèn)為T(mén);邏輯)是否在輸出文檔中包括塊輸出卵史。 如果為FALSE战转,輸出文檔中將不會(huì)任何輸出結(jié)果,但是代碼仍會(huì)執(zhí)行以躯,圖也會(huì)繼續(xù)生成槐秧,因此您可以稍后手動(dòng)插入圖形啄踊。
輸出:
strip.white: (TRUE; logical) Whether to remove blank lines in the beginning or end of a source code block in the output.
strip.white(默認(rèn)為T(mén)):是否移除開(kāi)頭或結(jié)尾的空白行。(實(shí)測(cè):html文檔中F和T均不會(huì)移除空白行刁标,可能是操縱有誤颠通。)class.output: (NULL; character) A vector of class names to be added to the text output blocks. This option only works for HTML output formats in R Markdown. For example, with class.output = c('foo', 'bar'), the text output will be placed in <pre class="foo bar"></pre>.
class.output:(NULL;字符)要添加到文本輸出塊的類(lèi)名稱(chēng)的向量膀懈。 此選項(xiàng)僅適用于R Markdown中的HTML輸出格式顿锰。 例如,使用class.output = c('foo'启搂,'bar')硼控,文本輸出將放置在<pre class =“ foo bar”> </ pre>中。 即文本輸出會(huì)在另一個(gè)塊中胳赌。
class.message/class.warning/class.error: (NULL; character) Similar to class.output, but applied to messages, warnings, and errors in R Markdown output. Please see the “Code Decoration” section for class.source, which applies similarly to source code blocks.
class.message / class.warning / class.error:(NULL牢撼;字符)類(lèi)似于class.output,但適用于R Markdown輸出中的消息疑苫,警告和錯(cuò)誤熏版。 請(qǐng)參閱class.source的“代碼修飾”部分,該部分類(lèi)似地適用于源代碼塊捍掺。attr.output/attr.message/attr.warning/attr.error: (NULL; character) Similar to the class.* options above, but for specifying arbitrary fenced code block attributes for Pandoc; class.* is a special application of attr.*, e.g., class.source = 'numberLines' is equivalent to attr.source = '.numberLines', but attr.source can take arbitrary attribute values, e.g., attr.source = c('.numberLines', 'startFrom="11"').
attr.output / attr.message / attr.warning / attr.error :(空值撼短;字符)類(lèi)似于上面的class∠缧。···選項(xiàng)阔加,但用于為Pandoc指定任意受保護(hù)的代碼塊屬性; class满钟∈だ疲···是attr.···的特殊應(yīng)用,例如湃番,class.source ='numberLines'等效于attr.source ='.numberLines'夭织,但是attr.source可以采用任意屬性值,例如attr.source = c ('.numberLines'吠撮,'startFrom =“ 11”')render: (knitr::knit_print; function(x, options, ...)) A function to print the visible values in a chunk. The value passed to the first argument of this function (i.e., x) is the value evaluated from each expression in the chunk. The list of current chunk options is passed to the argument options. This function is expected to return a character string. For more information, check out the package vignette about custom chunk rendering: vignette('knit_print', package = 'knitr').
render(渲染):(knitr :: knit_print; function(x尊惰,options,...))一個(gè)用于以塊形式打印可見(jiàn)值的函數(shù)泥兰。 傳遞給此函數(shù)的第一個(gè)參數(shù)的值(即x)是從塊中每個(gè)代碼運(yùn)算的值弄屡。 當(dāng)前塊選項(xiàng)列表將傳遞給參數(shù)選項(xiàng)。 該函數(shù)應(yīng)返回一個(gè)字符串鞋诗。 有關(guān)更多信息膀捷,請(qǐng)查看有關(guān)自定義塊渲染的程序包簡(jiǎn)介:vignette('knit_print',package ='knitr')
如果上一個(gè)模塊定義的函數(shù)dummy(x, ...)削彬,這個(gè)函數(shù)無(wú)論傳入什么參數(shù)都只會(huì)告訴你‘nothing’全庸,沒(méi)有render到下一個(gè)模塊秀仲,那么……
現(xiàn)在將render=dummy:
其他的解釋可見(jiàn):vignette('knit_print',package ='knitr')中的render壶笼。
-
split: (FALSE; logical) Whether to split the output into separate files and include them in LaTeX by \input{} or HTML by <iframe></iframe>. This option only works for .Rnw, .Rtex, and .Rhtml documents.
(默認(rèn)為F神僵;邏輯)是將輸出拆分為單獨(dú)的文件,然后通過(guò)\ input {}將其包含在LaTeX中(選T時(shí))覆劈,還是通過(guò)<iframe> </ iframe>將其包含在HTML中(選F時(shí))保礼。 此選項(xiàng)僅適用于.Rnw,.Rtex和.Rhtml文檔 墩崩。
這個(gè)在html文檔操作時(shí)也沒(méi)發(fā)現(xiàn)有什么變化氓英。
Code decoration
-
tidy: (FALSE) Whether to reformat the R code. Other possible values are as follows:將R代碼重新排列整齊侯勉,默認(rèn)為F鹦筹。
- TRUE (equivalent to tidy = 'formatR'): Call the function formatR::tidy_source() to reformat the code. T等同于"formatR",使用formatR::tidy_source() 函數(shù)來(lái)整理址貌。
- 'styler': Use styler::style_text() to reformat the code.
- A custom function of the form function(code, ...) {} to return the reformatted code.
- If reformatting fails, the original R code will not be changed (with a warning).
tidy.opts
: (NULL
; list) A list of options to be passed to the function determined by thetidy
option, e.g.,tidy.opts = list(blank = FALSE, width.cutoff = 60)
fortidy = 'formatR'
to remove blank lines and try to cut the code lines at 60 characters.
默認(rèn)為NULL铐拐,決定tidy的選項(xiàng)。比如tidy.opts = list(blank = FALSE, width.cutoff = 60)
就是移除空白行并且將代碼剪為60個(gè)字符练对。
-
prompt
: (FALSE
; logical) Whether to add the prompt characters in the R code. Seeprompt
andcontinue
on the help page?base::options
. Note that adding prompts can make it difficult for readers to copy R code from the output, soprompt = FALSE
may be a better choice. This option may not work well when the chunk optionengine
is notR
(#1274).
(默認(rèn)為F; 邏輯)是否在R代碼中添加提示字符遍蟋。
請(qǐng)參閱幫助頁(yè)面base :: options上的提示和繼續(xù)。
請(qǐng)注意螟凭,添加提示可能會(huì)使讀者難以從輸出中復(fù)制R代碼虚青,因此``prompt=F''可能是一個(gè)更好的選擇。
當(dāng)塊選項(xiàng)引擎不是R時(shí)螺男,此選項(xiàng)可能無(wú)法正常工作棒厘。
效果:
prompt=T時(shí)在每段前邊會(huì)有一個(gè)>符號(hào)。
- comment: ('##'; character) The prefix to be added before each line of the text output.
By default, the text output is commented out by ##, so if readers want to copy and run the source code from the output document, they can select and copy everything from the chunk, since the text output is masked in comments (and will be ignored when running the copied text). Set comment = ' ' remove the default ##.
在文本輸出的每一行之前添加的前綴(兩個(gè)井號(hào))下隧。
如果讀者想復(fù)制并運(yùn)行輸出文檔中的源代碼奢人,他們可以選擇并復(fù)制塊中的所有內(nèi)容,因?yàn)槲谋据敵霰蛔⑨屟谏w了(并且將 運(yùn)行復(fù)制的文本時(shí)被忽略)淆院。 設(shè)置注釋=' '可以刪除默認(rèn)的##何乎,文本輸出前邊沒(méi)有注釋。括號(hào)中也可以添加其他內(nèi)容土辩,輸出文本前就會(huì)有設(shè)定好的內(nèi)容
highlight: (TRUE; logical) Whether to syntax highlight the source code.高亮(默認(rèn)為true)支救,不同類(lèi)型的元素會(huì)用不同的顏色高亮出來(lái)。上圖中就是數(shù)字為藍(lán)色拷淘,引號(hào)內(nèi)為淺紅色各墨,‘function’為深紅色
class.source: (NULL; character) Class names for source code blocks in the output document. Similar to the class.* options for output such as class.output.
attr.source: (NULL; character) Attributes for source code blocks. Similar to the attr.* options for output such as attr.output.
size
: ('normalsize'
; character) Font size of the chunk output from.Rnw
documents. See this page for possible sizes.background
: ('#F7F7F7'
; character) Background color of the chunk output of.Rnw
documents. 背景。(默認(rèn)為#F7F7F7辕棚,天空灰)
FFFFFF為純白
-
indent
: (character) A string to be added to each line of the chunk output.
Typically it consists of white spaces.
This option is assumed to be read-only, and knitr sets its value while parsing the document.
For example, for the chunk below,indent
is a character string of two spaces:
```{r}
rnorm(10)
```
indent(字符)要添加到塊輸出的每一行的字符串欲主。 通常邓厕,它由空白組成。 通常此選項(xiàng)為只讀扁瓢,并且** knitr **在解析文檔時(shí)設(shè)置其值详恼。 例如,對(duì)于下面的塊引几,'indent`是兩個(gè)空格的字符串:
@[toc]( <center> knitr翻譯02)
title: "Untitled"
author: "ks_c"
date: "2021/1/31"
output: html_document
本次翻譯接下來(lái)三節(jié):
Cache
1.cache
-
cache
: (FALSE
; logical) Whether to cache a code chunk.
When evaluating code chunks for the second time, the cached chunks are skipped (unless they have been modified), but the objects created in these chunks are loaded from previously saved databases (.rdb
and.rdx
files), and these files are saved when a chunk is evaluated for the first time, or when cached files are not found (e.g., you may have removed them by hand).
Note that the filename consists of the chunk label with an MD5 digest of the R code and chunk options of the code chunk, which means any changes in the chunk will produce a different MD5 digest, and hence invalidate the cache. See more information on this page.
(默認(rèn)為FALSE;邏輯)是否緩存代碼塊昧互。
當(dāng)?shù)诙芜\(yùn)行代碼塊時(shí),將跳過(guò)緩存的塊(除非已對(duì)其進(jìn)行修改)伟桅,但是在這些塊中創(chuàng)建的對(duì)象是從先前保存的數(shù)據(jù)庫(kù)(.rdb和.rdx文件)中加載的敞掘,這些第一次運(yùn)行塊時(shí)或未找到緩存文件時(shí)(例如,您可能已手動(dòng)刪除它們)楣铁,文件將被保存玖雁。
請(qǐng)注意,文件名由帶有R代碼的MD5摘要和代碼塊的塊選項(xiàng)的塊標(biāo)簽組成盖腕,這意味著該塊中的任何更改都會(huì)產(chǎn)生不同的MD5摘要赫冬,從而使緩存無(wú)效。
2. cache.path
-
cache.path
: ('cache/'
; character) A prefix to be used to generate the paths of cache files. For R Markdown, the default value is based on the input filename, e.g., the cache paths for the chunk with the labelFOO
in the fileINPUT.Rmd
will be of the formINPUT_cache/FOO_*.*
.
('cache /'
; 字符串)用于生成緩存文件路徑的前綴溃列。 對(duì)于R Markdown劲厌,默認(rèn)值基于輸入文件名,例如听隐,文件INPUT.Rmd中標(biāo)簽為FOO''的塊的緩存路徑將采用
INPUT_cache / FOO _ 补鼻。''的形式。
3. cache.vars
-
cache.vars
: (NULL
; character) A vector of variable names to be saved in the cache database. By default, all variables created in the current chunks are identified and saved, but you may want to manually specify the variables to be saved, because the automatic detection of variables may not be robust, or you may want to save only a subset of variables.
(默認(rèn)NULL雅任,字符)要保存在緩存數(shù)據(jù)庫(kù)中的變量名的向量风范。 默認(rèn)情況下,將識(shí)別并保存在當(dāng)前塊中創(chuàng)建的所有變量椿访,但是您可能希望手動(dòng)指定要保存的變量乌企,因?yàn)樽詣?dòng)檢測(cè)變量可能不夠可靠,或者您可能只想保存一部分變量
4. cache.globals
-
cache.globals
: (NULL
; character) A vector of the names of variables that are not created from the current chunk. This option is mainly forautodep = TRUE
to work more precisely—a chunkB
depends on chunkA
when any ofB
’s global variables areA
’s local variables. In case the automatic detection of global variables in a chunk fails, you may manually specify the names of global variables via this option (see #1403for an example).
(默認(rèn)為NULL
成玫;字符串)不是從當(dāng)前塊創(chuàng)建的變量名的向量加酵。 此選項(xiàng)主要是為了使autodep = TRUE更精確地工作---當(dāng)B模塊的變量是A模塊的變量時(shí),B依靠A哭当。 如果自動(dòng)檢測(cè)塊中的全局變量失敗猪腕,則可以通過(guò)此選項(xiàng)手動(dòng)指定全局變量的名稱(chēng)
5. cache.lazy
-
cache.lazy
: (TRUE
; logical) Whether tolazyLoad()
or directlyload()
objects. For very large objects, lazyloading may not work, socache.lazy = FALSE
may be desirable (see #572).
延遲加載(默認(rèn)為T(mén))是要lazyLoad()還是直接是load()對(duì)象。 對(duì)于非常大的對(duì)象钦勘,延遲加載可能不起作用陋葡,因此可能需要``cache.lazy = FALSE''
6. cache.comments
-
cache.comments
: (NULL
; logical) IfFALSE
, changing comments in R code chunks will not invalidate the cache database.
(NULL;邏輯)如果為FALSE彻采,則在R代碼塊中更改注釋不會(huì)使高速緩存數(shù)據(jù)庫(kù)無(wú)效
7. cache.rebuild
-
cache.rebuild
: (FALSE
; logical) IfTRUE
, reevaluate the chunk even if the cache does not need to be invalidated. This can be useful when you want to conditionally invalidate the cache, e.g.,cache.rebuild = !file.exists("some-file")
can rebuild the chunk whensome-file
does not exist (see #238).
(FALSE
;邏輯)如果為``TRUE''腐缤,則即使不需要使緩存無(wú)效也要重新運(yùn)行源碼塊捌归。 當(dāng)您想有條件地使緩存無(wú)效時(shí),這很有用岭粤,例如惜索,cache.rebuild =!file.exists(“ some-file”)
可以在不存在some-file`的情況下重建塊
8. dependson
dependson
: (NULL
; character or numeric) A character vector of chunk labels to specify which other chunks this chunk depends on. This option applies to cached chunks only—sometimes the objects in a cached chunk may depend on other cached chunks, so when other chunks are changed, this chunk must be updated accordingly.
dependson
:(NULL
剃浇;字符或數(shù)字)塊標(biāo)簽的字符向量巾兆,用于指定該塊所依賴(lài)的其他塊。 此選項(xiàng)僅適用于高速緩存的塊-有時(shí)虎囚,高速緩存的塊中的對(duì)象可能取決于其他高速緩存的塊角塑,因此,在更改其他大塊時(shí)淘讥,必須相應(yīng)地更新該大塊圃伶。If
dependson
is a numeric vector, it means the indices of chunk labels, e.g.,dependson = 1
means this chunk depends on the first chunk in the document, anddependson = c(-1, -2)
means it depends on the previous two chunks (negative indices stand for numbers of chunks before this chunk, and note they are always relative to the current chunk).如果Dependson是數(shù)字向量,則表示塊標(biāo)簽的索引适揉,例如Dependson = 1表示此塊取決于文檔中的第一個(gè)塊留攒,而Dependson = c(-1,-2)表示 它取決于前兩個(gè)塊(負(fù)索引代表該塊之前的塊數(shù)嫉嘀,請(qǐng)注意,它們始終相對(duì)于當(dāng)前塊)魄揉。Please note this option does not work when set as a global chunk option via
opts_chunk$set()
; it must be set as a local chunk option.請(qǐng)注意剪侮,通過(guò)opts_chunk $ set()設(shè)置為全局塊選項(xiàng)時(shí),此選項(xiàng)不起作用; 必須將其設(shè)置為本地塊選項(xiàng)洛退。autodep
: (FALSE
; logical) Whether to analyze dependencies among chunks automatically by detecting global variables in the code (may not be reliable), sodependson
does not need to be set explicitly.autodep:(FALSE;邏輯)是否通過(guò)檢測(cè)代碼中的全局變量來(lái)自動(dòng)分析塊之間的依賴(lài)關(guān)系(可能不可靠)瓣俯,所以不需要顯式設(shè)置dependson。
Plots
fig.path
: ('figure/'
; character) A prefix to be used to generate figure file paths.fig.path
and chunk labels are concatenated to generate the full paths. It may contain a directory likefigure/prefix-
; the directory will be created if it does not exist.('figure /'; character)用于生成圖形文件路徑的前綴兵怯。 fig.path和塊標(biāo)簽被串聯(lián)以生成完整路徑彩匕。 它可能包含一個(gè)目錄,如圖/前綴-; 如果目錄不存在,將創(chuàng)建該目錄棍辕。fig.keep
: ('high'
; character) How plots in chunks should be kept. Possible values are as follows:如何保存代碼塊中的圖
* `high`: Only keep high-level plots (merge low-level changes into high-level plots).僅保留高級(jí)繪圖搔涝,低級(jí)圖被融合進(jìn)高級(jí)圖中
* `none`: Discard all plots.不保存
* `all`: Keep all plots (low-level plot changes may produce new plots).保存所有圖
* `first`: Only keep the first plot.只保留第一張圖
* `last`: Only keep the last plot.只保留最后一張圖
* If set to a numeric vector, the values are indices of (low-level) plots to keep. 數(shù)值向量為保存第幾張圖
Low-level plotting commands include `lines()` and `points()`, etc. To better understand `fig.keep`, consider the following chunk:
```
```{r, test-plot}
plot(1) # high-level plot
abline(0, 1) # low-level change
plot(rnorm(10)) # high-level plot
# many low-level changes in a loop (a single R expression)
for(i in 1:10) {
abline(v = i, lty = 2)
}
```
```
Normally this produces 2 plots in the output (because `fig.keep = 'high'`). For `fig.keep = 'none'`, no plots will be saved. For `fig.keep = 'all'`, 4 plots are saved. For `fig.keep = 'first'`, the plot produced by `plot(1)` is saved. For `fig.keep = 'last'`, the last plot with 10 vertical lines is saved.
-
fig.show
: ('asis'
; character) How to show/arrange the plots. Possible values are as follows:如何顯示/安排圖。 可能的值如下:
該部分類(lèi)似文字輸出部分的設(shè)置舶掖。
* `asis`: Show plots exactly in places where they were generated (as if the code were run in an R terminal).該在哪在哪
* `hold`: Hold all plots and output them at the end of a code chunk.所有圖都在最后
* `animate`: Concatenate all plots into an animation if there are multiple plots in a chunk.多個(gè)圖變成動(dòng)畫(huà)連續(xù)播放
* `hide`: Generate plot files but hide them in the output document. 隱藏
-
dev
: ('pdf'
for LaTeX output and'png'
for HTML/Markdown; character) The graphical device to generate plot files. All graphics devices in base R and those in Cairo, cairoDevice, svglite, ragg, and tikzDevice are supported, e.g.,pdf
,png
,svg
,jpeg
,tiff
,cairo_pdf
,CairoJPEG
,CairoPNG
,Cairo_pdf
,Cairo_png
,svglite
,ragg_png
,tikz
, and so on. Seenames(knitr:::auto_exts)
for the full list. Besides these devices, you can also provide a character string that is the name of a function of the formfunction(filename, width, height)
. The units for the image size are always inches (even for bitmap devices, in which DPI is used to convert between pixels and inches).
輸出格式。(對(duì)于LaTeX輸出是pdf'',對(duì)于HTML / Markdown是
png''; 字符)用于生成繪圖文件的圖形設(shè)備奠货。
支持Base R中的所有圖形設(shè)備以及** Cairo , cairoDevice 座掘, svglite 递惋, ragg 和 tikzDevice *中的所有圖形設(shè)備柔滔,例如pdf,png 萍虽,svg廊遍,jpeg,tiff贩挣,cairo_pdf喉前,cairoJPEG,cairoPNG王财,cairo_pdf卵迂,cairo_png,svglite绒净,ragg_png见咒,tikz等。 有關(guān)完整列表挂疆,請(qǐng)參見(jiàn)names(knitr ::: auto_exts)
改览。 除了這些設(shè)備之外,您還可以提供一個(gè)字符串缤言,該字符串是形式為function(文件名宝当,寬度,高度)的函數(shù)的名稱(chēng)胆萧。 圖像大小的單位始終是英寸(即使對(duì)于位圖設(shè)備庆揩,其中DPI用于在像素和英寸之間進(jìn)行轉(zhuǎn)換)。
The chunk options `dev`, `fig.ext`, `fig.width`, `fig.height`, and `dpi` can be vectors (shorter ones will be recycled), e.g., `dev = c('pdf', 'png')` creates a `PDF` and a `PNG`file for the same plot.201 / 5000跌穗。dev订晌,fig.ext,fig.width蚌吸,fig.height和dpi的塊選項(xiàng)可以是向量(較短的將被回收)锈拨,例如dev = c('pdf' ,'png')`為同一圖創(chuàng)建一個(gè)PDF文件和一個(gè)PNG文件羹唠。
dev.args
: (NULL
; list) More arguments to be passed to the device, e.g.,dev.args = list(bg = 'yellow', pointsize = 10)
fordev = 'png'
. This option depends on the specific device (see the device documentation). Whendev
contains multiple devices,dev.args
can be a list of lists of arguments, and each list of arguments is passed to each individual device, e.g.,dev = c('pdf', 'tiff'), dev.args = list(pdf = list(colormodel = 'cmyk', useDingats = TRUE), tiff = list(compression = 'lzw'))
.dev.args:(
NULL; list)更多的參數(shù)要傳遞給設(shè)備奕枢,例如,
dev.args = list(bg ='yellow'肉迫,pointssize = 10)验辞。 此選項(xiàng)取決于特定的設(shè)備(請(qǐng)參閱設(shè)備文檔)。 當(dāng)
dev包含多個(gè)設(shè)備時(shí)喊衫,
dev.args可以是參數(shù)列表的列表跌造,并且每個(gè)參數(shù)列表都傳遞給每個(gè)單獨(dú)的設(shè)備,例如,
dev = c('pdf'壳贪,'tiff')陵珍, dev.args = list(pdf = list(顏色模型='cmyk',useDingats = TRUE)违施,tiff = list(壓縮='lzw'))`fig.ext
: (NULL
; character) File extension of the figure output. IfNULL
, it will be derived from the graphical device; seeknitr:::auto_exts
for details.fig.ext
:(NULL
;字符)圖形輸出的文件擴(kuò)展名互纯。 如果為NULL,它將從圖形設(shè)備派生; 有關(guān)詳細(xì)信息磕蒲,請(qǐng)參見(jiàn)knitr ::: auto_exts
留潦。dpi
: (72
; numeric) The DPI (dots per inch) for bitmap devices (dpi * inches = pixels
).72;數(shù)字)位圖設(shè)備的DPI(每英寸點(diǎn)數(shù))(dpi *英寸=像素)辣往。fig.width
,fig.height
: (both are7
; numeric) Width and height of the plot (in inches), to be used in the graphics device.
圖片的高度和寬度兔院,英寸fig.asp
: (NULL
; numeric) The aspect ratio of the plot, i.e., the ratio of height/width. Whenfig.asp
is specified, the height of a plot (the chunk optionfig.height
) is calculated fromfig.width * fig.asp
.
寬高比。(NULL
;數(shù)字)繪圖的長(zhǎng)寬比站削,即高/寬比坊萝。 當(dāng)指定fig.asp
時(shí),圖的高度(fig.height塊選項(xiàng))是從fig.width * fig.asp
中計(jì)算出來(lái)的许起。fig.dim
: (NULL
; numeric) A numeric vector of length 2 to providefig.width
andfig.height
, e.g.,fig.dim = c(5, 7)
is a shorthand offig.width = 5, fig.height = 7
. If bothfig.asp
andfig.dim
are provided,fig.asp
will be ignored (with a warning).
(NULL
;數(shù)字)一個(gè)長(zhǎng)度為2的數(shù)字向量十偶,以提供fig.width
和fig.height
,例如fig.dim = c(5园细,7)
是簡(jiǎn)寫(xiě)形式 圖寬度= 5惦积,圖高度= 7。 如果同時(shí)提供了fig.asp
和fig.dim
珊肃,則fig.asp
將被忽略(帶有警告)荣刑。out.width
,out.height
: (NULL
; character) Width and height of the plot in the output document, which can be different with its physicalfig.width
andfig.height
, i.e., plots can be scaled in the output document. Depending on the output format, these two options can take special values. For example, for LaTeX output, they can be.8\\linewidth
,3in
, or8cm
; for HTML, they may be300px
. For.Rnw
documents, the default value forout.width
will be changed to\\maxwidth
, which is defined on this page. It can also be a percentage, e.g.,'40%'
will be translated to0.4\linewidth
when the output format is LaTeX.
(NULL
;字符)輸出文檔中繪圖的寬度和高度,可以與它的物理fig.width
和fig.height
不同伦乔,即 ,可以在輸出文檔中縮放繪圖董习。 根據(jù)輸出格式烈和,這兩個(gè)選項(xiàng)可以采用特殊值。 例如皿淋,對(duì)于LaTeX輸出招刹,它們可以是.8 \ linewidth,3in或8cm; 對(duì)于HTML窝趣,它們可能是300px疯暑。 對(duì)于.Rnw文檔,out.width的默認(rèn)值將更改為\ maxwidth哑舒,此值在此頁(yè)面上定義妇拯。](https://yihui.org/knitr/demo/framed/ )也可以是一個(gè)百分比,例如,當(dāng)輸出格式為L(zhǎng)aTeX時(shí)越锈,40%''將轉(zhuǎn)換為
0.4 \ linewidth''仗嗦。out.extra
: (NULL
; character) Extra options for figures. It can be an arbitrary string, to be inserted in\includegraphics[]
in LaTeX output (e.g.,out.extra = 'angle=90'
to rotate the figure by 90 degrees), or<img />
in HTML output (e.g.,out.extra = 'style="border:5px solid orange;"'
).(NULL
;字符)數(shù)字的額外選項(xiàng)。 它可以是任意字符串甘凭,可以插入LaTeX輸出的\ includegraphics []中(例如稀拐,out.extra ='angle = 90'將圖形旋轉(zhuǎn)90度),或<img />` 在HTML輸出中(例如丹弱,out.extra ='style =“ border:5px實(shí)心橙色;”')德撬。fig.retina
: (1
; numeric) This option only applies to HTML output. For Retina displays, setting this option to a ratio (usually 2) will change the chunk optiondpi
todpi * fig.retina
, andout.width
tofig.width * dpi / fig.retina
internally. For example, the physical size of an image is doubled, and its display size is halved whenfig.retina = fig.retina
:
(1; 數(shù)字)此選項(xiàng)僅適用于HTML輸出。 對(duì)于[Retina顯示器躲胳,](http://en.wikipedia.org/wiki/Retina_Display)將此選項(xiàng)設(shè)置為比率(通常為2)將將dpi''更改為
dpi * fig.retina''蜓洪,然后 在內(nèi)部將圖寬到圖寬 dpi /圖視網(wǎng)膜。 例如泛鸟,當(dāng)fig.retina = 2
時(shí)蝠咆,圖像的物理尺寸增加了一倍,顯示尺寸減半北滥。resize.width
,resize.height
: (NULL
; character) The width and height to be used in\resizebox{}{}
in LaTeX output. These two options are not needed unless you want to resize TikZ graphics, because there is no natural way to do it. However, according to the tikzDevice authors, TikZ graphics are not meant to be resized, to maintain consistency in style with other text in LaTeX. If only one of them isNULL
,!
will be used (read the documentation of graphicx if you do not understand this).
resize.width刚操,resize.height
:(NULL
;字符)LaTeX輸出中\(zhòng) resizebox {} {}中要使用的寬度和高度。 除非您想要調(diào)整TikZ圖形的大小再芋,否則不需要這兩個(gè)選項(xiàng)菊霜,因?yàn)闆](méi)有自然的方法可以做到這一點(diǎn)。 但是济赎,據(jù)tikzDevice 的作者稱(chēng)鉴逞,TikZ圖形并非要調(diào)整大小,以保持與LaTeX中其他文本的樣式一致性司训。 如果其中只有一個(gè)為``NULL''构捡,則將使用!!(如果您不了解,請(qǐng)閱讀 graphicx **的文檔)壳猜。fig.align
: ('default'
; character) Alignment of figures in the output document. Possible values aredefault
,left
,right
, andcenter
. The default is not to make any alignment adjustments.
(`'default';; character)輸出文檔中圖形的對(duì)齊勾徽。 可能的值為“默認(rèn)”,“左”统扳,“右”和“中心”喘帚。 默認(rèn)設(shè)置是不進(jìn)行任何對(duì)齊調(diào)整fig.link
: (NULL
; character) A link to be added onto the figure.fig.env
: ('figure'
; character) The LaTeX environment for figures, e.g., you may setfig.env = 'marginfigure'
to get\begin{marginfigure}
. This option requiresfig.cap
be specified.fig.cap
: (NULL
; character) A figure caption.fig.alt
: (NULL
; character) The alternative text to be used in thealt
attribute of the<img>
tags of figures in HTML output. By default, the chunk optionfig.cap
will be used as the alternative text if provided.fig.scap
: (NULL
; character) A short caption. This option is only meaningful to LaTeX output. A short caption is inserted in\caption[]
, and usually displayed in the “List of Figures” of a PDF document.fig.lp
: ('fig:'
; character) A label prefix for the figure label to be inserted in\label{}
. The actual label is made by concatenating this prefix and the chunk label, e.g., the figure label for ````{r, foo-plot}will be
fig:foo-plotby default. lable{}中可以插入圖形標(biāo)簽的前綴。 實(shí)際的標(biāo)簽是通過(guò)該前綴和塊標(biāo)簽制成的咒钟,例如吹由,{r,foo-plot}的圖形標(biāo)簽?zāi)J(rèn)情況下將為
fig:foo-plot`朱嘴。fig.pos
: (''
; character) A character string for the figure position arrangement to be used in\begin{figure}[]
.fig.subcap
: (NULL
) Captions for subfigures. When there are multiple plots in a chunk, and neitherfig.subcap
norfig.cap
isNULL
,\subfloat{}
will be used for individual plots (you need to add\usepackage{subfig}
in the preamble). See 067-graphics-options.Rnw for an example.fig.ncol
: (NULL
; integer) The number of columns of subfigures; see this issue for examples (note thatfig.ncol
andfig.sep
only work for LaTeX output).fig.sep
: (NULL
; character) A character vector of separators to be inserted among subfigures. Whenfig.ncol
is specified,fig.sep
defaults to a character vector of which every N-th element is\newline
(whereN
is the number of columns), e.g.,fig.ncol = 2
meansfig.sep = c('', '', '\\newline', '', '', '\\newline', '', ...)
.fig.process
: (NULL
; function) A function to post-process figure files. It should take the path of a figure file, and return the (new) path of the figure to be inserted in the output. If the function contains theoptions
argument, the list of chunk options will be passed to this argument.fig.showtext
: (NULL
; logical) IfTRUE
, callshowtext::showtext_begin()
before drawing plots. See the documentation of the showtext package for details.external
: (TRUE
; logical) Whether to externalize tikz graphics (pre-compile tikz graphics to PDF). It is only used for thetikz()
device in the tikzDevice package (i.e., whendev='tikz'
), and it can save time for LaTeX compilation.sanitize
: (FALSE
; character) Whether to sanitize tikz graphics (escape special LaTeX characters). See the documentation of the tikzDevice package.
There are two hidden options that are not designed to be set by users: fig.cur
(the current figure number or index when there are multiple figures), and fig.num
(the total number of figures in a chunk). The purpose of these two options is to help knitr deal with the filenames of multiple figures as well as animations. In some cases, we can make use of them to write animations into the output using plot files that are saved manually (see the graphics manual for examples).
Animation
interval
: (1
; numeric) Time interval (number of seconds) between animation frames.默認(rèn)為1秒倾鲫,動(dòng)畫(huà)幀之間的時(shí)間間隔(秒數(shù))animation.hook
: (knitr::hook_ffmpeg_html
; function or character) A hook function to create animations in HTML output; the default hook uses FFmpeg to convert images to a WebM video.(默認(rèn)為knitr :: hook_ffmpeg_html
;函數(shù)或字符)用于在HTML輸出中創(chuàng)建動(dòng)畫(huà)的鉤子函數(shù); 默認(rèn)掛鉤使用FFmpeg將圖像轉(zhuǎn)換為WebM視頻级乍。
- Another hook function is
knitr::hook_gifski
based on the gifski package to create GIF animations.另一個(gè)掛鉤函數(shù)是基于** gifski **包的knitr :: hook_gifski`來(lái)創(chuàng)建GIF動(dòng)畫(huà)舌劳。
This option can also take a character string
'ffmpeg'
or'gifski'
as a shorthand of the corresponding hook function, e.g.,animation.hook = 'gifski'
meansanimation.hook = knitr::hook_gifski
.此選項(xiàng)還可以將字符串'ffmpeg'
或'gifski'作為對(duì)應(yīng)的鉤子函數(shù)的簡(jiǎn)寫(xiě),例如玫荣,animation.hook ='gifski'意味著animation.hook = knitr :: hook_gifski 甚淡。aniopts
: ('controls,loop'
; character) Extra options for animations; see the documentation of the LaTeX animate package.
ffmpeg.bitrate
(1M
; character) To be passed to the-b:v
argument of FFmpeg to control the quality of WebM videos.動(dòng)畫(huà)的額外選項(xiàng); 請(qǐng)參閱LaTeX ** animate **軟件包的文檔ffmpeg.format
(webm
; character) The video format of FFmpeg, i.e., the filename extension of the video.webm
; character)FFmpeg的視頻格式捅厂,即視頻的文件擴(kuò)展名贯卦。
@[toc]( <center> knitr翻譯03)
title: "Untitled"
author: "ks_c"
date: "2021/2/1"
output: html_document
- Code chunk #代碼塊
- Child documents #子文件(?)
- Language engines #語(yǔ)言引擎
- Option templates #選項(xiàng)模板
- Extracting source code #提取源碼
- Other chunk options # 其他設(shè)置
- Package Options # 包的設(shè)置
Code chunk
code
: (NULL
; character) If provided, it will override the code in the current chunk. This allows us to programmatically insert code into the current chunk. For example,code = readLines('test.R')
will use the content of the filetest.R
as the code for the current chunk.
(NULL
;字符)如果提供,它將覆蓋當(dāng)前塊中的代碼焙贷。 這使我們能夠以編程方式將代碼插入當(dāng)前塊中撵割。 例如,code = readLines('test.R')將使用test.R文件的內(nèi)容作為當(dāng)前塊的代碼辙芍。ref.label
: (NULL
; character) A character vector of labels of the chunks from which the code of the current chunk is inherited (see the demo for chunk references).
(NULL
; character)當(dāng)前塊代碼是來(lái)自哪個(gè)塊的標(biāo)簽啡彬,字符向量
Child documents
-
child
: (NULL
; character) A character vector of paths of child documents to be knitted and input into the main document.子文件夾輸出到哪里的路徑
Language engines
engine
: ('R'
; character) The language name of the code chunk. Possible values can be found innames(knitr::knit_engines$get())
, e.g.,python
,sql
,julia
,bash
, andc
, etc. The objectknitr::knit_engines
can be used to set up engines for other languages.
當(dāng)前代碼塊的語(yǔ)言名稱(chēng),比如python故硅、sql庶灿、julia、c等-
engine.path
: (NULL
; character) The path to the executable of theengine
. This option makes it possible to use alternative executables in your system, e.g., the defaultpython
may be at/usr/bin/python
, and you may setengine.path = '~/anaconda/bin/python'
to use a different version of Python.
引擎的路徑吃衅。 此選項(xiàng)使您可以在系統(tǒng)中使用其他可執(zhí)行文件往踢,例如,默認(rèn)的python
可能位于/ usr / bin / python中徘层,并且您可以設(shè)置
engine.path ='?/ anaconda / bin / python' 使用其他版本的Python峻呕。engine.path
can also be a list of paths, which makes it possible to set different engine paths for different engines, e.g.,也可以同時(shí)為不同的引擎設(shè)置不同的路徑。
knitr::opts_chunk$set(engine.path = list(
python = '~/anaconda/bin/python',
ruby = '/usr/local/bin/ruby'
))
The names of the list correspond to the names of the engines.
Option templates
opts.label: (NULL; character) The label of options set in knitr::opts_template (see ?knitr::opts_template). This option can save some typing effort for sets of frequently used chunk options.
Extracting source code
purl: (TRUE; logical) When running knitr::purl() to extract source code from a source document, whether to include or exclude a certain code chunk.
Other chunk options
R.options: (NULL; list) Local R options for a code chunk. These options are set temporarily via options() before the code chunk, and restored after the chunk.