Search code examples
rdevtools

R CMD build versus devtools::build() (Non-standard file/directory found at top level)


I am writing an R package and build and test it with:

Rscript -e "devtools::document()" && R CMD build . && Rscript -e "devtools::test();devtools::check()"

I get a note:

checking top-level files
   Non-standard file/directory found at top level:
     ‘PosteriorBootstrap_0.0.1.tar.gz’

I get the note whether devtools::check() comes first or second.

This thread suggests:

The note is telling you that you usually shouldn't have a file called build in the top level of your package.

The tar.gz file is created by R CMD build and I get the same error even if I delete it before running it.

This thread suggests adding the tar.gz file to .Rbuildinore, which removes the note.

Another way to remove it is to run everything from devtools:

Rscript -e "devtools::document(); devtools::build(); devtools::load_all('.'); devtools::test(); devtools::check()"

And then I don't get that note.

What's the difference between R CMD build and devtools::build() and why does the former throw that note?


Solution

  • You are combining a number of steps that perform similar and/or competing functions. I would suggest reading this for a best-practice build and check workflow.

    When you run R CMD build it builds the package to the current directory, which is the top level package directory. Therefore, when you run your checks, it sees the .tar.gz file in the package root, which is a non-standard file to have in a package, thus the warning. devtools::build() is smart and builds the package to the package parent directory (regardless of where you are calling it from). Trying to call R CMD commands mixed with devtools functions can create issues, because devtools also calls R CMD commands, so you may be duplicating actions at various points in time or causing commands to be called in the incorrect order.

    Per the link above, a best-practice workflow would be:

    Rscript -e "devtools::document();devtools::check();devtools::build()"
    

    called from the package root, and you avoid dealing with R CMD altogether. If you want to use R CMD it would look something like this:

    Rscript -e "devtools::document()" && cd .. && R CMD build PosteriorBootstrap && R CMD check PosteriorBootstrap*.tar.gz
    

    starting in the package root and then changing to the parent directory.