On 2013-02-22, at 10:23 PM, Berwin A Turlach wrote:

>> On Feb 22, 2013, at 6:39 PM, David Winsemius wrote:
> [...]
>>> I've always wondered: How does lattice manage to use grid functions
>>> without putting them on the search path?
> 
> Because lattice imports the grid package and has a NAMESPACE (as have
> all packages nowadays):
> 
> R> packageDescription("lattice")
> Package: lattice
> Version: 0.20-10
> Date: 2012/08/21
> [...]
> Suggests: grid, KernSmooth, MASS
> Imports: grid, grDevices, graphics, stats, utils, methods
> [...]
> 

Having an "Imports" line in the DESCRIPTION doesn't actually import anything. You have to have an "import" or "importsFrom" in the NAMESPACE. Which, sure enough, Lattice has:

import(grid)
BTW, I noticed Lattice lists grid in both "Imports" and "Suggests". This seems contradictory, because "Imports" are supposed to be packages that are required while "Suggests" are optional.

> 
>> Neither can the R interpreter find it. But it's clearly available if
>> you ask nicely:
>> 
>>> grid::grid.text
> 
> This will always work, whether the grid package is loaded/attached or
> not:
[...]

This actually loads the package, as described in R-exts: "Evaluating foo::f will cause package foo to be loaded, but not attached, if it was not loaded already". 

See the example below, and notice that "grid" is present in the second call to sessionInfo:

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
> grid::grid.layout
function (nrow = 1, ncol = 1, widths = unit(rep(1, ncol), "null"), 
    heights = unit(rep(1, nrow), "null"), default.units = "null", 
    respect = FALSE, just = "centre") 
{
    if (!is.unit(widths)) 
        widths <- unit(widths, default.units)
    if (!is.unit(heights)) 
        heights <- unit(heights, default.units)
    valid.layout(nrow, ncol, widths, heights, respect, just)
}
<bytecode: 0x102539628>
<environment: namespace:grid>
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] grid_2.15.2

Davor
	[[alternative HTML version deleted]]

