From h.wickham at gmail.com  Sat Jan  5 01:24:14 2008
From: h.wickham at gmail.com (hadley wickham)
Date: Fri, 4 Jan 2008 18:24:14 -0600
Subject: [Rd] checking whether the name space can be loaded with stated
	dependencies
In-Reply-To: <59d7961d0801041454t8edfe8bre4fdcfa10cc5342d@mail.gmail.com>
References: <f8e6ff050801031831j36005a1cw8449a6f65481845b@mail.gmail.com>
	<Pine.LNX.4.64.0801040237590.26624@gannet.stats.ox.ac.uk>
	<f8e6ff050801040615t3469f32cldfe27bedc5539b1@mail.gmail.com>
	<59d7961d0801041454t8edfe8bre4fdcfa10cc5342d@mail.gmail.com>
Message-ID: <f8e6ff050801041624u735947e3yab22528acbd441d9@mail.gmail.com>

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/



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