Examples for 'base::asNamespace'


Namespace Internals

Aliases: asNamespace getNamespaceInfo .getNamespaceInfo importIntoEnv isBaseNamespace isNamespace namespaceExport namespaceImport namespaceImportClasses namespaceImportFrom namespaceImportMethods packageHasNamespace parseNamespaceFile registerS3method registerS3methods setNamespaceInfo .__S3MethodsTable__. .mergeExportMethods .mergeImportMethods .knownS3Generics loadingNamespaceInfo .getNamespace .getNamespaceInfo ..getNamespace .S3_methods_table

Keywords: internal

### ** Examples

nsName <- "stats"
(ns <- asNamespace(nsName)) # <environment: namespace:stats>
<environment: namespace:stats>
## Inverse function of asNamespace() :
environmentName(asNamespace("stats")) # "stats"
[1] "stats"
environmentName(asNamespace("base"))  # "base"
[1] "base"
getNamespaceInfo(ns, "spec")[["name"]] ## -> "stats"
[1] "stats"
## Don't show: 
stopifnot(identical(nsName,
                      getNamespaceInfo(ns, "spec")[["name"]]))
## End(Don't show)

## Only for the daring ones, trying to get into the bowels :

lsNamespaceInfo <- function(ns, ...) {
    ns <- asNamespace(ns, base.OK = FALSE)
    ls(..., envir = get(".__NAMESPACE__.", envir = ns, inherits = FALSE))
}
allinfoNS <- function(ns) sapply(lsNamespaceInfo(ns), getNamespaceInfo, ns=ns)

utils::str(allinfoNS("stats"))
List of 9
 $ DLLs          :List of 1
  ..$ stats:List of 5
  .. ..$ name         : chr "stats"
  .. ..$ path         : chr "/usr/local/R/4.2/library/stats/libs/stats.so"
  .. ..$ dynamicLookup: logi FALSE
  .. ..$ handle       :Class 'DLLHandle' <externalptr> 
  .. ..$ info         :Class 'DLLInfoReference' <externalptr> 
  .. ..- attr(*, "class")= chr "DLLInfo"
 $ dynlibs       : Named chr "stats"
  ..- attr(*, "names")= chr ""
 $ exports       :<environment: 0x55ccfaea1bc0> 
 $ imports       :List of 4
  ..$ base     : logi TRUE
  ..$ graphics : Named chr [1:88] "assocplot" "title" "axis.Date" "points" ...
  .. ..- attr(*, "names")= chr [1:88] "assocplot" "title" "axis.Date" "points" ...
  ..$ grDevices: Named chr [1:12] "as.graphicsAnnot" "dev.cur" "dev.flush" "dev.hold" ...
  .. ..- attr(*, "names")= chr [1:12] "as.graphicsAnnot" "dev.cur" "dev.flush" "dev.hold" ...
  ..$ utils    : Named chr [1:5] "count.fields" "flush.console" "modifyList" "str" ...
  .. ..- attr(*, "names")= chr [1:5] "count.fields" "flush.console" "modifyList" "str" ...
 $ lazydata      :<environment: 0x55ccfaea1fe8> 
  ..- attr(*, "name")= chr "lazydata:stats"
 $ nativeRoutines:List of 1
  ..$ stats: Named chr [1:222] "loess_raw" "loess_dfit" "loess_dfitse" "loess_ifit" ...
  .. ..- attr(*, "names")= chr [1:222] "C_loess_raw" "C_loess_dfit" "C_loess_dfitse" "C_loess_ifit" ...
 $ path          : chr "/usr/local/R/4.2/library/stats"
 $ S3methods     : chr [1:418, 1:4] "[" "[" "[" "[" ...
 $ spec          : Named chr [1:2] "stats" "4.2.3"
  ..- attr(*, "names")= chr [1:2] "name" "version"
utils::str(allinfoNS("stats4"))
List of 8
 $ dynlibs       : chr(0) 
 $ exports       :<environment: 0x55ccfbf17db8> 
 $ imports       :List of 6
  ..$ base     : logi TRUE
  ..$ grDevices: Named chr [1:2] "dev.flush" "dev.hold"
  .. ..- attr(*, "names")= chr [1:2] "dev.flush" "dev.hold"
  ..$ graphics : Named chr [1:3] "abline" "lines" "par"
  .. ..- attr(*, "names")= chr [1:3] "abline" "lines" "par"
  ..$ methods  : Named chr [1:3] "new" "show" "slotNames"
  .. ..- attr(*, "names")= chr [1:3] "new" "show" "slotNames"
  ..$ stats    : Named chr [1:7] "approx" "optim" "pchisq" "predict" ...
  .. ..- attr(*, "names")= chr [1:7] "approx" "optim" "pchisq" "predict" ...
  ..$ stats    : Named chr [1:10] "AIC" "BIC" "coef" "confint" ...
  .. ..- attr(*, "names")= chr [1:10] "AIC" "BIC" "coef" "confint" ...
 $ lazydata      :<environment: 0x55ccfbf18138> 
  ..- attr(*, "name")= chr "lazydata:stats4"
 $ nativeRoutines: list()
 $ path          : chr "/usr/local/R/4.2/library/stats4"
 $ S3methods     : chr[0 , 1:4] 
 $ spec          : Named chr [1:2] "stats4" "4.2.3"
  ..- attr(*, "names")= chr [1:2] "name" "version"

[Package base version 4.2.3 Index]