From ggrothendieck at gmail.com  Tue Sep 20 16:06:33 2005
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Tue, 20 Sep 2005 10:06:33 -0400
Subject: [Rd] Shy Suggestion?
In-Reply-To: <1127224092.21824.20.camel@biol102145.oulu.fi>
References: <1127222728.21824.15.camel@biol102145.oulu.fi>
	<433011BE.8090007@jhsph.edu>
	<1127224092.21824.20.camel@biol102145.oulu.fi>
Message-ID: <971536df0509200706171c26d@mail.gmail.com>

On 9/20/05, Jari Oksanen <jarioksa at sun3.oulu.fi> wrote:
> On Tue, 2005-09-20 at 09:42 -0400, Roger D. Peng wrote:
> > I think this needs to fail because packages listed in 'Suggests:' may, for
> > example, be needed in the examples.  How can 'R CMD check' run the examples and
> > verify that they are executable if those packages are not available?  I suppose
> > you could put the examples in a \dontrun{}.
> >
> Yes, that's what I do, and exactly for that reason: if something is not
> necessarily needed (= 'suggestion' in this culture), it should not be
> required in tests. However, if I don't use \dontrun{} for a
> non-recommended package, the check would fail and I would get the needed
> information: so why should the check fail already when checking
> DESCRIPTION?
> 

Also one could not have any demos that depend on the missing
packages nor vignettes.

1. Note that you can use:

if (require(mypackage)) {
  myfunction1()
  myfunction2()
}

which will only run my function if mypackage is accessible.
The main downside is that you don't interspersed input and
output but rather it shows the above all at once since its
one statement and then one sees all the output.

2. One could do:

if (require(mypackage)) myfunction1()
if (require(mypackage)) myfunction2()

but that is quite ugly.

3. Another possibility is:

if (!require(mypackage)) myfunction1 <- myfunction2 <- dummyfunction
myfunction1()
myfunction2()
if (!require(mypackage)) myfunction1 <- get("myfunction1", "package:mypackage")
if (!require(mypackage)) myfunction2 <- get("myfunction2", "package:mypackage")

None of these is really entirely satisfactory and I think we need some
better mechanism/solution for situations like this.

Note that this comes up not only in the situation you mention but also 
if you are working on a package whose purpose is to interface to 
external code since that external code may not be available but you
still want it to pass R CMD check.



[Rd] Shy Suggestion?
Gabor Grothendieck