简体   繁体   English

在 RMD 中使用外部包作为 R package 的一部分

[英]Using external packages in an RMD as part of an R package

CONTEXT语境

I'm working on an R package with multiple RMDs to demonstrate various components ie detailed example, theory, etc. The RMDs are stored in an inst file instance as recommended, and I have functions that exist to copy them into the user's working directory so they can interact with and export content from the examples.我正在使用带有多个 RMD 的 R package 来演示各种组件,即详细示例、理论等。 RMD 按照建议存储在inst文件实例中,并且我有将它们复制到用户工作目录中的功能他们可以与示例交互并从示例中导出内容。

ISSUE问题

I want one of these RMD files to use two libraries, one of which is also used in a Roxygen2 example (the other is not).我希望这些 RMD 文件之一使用两个库,其中一个也用于 Roxygen2 示例(另一个没有)。 Neither library is needed for the functionality of the package per se, but: package 本身的功能不需要这两个库,但是:

  1. For the first package, the input requires several variables (which I want to show), and one of the variables necessary would be hard to compute without a very specialized function which can be found in a different package.对于第一个 package,输入需要几个变量(我想展示),如果没有非常专业的 function 可以在不同的 ZEFE90A8E604A7C840E8ZF0 中找到,其中一个变量将很难计算。 I do not think it is within the scope of the package to implement this functionality (and if it were, it would just be a slightly-tuned alias of an external package function, which I do not think is good practice). I do not think it is within the scope of the package to implement this functionality (and if it were, it would just be a slightly-tuned alias of an external package function, which I do not think is good practice).

  2. For the second package, it's the boot package.对于第二个 package,它是boot package。 I just want to show an example of bootstrapping confidence intervals using my package.我只想展示一个使用我的 package 引导置信区间的示例。 It's not necessary but useful, as stochastic processes are involved.这不是必需的,但很有用,因为涉及随机过程。

QUESTION问题

What would be a good practice for including these packages in my RMD file.将这些包包含在我的 RMD 文件中是一个很好的做法。 Obviously for the one in the Roxygen2 example, I would need it as a suggested package, but the other one does not seem to technically require it.显然,对于 Roxygen2 示例中的那个,我需要它作为建议的 package,但另一个似乎在技术上不需要它。

Should I list them as suggested packages?我应该将它们列为建议的软件包吗? If I do, should I add existence checks to the RMD file to make sure that the user has them, or should I let them figure it out on their own?如果我这样做了,我应该在 RMD 文件中添加存在检查以确保用户拥有它们,还是应该让他们自己弄清楚?

Thanks in Advance!提前致谢!

Yes, list them as suggested packages, and check that they are installed using requireNamespace before using them.是的,将它们列为建议的包,并在使用它们之前检查它们是否使用requireNamespace安装。

I'm not sure where you saw a recommendation that you put Rmd files into inst ;我不确定您在哪里看到将 Rmd 文件放入inst的建议; it probably makes more sense to structure them as vignettes instead, and put them in the vignettes directory.将它们构建为小插图可能更有意义,并将它们放在vignettes目录中。 This is the standard place to put documentation like that.这是放置此类文档的标准位置。

It isn't usually necessary to copy them into the working directory (and it's generally considered bad practice, unless you only do so after asking, and are careful not to stomp on the user's own files).通常不需要将它们复制到工作目录中(这通常被认为是不好的做法,除非您只是在询问后才这样做,并且注意不要踩到用户自己的文件)。 You can use system.file("doc/something.Rmd", package = "yourPackage") to access them from there without copying.您可以使用system.file("doc/something.Rmd", package = "yourPackage")从那里访问它们而无需复制。

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

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