From hpages at fhcrc.org  Fri May 30 18:55:31 2014
From: hpages at fhcrc.org (=?UTF-8?B?SGVydsOpIFBhZ8Oocw==?=)
Date: Fri, 30 May 2014 09:55:31 -0700
Subject: [Rd] Style question
In-Reply-To: <CABdHhvHP7VRmU6Z68EDieEPOsyqUkFRrkuG=ohO0f8V5J0tWUw@mail.gmail.com>
References: <CAOVYLHcgBqBmFMhSnx3hRELV4D9ijdHRoG=SmnRx8g=6f90F3A@mail.gmail.com>
	<538654A4.60402@fhcrc.org>
	<CABdHhvHP7VRmU6Z68EDieEPOsyqUkFRrkuG=ohO0f8V5J0tWUw@mail.gmail.com>
Message-ID: <5388B803.8030506@fhcrc.org>

Hi Hadley,

On 05/30/2014 07:06 AM, Hadley Wickham wrote:
>> Even more important than choosing between whatever(...)
>> or foo::whatever(...), you should import that function
>> from the foo package by putting
>>
>>    importFrom(foo, whatever)
>>
>> or
>>
>>    import(foo)
>>
>> in your NAMESPACE file.
>>
>> The 1st form also kind of document what function comes from what
>> package.
>>
>> Note that you'll also need to have foo in the Depends or Imports field
>> of your DESCRIPTION file. Which field is appropriate depends on whether
>> or not you want foo to show up in the user's search path when s/he loads
>> your package with 'library(yourpackage)'.
>
> Except that if you do foo::whatever() you don't need to explicitly
> import the function.

There is at least one subtle consequence to keep in mind when doing
this. Of course, whatever choice you make, if the whatever() function
moves to a different package, this breaks your package.
However, if you explicitly import the function, your package will
break at load-time (which is good) and you'll only have to modify
1 line in the NAMESPACE file to fix it. But if you do foo::whatever(),
your package won't break at load-time, only at run-time. Also you'll
have to edit all the calls to foo::whatever() to fix the package.

Probably not a big deal, but in an environment like Bioconductor where
infrastructure classes and functions can be shared by hundreds of
packages, having people use foo::whatever() in a systematic way would
probably make maintenance a little bit more painful than it needs to
be when the need arises to reorganize/refactor parts of the
infrastructure. Also, the ability to quickly grep the NAMESPACE
files of all BioC packages to see who imports what is very convenient
in this situation.

Cheers,
H.

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



[Rd] Style question
=?UTF-8?B?SGVydsOpIFBhZ8Oocw==?=