简体   繁体   English

如何使用“roxygen2”在 R function 文档中包含图像?

[英]How to include an image in R function documentation using `roxygen2`?

I write an R package and I want to include some images in some of the function documentations.我写了一个 R package 并且我想在一些 function 文档中包含一些图像。 For documenting the functions I use roxygen2 .为了记录我使用roxygen2的功能。

Since roxygen2 handles Markdown very well, I saved the image in the Rd directory and tried to include it like this (within a @param tag):由于roxygen2处理 Markdown 非常好,我将图像保存在Rd目录中并尝试像这样包含它(在@param标记中):

![](my_image.png)

When I build the function documentation, it looks like this:当我构建 function 文档时,它看起来像这样:

找不到图片

It seems, as if the inclusion worked in principal, but the image is not found.似乎包含原则上有效,但找不到图像。

I also tried to store the image in inst/extdata/images/my_image.png and to include it like this:我还尝试将图像存储在inst/extdata/images/my_image.png并像这样包含它:

![](`r system.file(package = "my_package", "extdata", "images", "my_image.png")`)

This did not work either.这也不起作用。

So, where do I have to put the images to make them available and how can I include them in the function documentation?那么,我必须将图像放在哪里才能使它们可用,以及如何将它们包含在 function 文档中?

You have to put your image in the folder man/figures and type such an Roxygen code:您必须将您的图像放在文件夹man/figures中并输入这样的 Roxygen 代码:

#' \if{html}{Here is my figure:
#'
#'   \out{<div style="text-align: center">}\figure{myfigure.png}{options: style="width:750px;max-width:75\%;"}\out{</div>}
#'
#' }
#' \if{latex}{Here is my figure:
#'
#'   \out{\begin{center}}\figure{myfigure.png}\out{\end{center}}
#'
#' }

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

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