kornl / crossover

Crossover Designs
6 stars 2 forks source link

Avoid attaching namespace directly (compatibility fix for byte-code compiler) #4

Closed kalibera closed 8 years ago

kalibera commented 8 years ago

This patch is a quick fix for the problem of attaching a namespace directly (to expose its unexported members). When a namespace is attached directly using e.g. attach(asNamespace(..., one gets an environment structure with a namespace loaded within global environments (below globalenv). This is not allowed by the byte-code compiler. The attached quick fix instead copies bindings from the namespace into a fresh environment, which is not a namespace, and hence can be within global environments. Note that for testing, one can use e.g. testthat, which already takes care of these low-level issues (in a similar way, it also copies the namespace bindings, but has also to do a bit more to support S4). This patch only fixes the code under "pkg", which gets into the CRAN packages, but there are remaining instances of this elsewhere in the code. For development, one could probably use devtools::load_all to access unexported members.

kornl commented 8 years ago

Dear Thomas, thank you very much for this note and fix. I switched from RUnit to testthat and adapted your fix for the vignettes. I'll still look further into this later, but will submit this fixed package as it is soon. Thanks again and best regards, Kornelius