简体   繁体   中英

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.

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!

Yes, list them as suggested packages, and check that they are installed using requireNamespace before using them.

I'm not sure where you saw a recommendation that you put Rmd files into inst ; it probably makes more sense to structure them as vignettes instead, and put them in the vignettes directory. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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