Hi, I am trying to write a package(A) for myself and need to use a function from another package(B) which is in R already(need to install it before use). Could anyone tell me how to implement that? Also I hope that my package gives an ERROR message(something like "STOP, please install package B first") if the package B is not installed yet. It is my first time to write a package. Thanks very much for your help. Peter
Tuszynski, Jaroslaw W.
2005-Aug-09 18:08 UTC
[R] how to use the function from another package
See "Writing R Extensions" / Creating R package / Description file / "depends" field (section 1.1.1). Jarek ====================================================\====== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation <\__,| (703) 676-4192 "> \ Jaroslaw.W.Tuszynski at saic.com ` \ -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Peter Yang Sent: Tuesday, August 09, 2005 1:56 PM To: R-help at stat.math.ethz.ch Subject: [R] how to use the function from another package Hi, I am trying to write a package(A) for myself and need to use a function from another package(B) which is in R already(need to install it before use). Could anyone tell me how to implement that? Also I hope that my package gives an ERROR message(something like "STOP, please install package B first") if the package B is not installed yet. It is my first time to write a package. Thanks very much for your help. Peter ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On Tue, 9 Aug 2005, Peter Yang wrote:> I am trying to write a package(A) for myself and need to use a > function from another package(B) which is in R already(need to install > it before use). Could anyone tell me how to implement that? Also I > hope that my package gives an ERROR message(something like "STOP, > please install package B first") if the package B is not installed > yet. It is my first time to write a package. Thanks very much for > your help.In your package's DESCRIPTION file, you should have an entry that lists your package dependencies. Simply add the other package there as well. For example, to support the current version of R and a package named foo, the entry would look like this: Depends: R (>= 2.1.1), foo ---------------------------------------------------------- SIGSIG -- signature too long (core dumped)
Tuszynski, Jaroslaw W.
2005-Aug-09 19:13 UTC
[R] how to use the function from another package
> Thanks very much for your help. Do I still have to write library( ) toload the library in my code after I add a "depends" field in the DESCRIPTION file? No, First when user of your package downloads it (at least on Windows machines) all required packages are also downloaded (this mechanism sometimes needs manual help, but that is another story). Then when he loads your package (by calling library(YourPackage)) all required packages are loaded into R. One good way to research this kind of questions (other than documentation and R-Help) is to study source code of other people packages. Jarek ====================================================\====== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation <\__,| (703) 676-4192 "> \ Jaroslaw.W.Tuszynski at saic.com ` \ -----Original Message----- From: peterwyang at gmail.com [mailto:peterwyang at gmail.com] Sent: Tuesday, August 09, 2005 2:57 PM To: Tuszynski, Jaroslaw W. Subject: Re: [R] how to use the function from another package Thanks very much for your help. Do I still have to write library( ) to load the library in my code after I add a "depends" field in the DESCRIPTION file? Thanks. Peter On 8/9/05, Tuszynski, Jaroslaw W. <JAROSLAW.W.TUSZYNSKI at saic.com> wrote:> See "Writing R Extensions" / Creating R package / Description file / > "depends" field (section 1.1.1). > > Jarek > ====================================================\======> > Jarek Tuszynski, PhD. o / \ > Science Applications International Corporation <\__,| > (703) 676-4192 "> \ > Jaroslaw.W.Tuszynski at saic.com ` \ > > > > -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Peter Yang > Sent: Tuesday, August 09, 2005 1:56 PM > To: R-help at stat.math.ethz.ch > Subject: [R] how to use the function from another package > > Hi, I am trying to write a package(A) for myself and need to use a > function from another package(B) which is in R already(need to install > it before use). Could anyone tell me how to implement that? Also I > hope that my package gives an ERROR message(something like "STOP, > please install package B first") if the package B is not installed > yet. It is my first time to write a package. Thanks very much for yourhelp.> > Peter > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >