[R] install.packages() R vs RStudio

John Fox j|ox @end|ng |rom mcm@@ter@c@
Mon Aug 17 16:02:22 CEST 2020


Dear Duncan,

On 2020-08-17 9:03 a.m., Duncan Murdoch wrote:
> On 17/08/2020 7:54 a.m., Ivan Calandra wrote:
>> Dear useRs,
>>
>> Following the recent activity on the list, I have been made aware of
>> this discussion:
>> https://stat.ethz.ch/pipermail/r-help/2020-May/466788.html
>>
>> I used to install all packages in R, but for simplicity (I use RStudio
>> for all purposes), I now do it in RStudio. Now I am left wondering
>> whether I should continue installing packages directly from RStudio or
>> whether I should revert to using R.
>>
>> My goal is not to flare a debate over whether RStudio is better or worse
>> than R, but rather simply to understand whether there are differences
>> and potential issues (that could lead to problems in code) about
>> installing packages through RStudio.
>>
>> In general, it would be nice to have a list of the differences in
>> behavior between R and RStudio, but I believe this should come from the
>> RStudio side of things.
>>
>> Thank you all for the insights.
>> Ivan
>>
> 
> To see the install.packages function that RStudio installs, just type 
> its name:
> 
>  > install.packages
> function (...)
> .rs.callAs(name, hook, original, ...)
> <environment: 0x7fe7dc5b65b0>
> 
> You can debug it to see the other variables:
> 
>  > debug(install.packages)
>  > install.packages("abind")
> debugging in: install.packages("abind")
> debug: .rs.callAs(name, hook, original, ...)
> Browse[2]> name
> [1] "install.packages"
> Browse[2]> hook
> function (original, pkgs, lib, repos = getOption("repos"), ...)
> {
>      if (missing(pkgs))
>          return(utils::install.packages())
>      if (!.Call("rs_canInstallPackages", PACKAGE = "(embedding)")) {
>          stop("Package installation is disabled in this version of 
> RStudio",
>              call. = FALSE)
>      }
>      packratMode <- !is.na(Sys.getenv("R_PACKRAT_MODE", unset = NA))
>      if (!is.null(repos) && !packratMode && 
> .rs.loadedPackageUpdates(pkgs)) {
>          installCmd <- NULL
>          for (i in seq_along(sys.calls())) {
>              if (identical(deparse(sys.call(i)[[1]]), 
> "install.packages")) {
>                  installCmd <- gsub("\\s+", " ", 
> paste(deparse(sys.call(i)),
>                    collapse = " "))
>                  break
>              }
>          }
>          .rs.enqueLoadedPackageUpdates(installCmd)
>          stop("Updating loaded packages")
>      }
>      .rs.addRToolsToPath()
>      on.exit({
>          .rs.updatePackageEvents()
>          .Call("rs_packageLibraryMutated", PACKAGE = "(embedding)")
>          .rs.restorePreviousPath()
>      })
>      original(pkgs, lib, repos, ...)
> }
> <environment: 0x7fe7db925588>
> 
> The .rs.callAs function just substitutes the call to "hook" for the call 
> to the original install.packages.  So you can see that they do the 
> following:
>   - they allow a way to disable installing packages,
>   - they support "packrat" (a system for installing particular versions 
> of packages, see https://github.com/rstudio/packrat),
>   - they add RTools to the path (presumably only on Windows)
>   - they call the original function, and at the end update internal 
> variables so they can show the library in the Packages pane.
> 
> So there is no reason not to do it in R.
> 
> By the way, saying that this is a "modified version of R" is like saying 
> every single user who defines a variable creates a modified version of 
> R.  If you type "x" in the plain R console, you see "Error: object 'x' 
> not found".  If you "modify" R by assigning a value to x, you'll see 
> something different.  Very scary!

I can't recall ever disagreeing with something you said on the R-help, 
but this seems to me to be off-base. While what you say is technically 
correct, silently masking a standard R function, in this case, I 
believe, by messing with the namespace of the utils package, seems 
inadvisable to me.

As has been noted, cryptic problems have arisen with install.packages() 
in RStudio -- BTW, I use it regularly and haven't personally experienced 
any issues. One could concoct truly scary examples, such as redefining 
isTRUE().

Best,
  John

> 
> Duncan Murdoch
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list