Repository navigation
Description
I would like to be able to add a custom hook within hooking architecture / "tools:rstudio" that RStudio sets. I'm specifically making this request to obtain access to the install.packages() hook established after the R session was fully established. c.f.
rstudio/src/cpp/session/modules/SessionPackages.R
Lines 120 to 124 in 6c72909
| .rs.registerReplaceHook("install.packages", "utils", function(original, | |
| pkgs, | |
| lib, | |
| repos = getOption("repos"), | |
| ...) |
The present hook produces:
get('install.packages', 'package:utils')
# function (...)
# .rs.callAs(name, hook, original, ...)
# <environment: 0x7f92d7069ce8>After testing different options, all of RStudio's hooks seem to be established after R's own startup procedure that runs through .Renviron, .Rprofile, and .Rhistory. As a result, there isn't a way to mask code or load a package automatically that won't be overridden by RStudio claimed functions.
It would be helpful to have an injection point after the initial delayed registration.
rstudio/src/cpp/r/session/RInit.cpp
Lines 318 to 321 in 8af7304
| // now that all initialization code has had a chance to run we | |
| // can register all external routines which were added to r::routines | |
| // during the init sequence | |
| r::routines::registerAll(); |
The use case for the injection is:
- Disabling communication with CRAN/Global CDNs for secure environments
- Better user feedback as it now silently errors or triggers a full error when a bogus CRAN path is specified.
- Similar behavior to launching R from Terminal or GUI.
- Some kind of environmental disable package installation feature option (instead of removing the package panel).
Slient error without overriding CRAN mirror
Noisy error without masked function call when overriding with a bogus CRAN mirror
To recreate the mask shown desired, I've created a .Rprofile file that contains:
.First = function() {
## Place package on search path
library("utils")
## Unlock environment where the function/variable is found.
unlockBinding("install.packages", as.environment("package:utils"))
## Intercept install packages with a custom function.
base::assign("install.packages",
value = function(...) { cat("Done!\n")},
envir = as.environment("package:utils"))
## Close the environment
lockBinding("install.packages", as.environment("package:utils"))
}


Activity
Clarity of install.packages() shim functionality
Re-enable the local CRAN variant (#3)
jmcphers commentedon Mar 27, 2019
We agree. We're tracking the enhancement here:
#1579
I think what we're proposing there will address your use case, so I'm closing this one for now.