Examples for 'base::attachNamespace'


Loading and Unloading Name Spaces

Aliases: attachNamespace loadNamespace requireNamespace loadedNamespaces unloadNamespace isNamespaceLoaded

Keywords: data utilities

### ** Examples

 (lns <- loadedNamespaces())
 [1] "grDevices"      "png"            "FastRWeb"       "bitops"        
 [5] "mime"           "R6"             "evaluate"       "datasets"      
 [9] "rcloud.support" "httr"           "utils"          "uuid"          
[13] "graphics"       "base"           "gist"           "rjson"         
[17] "Cairo"          "tools"          "rediscc"        "RCurl"         
[21] "markdown"       "sendmailR"      "xfun"           "parallel"      
[25] "compiler"       "stats"          "base64enc"      "PKI"           
[29] "Rserve"         "knitr"          "methods"       
 statL <- isNamespaceLoaded("stats")
 stopifnot( identical(statL, "stats" %in% lns) )

 ## The string "foo" and the symbol 'foo' can be used interchangably here:
 stopifnot( identical(isNamespaceLoaded(  "foo"   ), FALSE),
            identical(isNamespaceLoaded(quote(foo)), FALSE),
            identical(isNamespaceLoaded(quote(stats)), statL))

hasS <- isNamespaceLoaded("splines") # (to restore if needed)
Sns <- asNamespace("splines") # loads it if not already
stopifnot(   isNamespaceLoaded("splines"))
if (is.null(try(unloadNamespace(Sns)))) # try unloading the NS 'object'
stopifnot( ! isNamespaceLoaded("splines"))
if (hasS) loadNamespace("splines") # (restoring previous state)

[Package base version 4.2.3 Index]