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).
Josh o'brien
source share