@@ -1807,46 +1807,41 @@ substituteFunctionArgs <-
18071807
18081808# # bootstrap version: all classes and methods must be in the version of the methods
18091809# # package being built in the toplevel environment: MUST avoid require("methods") !
1810- .requirePackage <- function (package , mustFind = TRUE )
1810+ .requirePackage <- function (package , mustFind = TRUE , quietly = FALSE )
18111811 topenv(parent.frame())
18121812
18131813# # real version of .requirePackage
1814- ..requirePackage <- function (package , mustFind = TRUE ) {
1815- value <- package
1814+ ..requirePackage <- function (package , mustFind = TRUE , quietly = FALSE ) {
18161815 if (nzchar(package )) {
18171816 # # lookup as lightning fast as possible:
1818- if (.Internal(exists(package , .Internal(getNamespaceRegistry()),
1819- " any" , FALSE )))
1820- value <- getNamespace(package )
1817+ if (! is.null(ns <- .Internal(getRegisteredNamespace(package ))))
1818+ return (ns )
18211819 else {
18221820 if (identical(package , " .GlobalEnv" ))
18231821 return (.GlobalEnv )
18241822 if (identical(package , " methods" ))
18251823 return (topenv(parent.frame())) # booting methods
1824+ # # else continue
18261825 }
18271826 }
1828- if (is.environment(value ))
1829- return (value )
1830- topEnv <- getOption(" topLevelEnvironment" )
1831- if (is.null(topEnv ))
1832- topEnv <- .GlobalEnv
1827+ topEnv <- getOption(" topLevelEnvironment" , default = .GlobalEnv )
18331828 if (! is.null(pkgN <- get0(" .packageName" , topEnv , inherits = TRUE )) &&
18341829 .identC(package , pkgN ))
18351830 return (topEnv ) # kludge for source'ing package code
1831+
18361832 # # If called from .findInheritedMethods which disables S4 primitive dispatch,
18371833 # # allow it here, as namespace loading hooks may need it:
18381834 if (! .allowPrimitiveMethods(TRUE ))
18391835 on.exit(.allowPrimitiveMethods(FALSE ))
1840- if (nzchar(package ) && require(package , character.only = TRUE )) {}
1836+ if (nzchar(package ) && requireNamespace(package , quietly = quietly ))
1837+ getNamespace(package )
18411838 else {
18421839 if (mustFind )
18431840 stop(gettextf(" unable to load required package %s" ,
18441841 sQuote(package )),
18451842 domain = NA )
1846- else
1847- return (NULL )
18481843 }
1849- getNamespace( package )
1844+ # # else return(NULL )
18501845}
18511846
18521847.classDefEnv <- function (classDef ) {
0 commit comments