[R] How do I import packages with the package I've built?

Uwe Ligges ligges at statistik.uni-dortmund.de
Wed Nov 21 17:32:13 CET 2007



Nutter, Benjamin wrote:
> So if I understand you correctly, if I include in my namespace file the
> command    importFrom(MASS, stepAIC),   whenever stepAIC is called from
> my package, it will still run even if I haven't explicitly imported the
> MASS package?

Yes.



> Or if I use the command      import(survival)   then the functions in
> the survival package will work within my functions even without
> explicitly loading the package?

Yes.

Uwe Ligges



> Thanks for the help.
> 
> Benjamin
> 
> -----Original Message-----
> From: Uwe Ligges [mailto:ligges at statistik.uni-dortmund.de] 
> Sent: Saturday, November 17, 2007 12:04 PM
> To: Nutter, Benjamin
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] How do I import packages with the package I've built?
> 
> There is a difference between importing a namespace and loading a
> package:
> 
> If you import functions from a namespace into your package, these 
> functions are known within that namespace, i.e. functions from your 
> package's namespace know the other functions and can use them. The user 
> still won't see those imported functions while working on the top level.
> If you want the latter, you have to load the other package explicitly, 
> e.g. in your .onLoad directives.
> 
> Uwe Ligges
> 
> 
> Nutter, Benjamin wrote:
>> I have successfully completed building a package to contain the
>> functions I commonly use.  However, I need to have other packages
>> installed in order for some of my functions to work.  I've been
> studying
>> the instructions on installing packages for about a month now, but
> still
>> haven't figured this one out.  From what I do understand, to import
>> additional packages I need some combination of commands in my
>> DESCRIPTION and NAMESPACE files.  Currently, these are what mine look
>> like:
>>
>> DESCRIPTION
>> Package: myPackage
>> Type: Package
>> Title: Commonly used functions.
>> Version: 1.0
>> Date: 2007-11-08
>> Author: My Name
>> Maintainer: My Name <myfault at somewhere.net>
>> Description: Blah Blah Blah
>> License: R 2.3.0
>> Depends: MASS, survival
>>
>>
>> NAMESPACE
>> export(func1, func2, ... , funcx)
>>
>> import(MASS, survival)
>>
>>
>> These pass all the checks, and the package installs just fine, but it
>> doesn't load MASS and survival when I load myPackage.  What am I doing
>> wrong?
>>
>> Benjamin
>>
>>
>> P Please consider the environment before printing this e-mail
>>
>> Cleveland Clinic is ranked one of the top hospitals
>> in America by U.S. News & World Report (2007).  
>> Visit us online at http://www.clevelandclinic.org for
>> a complete listing of our services, staff and
>> locations.
>>
>>
>> Confidentiality Note:  This message is intended for
> use\...{{dropped:13}}
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> 
> ===================================
> 
> P Please consider the environment before printing this e-mail
> 
> Cleveland Clinic is ranked one of the top hospitals
> in America by U.S. News & World Report (2007).  
> Visit us online at http://www.clevelandclinic.org for
> a complete listing of our services, staff and
> locations.
> 
> 
> Confidentiality Note:  This message is intended for use
> only by the individual or entity to which it is addressed
> and may contain information that is privileged,
> confidential, and exempt from disclosure under applicable
> law.  If the reader of this message is not the intended
> recipient or the employee or agent responsible for
> delivering the message to the intended recipient, you are
> hereby notified that any dissemination, distribution or
> copying of this communication is strictly prohibited.  If
> you have received this communication in error,  please
> contact the sender immediately and destroy the material in
> its entirety, whether electronic or hard copy.  Thank you.
>



More information about the R-help mailing list