How can I prevent the download of package R?

I use a multi-core package in R to parallelize my code. However, if the tcltk package is loaded, branching processes with a multicore package will cause R to hang indefinitely. Therefore, I want to prevent tcltk from loading. I want an immediate error if any package tries to load it as a dependency. Is it possible?

Alternatively, is it possible to unload a package after downloading it?

+7
source share
2 answers

If immediately disconnecting the package after attaching is a good enough solution, try the following:

setHook(hookName = packageEvent("tcltk", "attach"), value = function(...) detach(package:tcltk)) # Try it out library(tcltk) # Loading Tcl/Tk interface ... done # Error in as.environment(pos) : invalid 'pos' argument search() # [1] ".GlobalEnv" "package:graphics" "package:grDevices" # [4] "package:utils" "package:datasets" "package:methods" # [7] "Autoloads" "package:base" 

If (as it seems likely) the process of downloading and attaching a package is causing a problem, you can also use a strategy similar to that described in the comments on your question. Namely:

  • Create a harmless dummy package, also called tcltk
  • Put it in a directory with a name, for example, "C:/R/Library/dummy/" .
  • Before running any other commands, add this directory to .libPaths by executing .libPaths(c("C:/R/Library/dummy/", .libPaths())) .

Then, if a package tries to load tcltk , it first looks for packages in "C:/R/Library/dummy/" , and finding one of them, it will load it for a moment (before it disconnects immediately with a hook, described above).

+3
source

Another way to avoid loading a specific package as a dependency is based on the assumption that not one of the functions that you need depends on that package, will refer to the functions you need using the namespace:

 lattice::xyplot(1~1) 

Thus, you do not need to download the package using your function, and you do not accidentally download the problem package.

+1
source

All Articles