6

I am building an R package using devtools, but find that load_all() runs functions even when they are included in .Rbuildignore via use_build_ignore(). I've created a minimal package at https://github.com/adsteen/loadallfail/tree/master/R to illustrate the problem.

I created this package using devtools::create("loadallfail"). Then added a single file, R/syntax_error.R, with the following contents:

syntax_error <- function{

Next I opened the package project in RStudio and ran devtools::use_build_ignore("syntax_error")

When I run load_all() I get the following error:

Loading loadallfail
Error in parse(text = lines, n = -1, srcfile = srcfile) : 
  /Users/andrewsteen/Documents/Rpkgs/loadallfail/R/syntax_error.R:1:26: unexpected '{'
1: syntax_error <- function {

I would expect that the package would load successfully because anything matching the pattern in .Rbuildignore would not load and therefore not cause problems. What am I misunderstanding?

Note: a similar question is posted at Rbuildignore and Excluding Directories, but in that question the problem seemed to be an RStudio bug. I am using RStudio, but am calling all the devtools functions via the RStudio console (and in any case I can verify that .Rbuildignore looks like I think it should.)

Community
  • 1
  • 1
Drew Steen
  • 16,045
  • 12
  • 62
  • 90
  • 1
    As far as I can tell, there's no provision in devtools to use .Rbuildignore for anything except *building* packages. Diving down the stack from `load_all()`, `devtools:::find_code()` seems to be what selects what to load and doesn't reference .Rbuildignore at all. I also searched the devtools repo for references to .Rbuildignore, none of the hits are in relevant functions. – Noam Ross Sep 29 '16 at 23:41
  • That's kind of an odd decision, isn't it? I'm new to R package development, but I thought a.) most packages have some files that shouldn't be loaded, and b.) the point of `load_all()` is to quickly simulate building the package. So does `load_all()` typically fail during package development? I must be misunderstanding something about normal package development workflow. – Drew Steen Sep 30 '16 at 14:44
  • 2
    `load_all()` is deliberately different than building the package. For instance, it makes all internal functions available, not just exported ones. I think its not so much meant to simulate building but just make everything available during development. `.Rbuildignore` is more about keeping out extras (like Travis files) that CRAN doesn't like. I think a better workflow might be to put fragments in `inst/` and move them to `R/` when they are loadable. – Noam Ross Sep 30 '16 at 19:29

0 Answers0