简体   繁体   English

使用devtools查看我的软件包文档

[英]Viewing my package documentation with devtools

I'm using devtools to handle a package I'm working on. 我正在使用devtools处理我正在处理的软件包。

If I run R and then run 如果我运行R然后运行

library(devtools)
devtools:::load_all()

I am able to view my packages documentation. 我可以查看我的包裹文件。

However, I'm trying to create an alias to automate the launching of R (it's actually going into a Makefile). 但是,我正在尝试创建一个别名来自动启动R(它实际上正在进入Makefile中)。 So I created a file "load.R" with those two lines, then run 所以我用这两行创建了一个文件“ load.R”,然后运行

R_PROFILE=load.R R

I get my package loaded properly (eg I can do mypackage::: and see all functions) but I cannot access my help files. 我可以正确加载程序包(例如,可以执行mypackage:::并查看所有功能),但无法访问帮助文件。

(If I start R and run source("load.R") I can see my help files, so I'm confident it's not a typo or something else foolish.) (如果我启动R并运行source("load.R") ,则可以看到我的帮助文件,因此我确信这不是错别字或其他愚蠢的东西。)

I'm thinking it might have something to do with the timing of the load_all call; 我认为这可能与load_all调用的时间有关; I believe passing a R_PROFILE runs the code before the session becomes interactive. 我相信在会话变为交互式之前,传递R_PROFILE运行代码。 So, alternatively, is there a way to run something like 因此,有一种方法可以运行类似

R -e 'source("load.R")'

and have it stay interactive instead of quitting after the code terminates? 并保持交互性而不是在代码终止后退出?

Thanks. 谢谢。

I've found a solution myself, though I'd appreciate any additional ideas, as I'm a bit uncomfortable mucking about with environments like this. 我自己找到了一个解决方案,尽管我会感谢任何其他想法,因为我对这样的环境感到有点不舒服。

devtools appropriates help and ? devtools适当help? by creating a new environment defining versions of the functions which can see my package's help files, and attaching this environment. 通过创建一个新的环境来定义可以查看我的软件包帮助文件的功能版本,并附加该环境。 By the time it gets called interactively, the search() stack has already filled out with the default environments, specifically the package:utils environment from the built in package utils (where help and ? exist). 到它被交互式调用时, search()堆栈已经填充了默认环境,特别是内置软件包utils (其中存在help? )中的package:utils环境。 When attach ing a new environment, it gets added to the top of the search() stack (just behind .GlobalEnv . attach新环境时,它将被添加到search()堆栈的顶部( .GlobalEnv

However, R_PROFILE loads earlier than those base packages being loaded, so when using R_PROFILE=load.R , the devtools environment is lower on the search() stack, so help and ? 但是,R_PROFILE的加载要早于那些正在加载的基本软件包,因此,当使用R_PROFILE=load.Rdevtools环境在search()堆栈上较低,因此help? stick with their default versions. 坚持使用其默认版本。

The solution I have is to update load.R to have 我要解决的办法是更新load.R

library(utils)
library(devtools)
load_all()

This forces utils to load earlier, and before devtools , so that the order of environments is as desired. 这迫使utilsdevtools之前和之前加载,因此环境顺序是所需的。

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

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