简体   繁体   English

R 中不可用的包小插图

[英]Package vignettes not available in R

I am building an R package.我正在构建一个 R 包。

I have an rmarkdown file at vignettes/mydoc.Rmd .我在vignettes/mydoc.Rmd有一个 rmarkdown 文件。

Using devtools::build_vignettes() results in files appearing at inst/doc .使用devtools::build_vignettes()导致文件出现在inst/doc

No warnings or errors appear when I use R CMD build .使用R CMD build .时不会出现警告或错误R CMD build . . .

However, when I use vignette() from within R, I do not see any vignette for the package.但是,当我在 R 中使用vignette() ,我看不到包的任何小插图。

My DESCRIPTION file includes:我的DESCRIPTION文件包括:

Suggests: knitr,
    rmarkdown,
VignetteBuilder: knitr

It's not clear how/if you're installing in between steps.目前尚不清楚如何/是否在步骤之间进行安装。 I'll quote from Hadley's R Packages website, the Vignettes chapter, mostly from the Development Cycle section:我将引用 Hadley 的R Packages网站的Vignettes章节,主要来自开发周期部分:

To create your first vignette, run:要创建您的第一个小插图,请运行:

 devtools::use_vignette("my-vignette") This will:
  1. Create a vignettes/ directory.创建一个小插图/目录。

  2. Add the necessary dependencies to DESCRIPTION (ie it adds knitr to the Suggests and VignetteBuilder fields).将必要的依赖项添加到说明(即,它将 knitr 添加到 Suggests 和 VignetteBuilder 字段)。

  3. Draft a vignette, vignettes/my-vignette.Rmd.起草一个小插图,vignettes/my-vignette.Rmd。

The above can be done manually or via the use_vignette() command, but it does need to be done.以上可以手动或通过use_vignette()命令完成,但确实需要完成。

After authoring your vignette, it will need to be built.创作小插图后,需要构建它。

You can build all vignettes from the console with devtools::build_vignettes() , but this is rarely useful.您可以使用devtools::build_vignettes()从控制台构建所有小插图,但这很少有用。 Instead use devtools::build() to create a package bundle with the vignettes included.而是使用devtools::build()创建一个包含小插图的包包。 RStudio's "Build & reload" does not build vignettes to save time. RStudio 的“构建和重新加载”不会构建小插图以节省时间。 Similarly, devtools::install_github() (and friends) will not build vignettes by default because they're time consuming and may require additional packages.同样, devtools::install_github() (和朋友们)默认不会构建小插图,因为它们很耗时并且可能需要额外的包。 You can force building with devtools::install_github(build_vignettes = TRUE) .您可以使用devtools::install_github(build_vignettes = TRUE)强制构建。 This will also install all suggested packages.这也将安装所有建议的软件包。

I believe that devtools::install() will include any vignettes that are already built, the extra argument is only needed if you want rebuild them at the time of installation.我相信devtools::install()将包含任何已经构建的小插图,仅当您想在安装时重建它们时才需要额外的参数。


R CMD BUILD makes a tarball, it doesn't modify your development directories, and R CMD INSTALL installs the package in your library, it also doesn't modify your development directories. R CMD BUILD制作一个 tarball,它不会修改您的开发目录,并且R CMD INSTALL会在您的库中安装该包,它也不会修改您的开发目录。

For development you can use just devtools::install(..., build_vignettes = T) when you want to rebuild vignettes and install a package.对于开发devtools::install(..., build_vignettes = T)当您想要重建小插图并安装软件包时devtools::install(..., build_vignettes = T)您可以仅使用devtools::install(..., build_vignettes = T)

You really only need to build the package itself (generate zip or tarball depending on your system) when you're ready to release to CRAN.当您准备好发布到 CRAN 时,您实际上只需要构建包本身(根据您的系统生成 zip 或 tarball)。 At that point, I'd use devtools::build(..., vignettes = T) as a wrapper for R CMD BUILD , but that's just a preference.那时,我会使用devtools::build(..., vignettes = T)作为R CMD BUILD的包装器,但这只是一种偏好。

I've been experiencing very erratic behaviour with我一直在经历非常不稳定的行为

R CMD build myPackage
R CMD INSTALL myPackage

sometimes this installs the vignettes, and sometimes not.有时这会安装小插曲,有时不会。

devtools::install(build_vignettes = TRUE) seems like a more robust alternative. devtools::install(build_vignettes = TRUE) 似乎是一个更强大的替代方案。 It also has the advantage of offering to update any outdated packages involved in the installation.它还具有提供更新安装中涉及的任何过时软件包的优势。

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

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