Skip to content
Prev 48910 / 63424 Next

no visible binding for global variable for data sets in a package

On 27 Aug 2014, at 16:48 , Hadley Wickham <h.wickham at gmail.com> wrote:

            
I meant that 

a) :: gives results as if the data was in the namespace

b) if you do
[1] "abbey"              "accdeaths"          "addterm"           
  [4] "Aids2"              "Animals"            "anorexia"          
  [7] "area"               "as.fractions"       "bacteria"          
 [10] "bandwidth.nrd"      "bcv"                "beav1"             
 ....

data and functions get put together in the same environment (however, this is not the namespace environment, see later).

What puzzles me is why the distinction between lazydata and exports was there to begin with. 

The implication of the current setup is clearly that pkg::foo() cannot access package::dat by referring to `dat` whereas it can do so if invoked as library(pkg); foo(). 

We also have
Error in get("accdeaths", environment(MASS::addterm)) : 
  object 'accdeaths' not found
Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov
1973  9007  8106  8928  9137 10017 10826 11317 10744  9713  9938  9161
1974  7750  6981  8038  8422  8714  9512 10120  9823  8743  9129  8710
...

which confused me at first, but it actually just means that "accdeaths" is found on the search path in the latter case. This strikes me as somewhat dangerous: If a package uses one of its own datasets, it can be masked by a later attach() or the global env. 

(I suspect that someone already explained all this a while back, but I just wasn't listening at the time...)