[Rd] checking whether the name space can be loaded with stated dependencies

Henrik Bengtsson hb at stat.berkeley.edu
Fri Jan 4 23:54:57 CET 2008


On 04/01/2008, hadley wickham <h.wickham at gmail.com> wrote:
> On 1/4/08, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> > What it is trying is
> >
> > % env R_DEFAULT_PACKAGES=NULL R
> >
> > > loadNamespace("ggplot2")
> >
> > The test is not new, so it would seem to be a change in ggplot2 since the
> > version on CRAN.  My guess is the your package is doing top-level
> > computations, which `Writing R Extensions' warns against:
> >
> >    The R code files should only create R objects and not call functions
> >    with side effects such as require and options.
>
> Thanks for the additional info. I've grepped for ^[^#\n ]+\(  (which I
> think should find any top-level function call) and didn't find

Not the correct pattern; there can be spaces after the function name
the first parentesis, e.g.

> rnorm   (3)
[1]  0.6127487  0.8150284 -0.7170449

More, the above regular expression will not detect function calls
starting with a space, neither expressions such as "3+3" although I
don't think they would generate the above NOTE/error.

> pattern <- "^[^#\n ]+\\("
> regexpr(pattern, "rnorm(3)")
[1] 1
> regexpr(pattern, "rnorm   (3)")
[1] -1
> regexpr(pattern, " rnorm(3)")
[1] -1
> regexpr(pattern, "3+3")
[1] -1

Also, what is the newline ('\n') doing in the negated set - isn't grep
done line by line?

> anything. I certainly can't think of any top level computations that
> I'm doing apart from creating R functions and objects.  Is there
> anyway to get more details about what exactly I've done wrong?
> Calling traceback after loadNamespace isn't helpful.

Start commenting out/exclude part of your source code and recheck for
the same error should do.  Start from scratch by adding a

foo <- function() { NA }

and exclude everything else.  If that works, leave 1st half out, then
2nd and continue with "divide and conquer" until you narrow down the
problem.  Sometimes it comes down to a single right bracket missed
out.

/Henrik


>
> > If you must deviate from that, you need to arrange for the environment you
> > need: when loading a name space the Depends: packages are not loaded.
>
> Is this a recent change to R? The package appears to work fine after
> installation so I presume this check is protecting me from some more
> subtle danger.
>
> If it's helpful, my depends line is:
> Depends: R (>= 2.6), grid, reshape (>= 0.8.0), proto, splines, MASS,
>   RColorBrewer, colorspace
>
> so only proto or RColorBrewer should be a problem.
>
> Hadley
>
> --
> http://had.co.nz/
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list