From dwinsemius at comcast.net  Sat Feb 23 03:39:55 2013
From: dwinsemius at comcast.net (David Winsemius)
Date: Fri, 22 Feb 2013 18:39:55 -0800
Subject: [Rd] Recommended way to call/import functions from a Suggested
	package
In-Reply-To: <CABdHhvHkJkyzKODdDKKt+fmCeUAXJC7L24vXLuLPWmRYsYZtkQ@mail.gmail.com>
References: <FD2C7845-F6AD-4AA1-91C1-8CB14F43AA7D@stat.ubc.ca>
	<CABdHhvHkJkyzKODdDKKt+fmCeUAXJC7L24vXLuLPWmRYsYZtkQ@mail.gmail.com>
Message-ID: <AD286524-32D5-4808-B984-E6AF521FB6E5@comcast.net>


On Feb 22, 2013, at 6: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.

I've always wondered: How does lattice manage to use grid functions without putting them on the search path?

-- 
David
> 
> Hadley
> 
> On Fri, Feb 22, 2013 at 6:26 PM, Davor Cubranic <cubranic at stat.ubc.ca> wrote:
>> If in my package "Foo" I call a function from another package "Bar" if it's available, according to R-exts, this sounds like I should include "Suggests: Bar" in package Foo's description. But the manual is silent on how to treat Bar's namespace. Should I import it? If so, should this be conditional or unconditional? There is a thread from 2008 in which Duncan Murdoch suggests trying conditionally importing a package if it's installed, with the caveat "If this is allowed" (http://tolstoy.newcastle.edu.au/R/e5/devel/08/10/0488.html). This appears to work in current release of R, 2.15.2, but I'm still not clear if it's officially allowed, much less recommended.
>> 
>> The manual also says:
>> 
>>> If a package only needs a few objects from another package it can use a fully qualified variable reference in the code instead of a formal import. A fully qualified reference to the function f in package foo is of the form foo::f. This is slightly less efficient than a formal import and also loses the advantage of recording all dependencies in the NAMESPACE file, so this approach is usually not recommended. Evaluating foo::f will cause package foo to be loaded, but not attached, if it was not loaded already?this can be an advantage in delaying the loading of a rarely used package.
>>> 
>> 
>> 
>> Would this be a better solution than importing when calling into a suggested package?
>> 
>> Davor
>> 
>> 
>>        [[alternative HTML version deleted]]
>> 
>> 
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>> 
> 
> 
> 
> -- 
> Chief Scientist, RStudio
> http://had.co.nz/
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

David Winsemius
Alameda, CA, USA



[Rd] Recommended way to call/import functions from a Suggested package
David Winsemius