Skip to content

Instantly share code, notes, and snippets.

@LukeGoodsell
Last active September 20, 2018 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LukeGoodsell/aa8c79b34481c0544bd1f9800cd197b5 to your computer and use it in GitHub Desktop.
Save LukeGoodsell/aa8c79b34481c0544bd1f9800cd197b5 to your computer and use it in GitHub Desktop.
Unload strict library in R

The strict R package is a great tool for helping to build robust R code. However, there are times when it doesn't place nicely with certain packages.

For example, the GenomicRanges packages defines functions with the same name as base functions (e.g. gsub) and then calls them without specifying the namespace, which results in strict rightly complaining about a conflict.

Unfortunately, you cannot just detach the strict package. These commands will detach strict's functionality (or silently do nothing if it isn't loaded):

if ("strict_conflicts" %in% search()) detach("strict_conflicts")
if ("strict_shims" %in% search()) detach("strict_shims")
if ("strict" %in% loadedNamespaces()) unloadNamespace("strict")
> T
[1] TRUE
> library("strict")
> T
Error: [strict]
Please use TRUE, not T
5: (function ()
{
traceback(2)
if (!interactive()) {
print("Encountered an error")
quit(save = "default", status = 1, runLast = FALSE)
}
})()
4: stop(cnd)
3: abort(msg)
2: strict_abort("Please use TRUE, not T")
1: (function ()
strict_abort("Please use TRUE, not T"))()
> search()
[1] ".GlobalEnv" "strict_conflicts" "strict_shims"
[4] "package:strict" "package:stats" "package:graphics"
[7] "package:grDevices" "package:utils" "package:datasets"
[10] "package:methods" "Autoloads" "package:base"
> loadedNamespaces()
[1] "compiler" "graphics" "strict" "utils" "grDevices" "stats"
[7] "datasets" "methods" "rlang" "base"
> if ("strict_shims" %in% search()) detach("strict_conflicts")
> if ("strict_shims" %in% search()) detach("strict_shims")
> if ("strict" %in% loadedNamespaces()) unloadNamespace("strict")
> T
[1] TRUE
> search()
[1] ".GlobalEnv" "package:stats" "package:graphics"
[4] "package:grDevices" "package:utils" "package:datasets"
[7] "package:methods" "Autoloads" "package:base"
> loadedNamespaces()
[1] "compiler" "graphics" "utils" "grDevices" "stats" "datasets"
[7] "methods" "rlang" "base"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment