0

I'm using devtools to handle a package I'm working on.

If I run R and then run

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). So I created a file "load.R" with those two lines, then run

R_PROFILE=load.R R

I get my package loaded properly (e.g. I can do mypackage::: and see all functions) but I cannot access my help files.

(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.)

I'm thinking it might have something to do with the timing of the load_all call; I believe passing a R_PROFILE runs the code before the session becomes interactive. 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.

Josh
  • 1,248
  • 12
  • 25

1 Answers1

0

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 ? 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). When attaching a new environment, it gets added to the top of the search() stack (just behind .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 ? stick with their default versions.

The solution I have is to update load.R to have

library(utils)
library(devtools)
load_all()

This forces utils to load earlier, and before devtools, so that the order of environments is as desired.

Josh
  • 1,248
  • 12
  • 25