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?

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

