Add Option to Sync renv Cache #1423
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What problem did you solve?
I frequently run into issues where the language or help server will start up and then crash because it cannot find packages (usually
jsonlite). There is the option to add.libPathsin the extension currently, but therenvpackage cache is unstable and liable to change with different architectures and versions ofrenv.Users can get "lucky" when the extension starts an R process in a directory where an .Rprofile bootstraps the
renvenvironment correctly, but for situations where this does not happen (which I find happens often for me), the user is out of luck.This pull request adds a boolean option to the extension where users can opt into automatically adding the
renvpackage cache to.libPathswhen these R processes start up. The mechanism is to write an environment variable on the typescript side that is then parsed as a boolean on the R side, following patterns elsewhere in the code. We then ensure thatrenvis in fact installed—issuing a warning but not crashing if it isn't—and then read the package cache path fromrenv::paths$cache()and add this to our.libPaths.Screenshot
When the language server starts up and
renvis bootstrapped, the.libPathslook like this:When the language server starts up somewhere that does not bootstrap
renv,.libPathslooks like this:Is it a problem that we see packages that the user doesn't?
This change does not automatically bootstrap
renvwhen an R terminal is created. Hence, the language and help servers may have more packages visible to them than the user's terminal does. Users familiar withrenvshould know how to rectify this, and the user who "accidentally" activates this option without knowing anything aboutrenvcan just install the missing packages. The major problem that this change overcomes is thatjsonliteandhttpgdoften get installed into therenvpackage cache by the extension, and this is a problem that can't be overcome as easily as the accidental user error mentioned above.