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

Hervé Pagès hpages at fhcrc.org
Wed Feb 27 00:48:19 CET 2013


On 02/26/2013 03:12 PM, Simon Urbanek wrote:
>
> On Feb 26, 2013, at 5:47 PM, Hervé Pagès wrote:
>
>> Hi,
>>
>> So MASS::huber(1:10) seems to do the job i.e. (1) loads the MASS
>> package (if it's installed), (2) does not pollute the search path,
>> (3) no 'R CMD check' warning if MASS is listed in Suggests,
>> and (4) descent error message if MASS is not installed:
>>
>>   > MASS::huber(1:10)
>>   Error in loadNamespace(name) : there is no package called ‘MASS’
>>
>
> But (4) is a problem - it may not fail without MASS since it is only suggested, that's why you need the try() ...

Not everybody needs the try(). Some functions in my package won't be
able to return anything if the suggested package is not installed, so 
they will have to fail, preferably loudly rather than silently. A pretty 
common situation.

Believe it or not, the discussion was not just about the recommended
way to call functions from the multicore package or another package
providing some kind of support for parallelization, where not having
it installed doesn't diminish the set of functionalities provided by
my package, only makes it slower.

> The whole thread (which you omitted) was started because the usual if(require(...)) { .. } has an unwanted side-effect which the requestor did not want so the question was what does the job and that got settled before you joined in ...

I didn't omit the thread: I actually read every answer including yours.
Are you claiming your solution is the recommended one? Thanks for
clarifying. Also as suggested by some posts in this thread, a
clarification in the official documentation would be nice.

Thanks,
H.

>
> Cheers,
> S
>
>
>
>
>> So is this recommendable or are there good reasons for stating in
>> the manual that "this approach is usually not recommended"? (In which
>> case it would be good to know what the recommended way is.)
>>
>> Thanks,
>> H.
>>
>>
>> On 02/25/2013 02:56 PM, Hadley Wickham wrote:
>>>> loadNamespaces loads but does not attach the package. Suggests: is enough to
>>>> quieten the warning with
>>>>
>>>> ~/tmp$ R --version
>>>> R Under development (unstable) (2013-02-21 r62017) -- "Unsuffered
>>>> Consequences"
>>>>
>>>> This is consistent with RShowDoc("R-exts") section 1.1.1
>>>>
>>>>    Namespaces accessed by the ‘::’ and ‘:::’ operators must be listed here,
>>>> or in ‘Suggests’ or ‘Enhances’ (see below).
>>>
>>> I guess that's changed since I last tried it.  (My reproducible
>>> example forgot to include MASS in the Suggests :/ )
>>>
>>> Thanks!
>>>
>>> Hadley
>>>
>>
>> --
>> Hervé Pagès
>>
>> Program in Computational Biology
>> Division of Public Health Sciences
>> Fred Hutchinson Cancer Research Center
>> 1100 Fairview Ave. N, M1-B514
>> P.O. Box 19024
>> Seattle, WA 98109-1024
>>
>> E-mail: hpages at fhcrc.org
>> Phone:  (206) 667-5791
>> Fax:    (206) 667-1319
>>
>>
>

-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages at fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



More information about the R-devel mailing list