r-lib / devtools

Tools to make an R developer's life easier
https://devtools.r-lib.org
Other
2.37k stars 755 forks source link

devtools::install(quick = TRUE) recompiles everything when changing the git branch #2519

Closed stla closed 8 months ago

stla commented 1 year ago

Hello

I have a package with a lot of C++ code. It takes several hours to install it (especially on Windows). So devtools::install(quick = TRUE) is nice, because it recompiles only the files which have changed.

But when I change the git branch and I come back to the previous one, devtools::install(quick = TRUE) recompiles everything. It would be nice if it could "remember" the state of the branch.

jennybc commented 8 months ago

The documentation for the purpose of quick doesn't really match the impression you have:

quick | if TRUE skips docs, multiple-architectures, demos, and vignettes, to make installation as fast as possible.

And this is born out by looking at the source for install(). I.e. quick just influences the arguments passed to base R CMD INSTALL.

So this feels like something that is really out of devtools's hands, so to speak.

stla commented 8 months ago

Hmm... I feel like this doc is incomplete. When the C(++) files have not changed, the option quick=TRUE allows to not recompile these files ("Nothing to be done for all" is printed). That's why I use it.

jennybc commented 8 months ago

I suspect there's some indirection / misattribution in what you're experiencing. For example, quick = TRUE implies build = FALSE, by default. Which means that the package doesn't get built prior to installation. The word "built" is confusing, because it's not about, e.g. compiling code, but rather about making a so-called package bundle. And a package bundle does not contain any compliation artefacts that are lying around. So if quick = FALSE, then build = TRUE, and install() will definitely compile your package from scratch, because it will first be bundled (leaving behind any pre-compiled code) then installed.

But devtools has no direct relationship with your compilation artefacts and is not in a position to take the lead on preserving them across git branch changes, for example.

This chapter is a good reference re: the different package states: https://r-pkgs.org/structure.html