[R] Importing only one function from a package

Frank E Harrell Jr f.harrell at vanderbilt.edu
Sat Sep 29 14:50:27 CEST 2007


Matthew Keller wrote:
> Hi Soren,
> 
> What I do in cases like this is just copy the function and place it
> into my script at the top (or write it into its own source file and
> call it from script). Best,
> 
> Matt

I'm not a fan of that because you won't get updates when we update the 
packages.

Frank

> 
> On 9/28/07, Søren Højsgaard <Soren.Hojsgaard at agrsci.dk> wrote:
>> Dear List
>>
>> In a package I want to import the mApply function from the Hmisc package, and I would like to import only that function.
>>
>> 1) If I write "Depends: Hmisc" in the DESCRIPTION file I get the whole Hmisc package, so that is not the way to go ahead.
>>
>> 2) According to "Writing R extensions", sec 1.6.1 "Specifying imports and exports" I can (as I read it) simply type Hmisc:::mApply(....) in my code. That works, but gives a warning in the check:
>>
>> * checking for unstated dependencies in R code ... WARNING
>> '::' or ':::' imports not declared from:
>>   Hmisc
>>
>> 3) According to the same section I can (again as I read it) write in the NAMESPACE file
>> importFrom(Hmisc,mApply)
>>
>> Then I get:
>>
>> * checking package dependencies ... ERROR
>> Namespace dependencies not required:
>>   Hmisc
>>
>> That message goes away if I write  "Depends: Hmisc" in DESCRIPTION, but then we are back to 1) where I started where the whole Hmisc package is loaded.
>>
>> Obviously I have missed a point or two somewhere. Can anyone enlighten me?
>>
>> I use R 2.5.1 on windows XP.
>>
>> Regards
>> Søren

Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University



More information about the R-help mailing list