简体   繁体   English

使用 roxygen2 忽略脚本

[英]ignore script with roxygen2

I am writing a package that does some work on a server.我正在编写一个 package,它在服务器上做了一些工作。 I have a script that updates a table but my intention was not to run it manually and infrequently.我有一个更新表格的脚本,但我的意图不是手动和不频繁地运行它。 It's not a function that needs to go into the namespace or anything, just a script.这不是 function 需要 go 进入命名空间或任何东西,只是一个脚本。

The problem is that when I call roxygen2::roxygenize() it runs this script and takes a while to run which is very annoying while I'm trying to develop the interactive functions.问题是,当我调用roxygen2::roxygenize()时,它会运行此脚本并需要一段时间才能运行,这在我尝试开发交互式功能时非常烦人。 I know that I can add \donotrun{} around the examples in my documentation but that doesn't quite make sense in this context.我知道我可以在文档中的示例周围添加\donotrun{} ,但这在这种情况下不太有意义。 Is there a way that I can tell roxygen to not bother executing this?有没有办法告诉 roxygen 不要费心执行这个?

I considered making this a function just so that executing it would just define the function body but that seems a little sideways.我考虑将其设为 function 以便执行它只会定义 function 主体,但这似乎有点横向。

Any suggestions would be great任何建议都会很棒

For new visitors, this is not code within roxygen documentation for a function;对于新访问者,这不是 function 的 roxygen 文档中的代码; for that, it would be best to surround it with \donotrun , as in为此,最好用\donotrun将其包围,如

#' @examples
#' \donotrun{
#' something_goes_here()
#' }
myfunction <- function(...) {

In this case, though, it's including some files in the package itself.但是,在这种情况下,它包含 package 本身中的一些文件。

  1. Files you place within the ./inst/ directory are installed with the packages, but they are not assumed to be R scripts (or anything, for that matter).您放置在./inst/目录中的文件与软件包一起安装,但不假定它们是 R 脚本(或其他任何东西)。 The authoritative reference for this starts with "Writing R Extensions" , Section 1.1.5 Package sub-directories .对此的权威参考开始于“编写 R 扩展”第 1.1.5 节 Package 子目录 This will install the file(s) on each computer that installs the package via install.packages(...) .这将在通过install.packages(...)安装 package 的每台计算机上安装文件。

  2. If you want something within the package source but not to be installed with the package itself, I suggest you place a file in the root of the package named .Rbuildignore (ref: same link, now section 1.3.2 Building package tarballs). If you want something within the package source but not to be installed with the package itself, I suggest you place a file in the root of the package named .Rbuildignore (ref: same link, now section 1.3.2 Building package tarballs). Files that are matched by these patterns will not be included in the package tarball.与这些模式匹配的文件不会包含在 package tarball 中。 Whether you put the actual file within ./inst/ or anywhere else is completely up to you: if it is in the .Rbuildignore file, then it will be excluded from the tarball (and therefore seen/findable by the end users).是否将实际文件放在./inst/或其他任何地方完全取决于您:如果它位于.Rbuildignore文件中,那么它将从 tarball 中排除(因此最终用户可以看到/找到)。

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

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