R markdown笔记04-knitr02

@[toc]( <center> knitr翻译02)


title: "Untitled"
author: "ks_c"
date: "2021/1/31"
output: html_document


本次翻译接下来三节:


Cache

1.cache

  1. 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.
    (默认为FALSE;逻辑)是否缓存代码块。
    当第二次运行代码块时,将跳过缓存的块(除非已对其进行修改),但是在这些块中创建的对象是从先前保存的数据库(.rdb和.rdx文件)中加载的,这些第一次运行块时或未找到缓存文件时(例如,您可能已手动删除它们),文件将被保存。
    请注意,文件名由带有R代码的MD5摘要和代码块的块选项的块标签组成,这意味着该块中的任何更改都会产生不同的MD5摘要,从而使缓存无效。

2. cache.path

  1. 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 label FOO in the file INPUT.Rmd will be of the form INPUT_cache/FOO_*.*.
    ('cache /'; 字符串)用于生成缓存文件路径的前缀。 对于R Markdown,默认值基于输入文件名,例如,文件INPUT.Rmd中标签为FOO''的块的缓存路径将采用INPUT_cache / FOO _ ''的形式。

3. cache.vars

  1. 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.
    (默认NULL,字符)要保存在缓存数据库中的变量名的向量。 默认情况下,将识别并保存在当前块中创建的所有变量,但是您可能希望手动指定要保存的变量,因为自动检测变量可能不够可靠,或者您可能只想保存一部分变量

4. cache.globals

  1. cache.globals: (NULL; character) A vector of the names of variables that are not created from the current chunk. This option is mainly for autodep = TRUE to work more precisely—a chunk B depends on chunk A when any of B’s global variables are A’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).
    (默认为NULL;字符串)不是从当前块创建的变量名的向量。 此选项主要是为了使autodep = TRUE更精确地工作---当B模块的变量是A模块的变量时,B依靠A。 如果自动检测块中的全局变量失败,则可以通过此选项手动指定全局变量的名称

5. cache.lazy

  1. cache.lazy: (TRUE; logical) Whether to lazyLoad() or directly load() objects. For very large objects, lazyloading may not work, so cache.lazy = FALSE may be desirable (see #572).
    延迟加载(默认为T)是要lazyLoad()还是直接是load()对象。 对于非常大的对象,延迟加载可能不起作用,因此可能需要``cache.lazy = FALSE''

6. cache.comments

  • cache.comments: (NULL; logical) If FALSE, changing comments in R code chunks will not invalidate the cache database.
    (NULL;逻辑)如果为FALSE,则在R代码块中更改注释不会使高速缓存数据库无效

7. cache.rebuild

  • cache.rebuild: (FALSE; logical) If TRUE, 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 when some-file does not exist (see #238).
    FALSE;逻辑)如果为``TRUE'',则即使不需要使缓存无效也要重新运行源码块。 当您想有条件地使缓存无效时,这很有用,例如,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;字符或数字)块标签的字符向量,用于指定该块所依赖的其他块。 此选项仅适用于高速缓存的块-有时,高速缓存的块中的对象可能取决于其他高速缓存的块,因此,在更改其他大块时,必须相应地更新该大块。

  • 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, and dependson = 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是数字向量,则表示块标签的索引,例如Dependson = 1表示此块取决于文档中的第一个块,而Dependson = c(-1,-2)表示 它取决于前两个块(负索引代表该块之前的块数,请注意,它们始终相对于当前块)。

  • 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.请注意,通过opts_chunk $ set()设置为全局块选项时,此选项不起作用; 必须将其设置为本地块选项。

  • autodep: (FALSE; logical) Whether to analyze dependencies among chunks automatically by detecting global variables in the code (may not be reliable), so dependson does not need to be set explicitly.autodep:(FALSE;逻辑)是否通过检测代码中的全局变量来自动分析块之间的依赖关系(可能不可靠),所以不需要显式设置dependson。

Plots

  1. 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 like figure/prefix-; the directory will be created if it does not exist.('figure /'; character)用于生成图形文件路径的前缀。 fig.path和块标签被串联以生成完整路径。 它可能包含一个目录,如图/前缀-; 如果目录不存在,将创建该目录。

  2. 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).仅保留高级绘图,低级图被融合进高级图中
*   `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. 数值向量为保存第几张图

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.
  1. fig.show: ('asis'; character) How to show/arrange the plots. Possible values are as follows:如何显示/安排图。 可能的值如下:
    该部分类似文字输出部分的设置。
*   `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.多个图变成动画连续播放
*   `hide`: Generate plot files but hide them in the output document. 隐藏
  1. 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. See names(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 form function(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).
    输出格式。(对于LaTeX输出是pdf'',对于HTML / Markdown是png''; 字符)用于生成绘图文件的图形设备。
    支持Base R中的所有图形设备以及** Cairo cairoDevice svglite ragg tikzDevice *中的所有图形设备,例如pdf,png ,svg,jpeg,tiff,cairo_pdf,cairoJPEG,cairoPNG,cairo_pdf,cairo_png,svglite,ragg_png,tikz等。 有关完整列表,请参见names(knitr ::: auto_exts)。 除了这些设备之外,您还可以提供一个字符串,该字符串是形式为function(文件名,宽度,高度)的函数的名称。 图像大小的单位始终是英寸(即使对于位图设备,其中DPI用于在像素和英寸之间进行转换)。
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的块选项可以是向量(较短的将被回收),例如dev = c('pdf' ,'png')`为同一图创建一个PDF文件和一个PNG文件。 
  1. dev.args: (NULL; list) More arguments to be passed to the device, e.g., dev.args = list(bg = 'yellow', pointsize = 10) for dev = 'png'. This option depends on the specific device (see the device documentation). When dev 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)更多的参数要传递给设备,例如,dev.args = list(bg ='yellow',pointssize = 10)。 此选项取决于特定的设备(请参阅设备文档)。 当dev包含多个设备时,dev.args可以是参数列表的列表,并且每个参数列表都传递给每个单独的设备,例如,dev = c('pdf','tiff'), dev.args = list(pdf = list(颜色模型='cmyk',useDingats = TRUE),tiff = list(压缩='lzw'))`

  2. fig.ext: (NULL; character) File extension of the figure output. If NULL, it will be derived from the graphical device; see knitr:::auto_exts for details.fig.ext:(NULL;字符)图形输出的文件扩展名。 如果为NULL,它将从图形设备派生; 有关详细信息,请参见knitr ::: auto_exts

  3. dpi: (72; numeric) The DPI (dots per inch) for bitmap devices (dpi * inches = pixels).72;数字)位图设备的DPI(每英寸点数)(dpi *英寸=像素)。

  4. fig.width, fig.height: (both are 7; numeric) Width and height of the plot (in inches), to be used in the graphics device.
    图片的高度和宽度,英寸

  5. fig.asp: (NULL; numeric) The aspect ratio of the plot, i.e., the ratio of height/width. When fig.asp is specified, the height of a plot (the chunk option fig.height) is calculated from fig.width * fig.asp.
    宽高比。(NULL;数字)绘图的长宽比,即高/宽比。 当指定fig.asp时,图的高度(fig.height块选项)是从fig.width * fig.asp中计算出来的。

  6. fig.dim: (NULL; numeric) A numeric vector of length 2 to provide fig.width and fig.height, e.g., fig.dim = c(5, 7) is a shorthand of fig.width = 5, fig.height = 7. If both fig.asp and fig.dim are provided, fig.asp will be ignored (with a warning).
    NULL;数字)一个长度为2的数字向量,以提供fig.widthfig.height,例如fig.dim = c(5,7)是简写形式 图宽度= 5,图高度= 7。 如果同时提供了fig.aspfig.dim,则fig.asp将被忽略(带有警告)。

  7. out.width, out.height: (NULL; character) Width and height of the plot in the output document, which can be different with its physical fig.width and fig.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, or 8cm; for HTML, they may be 300px. For .Rnw documents, the default value for out.width will be changed to \\maxwidth, which is defined on this page. It can also be a percentage, e.g., '40%' will be translated to 0.4\linewidthwhen the output format is LaTeX.
    NULL;字符)输出文档中绘图的宽度和高度,可以与它的物理fig.widthfig.height不同,即 ,可以在输出文档中缩放绘图。 根据输出格式,这两个选项可以采用特殊值。 例如,对于LaTeX输出,它们可以是.8 \ linewidth,3in或8cm; 对于HTML,它们可能是300px。 对于.Rnw文档,out.width的默认值将更改为\ maxwidth,此值在此页面上定义。](https://yihui.org/knitr/demo/framed/ )也可以是一个百分比,例如,当输出格式为LaTeX时,40%''将转换为0.4 \ linewidth''。

  8. 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;字符)数字的额外选项。 它可以是任意字符串,可以插入LaTeX输出的\ includegraphics []中(例如,out.extra ='angle = 90'将图形旋转90度),或<img />` 在HTML输出中(例如,out.extra ='style =“ border:5px实心橙色;”')。

  9. 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 option dpi todpi * fig.retina, and out.width to fig.width * dpi / fig.retina internally. For example, the physical size of an image is doubled, and its display size is halved when fig.retina = fig.retina
    (1; 数字)此选项仅适用于HTML输出。 对于[Retina显示器,](http://en.wikipedia.org/wiki/Retina_Display)将此选项设置为比率(通常为2)将将dpi''更改为dpi * fig.retina'',然后 在内部将图宽到图宽 dpi /图视网膜。 例如,当fig.retina = 2时,图像的物理尺寸增加了一倍,显示尺寸减半。

  10. 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 is NULL, !will be used (read the documentation of graphicx if you do not understand this).
    resize.width,resize.height:(NULL;字符)LaTeX输出中\ resizebox {} {}中要使用的宽度和高度。 除非您想要调整TikZ图形的大小,否则不需要这两个选项,因为没有自然的方法可以做到这一点。 但是,据tikzDevice 的作者称,TikZ图形并非要调整大小,以保持与LaTeX中其他文本的样式一致性。 如果其中只有一个为``NULL'',则将使用!!(如果您不了解,请阅读 graphicx **的文档)。

  11. fig.align: ('default'; character) Alignment of figures in the output document. Possible values are default, left, right, and center. The default is not to make any alignment adjustments.
    (`'default';; character)输出文档中图形的对齐。 可能的值为“默认”,“左”,“右”和“中心”。 默认设置是不进行任何对齐调整

  12. fig.link: (NULL; character) A link to be added onto the figure.

  13. fig.env: ('figure'; character) The LaTeX environment for figures, e.g., you may set fig.env = 'marginfigure' to get \begin{marginfigure}. This option requires fig.cap be specified.

  14. fig.cap: (NULL; character) A figure caption.

  15. fig.alt: (NULL; character) The alternative text to be used in the alt attribute of the <img> tags of figures in HTML output. By default, the chunk option fig.cap will be used as the alternative text if provided.

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

  17. 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 befig:foo-plotby default. lable{}中可以插入图形标签的前缀。 实际的标签是通过该前缀和块标签制成的,例如,{r,foo-plot}的图形标签默认情况下将为fig:foo-plot`。

  18. fig.pos: (''; character) A character string for the figure position arrangement to be used in \begin{figure}[].

  19. fig.subcap: (NULL) Captions for subfigures. When there are multiple plots in a chunk, and neither fig.subcap nor fig.cap is NULL, \subfloat{} will be used for individual plots (you need to add \usepackage{subfig} in the preamble). See 067-graphics-options.Rnw for an example.

  20. fig.ncol: (NULL; integer) The number of columns of subfigures; see this issue for examples (note that fig.ncol and fig.sep only work for LaTeX output).

  21. fig.sep: (NULL; character) A character vector of separators to be inserted among subfigures. When fig.ncol is specified, fig.sep defaults to a character vector of which every N-th element is \newline (where N is the number of columns), e.g., fig.ncol = 2 means fig.sep = c('', '', '\\newline', '', '', '\\newline', '', ...).

  22. 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 the options argument, the list of chunk options will be passed to this argument.

  23. fig.showtext: (NULL; logical) If TRUE, call showtext::showtext_begin() before drawing plots. See the documentation of the showtext package for details.

  24. external: (TRUE; logical) Whether to externalize tikz graphics (pre-compile tikz graphics to PDF). It is only used for the tikz() device in the tikzDevice package (i.e., when dev='tikz'), and it can save time for LaTeX compilation.

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

  1. interval: (1; numeric) Time interval (number of seconds) between animation frames.默认为1秒,动画帧之间的时间间隔(秒数)

  2. 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.(默认为knitr :: hook_ffmpeg_html;函数或字符)用于在HTML输出中创建动画的钩子函数; 默认挂钩使用FFmpeg将图像转换为WebM视频。

  • Another hook function is knitr::hook_gifski based on the gifski package to create GIF animations.另一个挂钩函数是基于** gifski **包的knitr :: hook_gifski`来创建GIF动画。
  • This option can also take a character string 'ffmpeg' or 'gifski' as a shorthand of the corresponding hook function, e.g., animation.hook = 'gifski' means animation.hook = knitr::hook_gifski.此选项还可以将字符串'ffmpeg'或'gifski'作为对应的钩子函数的简写,例如,animation.hook ='gifski'意味着animation.hook = knitr :: hook_gifski 。

  • aniopts: ('controls,loop'; character) Extra options for animations; see the documentation of the LaTeX animate package.

  1. ffmpeg.bitrate (1M; character) To be passed to the -b:v argument of FFmpeg to control the quality of WebM videos.动画的额外选项; 请参阅LaTeX ** animate **软件包的文档

  2. ffmpeg.format (webm; character) The video format of FFmpeg, i.e., the filename extension of the video. webm; character)FFmpeg的视频格式,即视频的文件扩展名。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,386评论 6 479
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,939评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,851评论 0 341
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,953评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,971评论 5 369
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,784评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,126评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,765评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,148评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,744评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,858评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,479评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,080评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,053评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,278评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,245评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,590评论 2 343

推荐阅读更多精彩内容