[Rd] no visible binding for global variable for data sets in a package

Hadley Wickham h.wickham at gmail.com
Wed Aug 27 16:48:30 CEST 2014

> I think the right answer _is_ to export the lazy data; the question is how to do it. There's nothing particularly strange about exporting non-functions ("letters" would be an example, save for the special status of package:base). If you attach the package, the lazyloaded data appear in the same environment as the exported function so they are de facto already in the namespace for the purposes of library() and `::`. So I agree, something like exportData() would be useful. (Or some other mechanism. You might want to be able to export data selectively.)

I don't think lazyloaded data are in the same environment as exported
functions - getExportedValue() (called by ::) looks first in the
"exports" namespace, then in the "lazydata" namespace:

function (ns, name)
    getInternalExportName <- function(name, ns) {
        exports <- getNamespaceInfo(ns, "exports")
        if (exists(name, envir = exports, inherits = FALSE))
            get(get(name, envir = exports, inherits = FALSE),
                envir = ns)
        else {
            ld <- getNamespaceInfo(ns, "lazydata")
            if (exists(name, envir = ld, inherits = FALSE))
                get(name, envir = ld, inherits = FALSE)
            else stop(gettextf("'%s' is not an exported object from
                name, getNamespaceName(ns)), call. = FALSE, domain = NA)
    ns <- asNamespace(ns)
    if (isBaseNamespace(ns))
        get(name, envir = ns, inherits = FALSE)
    else getInternalExportName(name, ns)

(But maybe you just meant the library() and :: behaves as is lazydata
and exports were the same thing)



More information about the R-devel mailing list