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

hadley wickham h.wickham at gmail.com
Sat Jan 5 01:24:14 CET 2008


On 1/4/08, Henrik Bengtsson <hb at stat.berkeley.edu> wrote:
> 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

Well, yes, but I never write functions like that, and I hardly need to
search my own code for idioms that I never use.

> 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?

I wasn't actually using grep.

> > 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.

Unfortunately a binary search isn't so easy when you have fairly
complex dependencies between files.

Hadley

-- 
http://had.co.nz/



More information about the R-devel mailing list