From nalimilan at club.fr  Tue Feb 26 10:58:25 2013
From: nalimilan at club.fr (Milan Bouchet-Valat)
Date: Tue, 26 Feb 2013 10:58:25 +0100
Subject: [Rd] Recommended way to call/import functions from a Suggested
 package
In-Reply-To: <4F6FBC64-4EAE-43E2-B041-B54663CDF950@stat.ubc.ca>
References: <FD2C7845-F6AD-4AA1-91C1-8CB14F43AA7D@stat.ubc.ca>
	<CABdHhvHkJkyzKODdDKKt+fmCeUAXJC7L24vXLuLPWmRYsYZtkQ@mail.gmail.com>
	<FDF2030A-2A91-4A40-B09F-C4DD78682A62@r-project.org>
	<CABdHhvHx1H09Qbx6mGBZUkB-yyta5nNv-cg=JgbS+0Js-iN7Yw@mail.gmail.com>
	<4F6FBC64-4EAE-43E2-B041-B54663CDF950@stat.ubc.ca>
Message-ID: <1361872705.15898.3.camel@milan>

Le lundi 25 f?vrier 2013 ? 12:59 -0800, Davor Cubranic a ?crit :
> I haven't gotten any complaints from "R CMD check" when I used Simon's
> suggestion, even with "--as-cran" flag. Hadley's suggestion to use
> 'require' also works, and its side-effect of attaching the other
> package can in some applications be seen by the end user as a nice
> bonus, so I'll probably have to decide on a case-by-case basis which
> method to use.
> 
> On the other hand, conditional import fails the check with "Namespace
> dependency not required: 'foo'", if 'foo' is only listed in the
> Suggests. Putting it in Imports gets rid of the warning, but then I
> don't need to conditionally import it any more. :-)
> 
> To summarize, it appears that the only way to call functions from a
> suggested package is by using either 'require' (which will dynamically
> attach it) or the double colon method. Is this something that should
> be mentioned in R-exts?
I second that request. As this thread illustrates, most of us do not
know the best way of using functions from suggested packages.

Regards

> Davor
> 
> 
> On 2013-02-22, at 8:40 PM, Hadley Wickham wrote:
> 
> > 
> > On Friday, February 22, 2013, Simon Urbanek wrote:
> > 
> > On Feb 22, 2013, at 9:13 PM, Hadley Wickham wrote:
> > 
> > > Hi Davor,
> > >
> > > To the best of my knowledge, there's only one way to use functions
> > > from a suggested package: with require:
> > >
> > > if (require("suggested_package")) {
> > >  function_from_suggested_package()
> > > } else {
> > >  stop("suggested package not installed")
> > > }
> > >
> > > Unfortunately I don't think there's any way to use a suggested package
> > > without polluting the search path.
> > >
> > 
> > Why -- wouldn't
> > 
> > if (is.function(try(foo::bar, silent=TRUE))) {
> >   foo::bar(...)
> > }
> > 
> > do the job?
> > 
> > 
> >  I may be misremembering, but I think r cmd check complains about that.
> > 
> > Hadley
> > 
> > 
> > -- 
> > Chief Scientist, RStudio
> > http://had.co.nz/
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Recommended way to call/import functions from a Suggested package
Milan Bouchet-Valat