首页 > 解决方案 > 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 i.e. 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.

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). Neither library is needed for the functionality of the package per se, but:

  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. 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. I just want to show an example of bootstrapping confidence intervals using my 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. 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.

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?

Thanks in Advance!

标签: rr-markdownr-package

解决方案


是的,将它们列为建议的软件包,并requireNamespace在使用它们之前检查它们是否已安装。

我不确定您在哪里看到将 Rmd 文件放入的建议inst;将它们构造为小插图可能更有意义,并将它们放在vignettes目录中。这是放置此类文档的标准位置。

通常不需要将它们复制到工作目录中(这通常被认为是不好的做法,除非您只是在询问后才这样做,并且注意不要踩到用户自己的文件)。您可以使用system.file("doc/something.Rmd", package = "yourPackage")从那里访问它们而无需复制。


推荐阅读