rdevtoolsr-packagerprofile

Building an R package error with devtools::document


I am building R packages using devtools. I've built a package with some functions that I'd like to include. And I'd like to load the package and its documentation at startup. My package files are located at the location:

'~/global/Rcode/Startup Package'

My .Rprofile file looks like this:

.First <- function(){
    library(devtools)
    location <- '~/global/Rcode/Startup Package'
    document(location)
}

However when I open R, the functions from the package are loaded but the documentation is not.

If I run the same lines of code after startup myself, namely:

library(devtools)
location <- '~/global/Rcode/Startup Package'
document(location)

then everything works and the package correctly documents. This thus seems like a rather weird bug!

(As a partial fix I can run

install(location) 

and treat it like a normal r package and everything works fine, however this takes time and as I intend to update the package a lot and do not really want to have to run this every time, especially as the devtools option should work.)


Solution

  • Make sure utils is loaded before loading devtools otherwise there's no help function for devtools to overwrite.

    With .Rprofile:

    .First = function(){
    library(utils)
    library(devtools)
    document("./foo")
    }
    

    then R startup goes:

    [stuff]
    Type 'q()' to quit R.
    
    Updating foo documentation
    Loading foo
    

    And help is devtools version:

    > environment(help)
    <environment: namespace:devtools>
    

    Remove that library(utils) and you'll see the help function is the one in utils that won't find your package documentation.