Skip to content
Prev 52167 / 63424 Next

strange behavior in 'inherits' check for loaded S4 object

I should add one more item that may be related here -- calling
'methods:::.requirePackage' returns a different result based on
whether the package namespace is already loaded or not.

If the package namespace is not loaded, the package is loaded and
attached, and the package environment is returned:

    > methods:::.requirePackage("digest")
    Loading required package: digest
    <environment: package:digest>
    attr(,"name")
    [1] "package:digest"
    attr(,"path")
    [1] "/Users/kevin/Library/R/3.3/library/digest"
    > "digest" %in% loadedNamespaces()
    [1] TRUE
    > "package:digest" %in% search()
    [1] TRUE

On the other hand, if the package namespace has already been loaded,
the package namespace is returned without attaching the package:

    > requireNamespace("digest")
    Loading required namespace: digest
    > methods:::.requirePackage("digest")
    <environment: namespace:digest>
    > "digest" %in% loadedNamespaces()
    [1] TRUE
    > "package:digest" %in% search()
    [1] FALSE

This may be intentional, but the behavior seems surprising and could
be responsible for the behavior outlined earlier.

Best,
Kevin
On Fri, Jul 29, 2016 at 11:37 AM, Kevin Ushey <kevinushey at gmail.com> wrote: