r - 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:
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).
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!
解决方案
是的,将它们列为建议的软件包,并requireNamespace
在使用它们之前检查它们是否已安装。
我不确定您在哪里看到将 Rmd 文件放入的建议inst
;将它们构造为小插图可能更有意义,并将它们放在vignettes
目录中。这是放置此类文档的标准位置。
通常不需要将它们复制到工作目录中(这通常被认为是不好的做法,除非您只是在询问后才这样做,并且注意不要踩到用户自己的文件)。您可以使用system.file("doc/something.Rmd", package = "yourPackage")
从那里访问它们而无需复制。
推荐阅读
- php - php中的sql查询没有返回需要的内容
- javascript - 尝试创建一个随机播放功能
- azure - 为公共 IP 地址配置自定义 DNS
- flutter - 没有状态管理的应用程序有什么危险
- javascript - 是否可以从 Discord.js 中的 ReactionCollector 获取用户?
- vb.net - 如何从我的 Amazon Dynamodb 表中获取单个项目
- javascript - 页面加载时自动单击下一个按钮
- php - 如何将图像包含在画廊中 - 包含在文章中
- c# - 为什么 FileSystemWatcher 在监视 Windows 卷的 Linux 容器中不起作用
- java - 在访问其他活动之前,活动不会呈现数组列表