[Rd] evaluation in unattached namespace

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Apr 27 02:44:07 CEST 2007


On 4/26/07, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> On 4/26/2007 7:39 PM, Deepayan Sarkar wrote:
> > Hi,
> >
> > I recently discovered this buglet in lattice: If lattice is _not_
> > attached, I get
> >
> >> lattice::dotplot(~1:10)
> > Error in eval(expr, envir, enclos) : could not find function "bwplot"
> >
> > This happens because of this:
> >
> >> lattice:::dotplot.formula
> > function (x, data = NULL, panel = "panel.dotplot", ...)
> > {
> >     ocall <- ccall <- match.call()
> >     ccall$data <- data
> >     ccall$panel <- panel
> >     ccall[[1]] <- as.name("bwplot")
> >     ans <- eval.parent(ccall)
> >     ans$call <- ocall
> >     ans
> > }
> > <environment: namespace:lattice>
> >
> > That is, ccall is eval()-ed in the global environment where bwplot is
> > not visible. While this example is somewhat silly, similar things
> > happen when I try to import lattice from another package.
> >
> > Are there any simple alternatives? I tried
> >
> >     ccall[[1]] <- as.name("lattice::bwplot")

Seth suggested

ccall[[1]] <- quote(lattice::bwplot)

which makes more sense and seems to work too.

-Deepayan



More information about the R-devel mailing list