Skip to content
Prev 302122 / 398502 Next

How to link two R packages together

Hi Josh,
Thank you so much for your detailed explanation. It's very clear, and now I can understand the difference between depends and imports.
Thank you so much for your help!! I really really appreciate it!
Yours,
Xuan

-----Original Message-----
From: Joshua Wiley [mailto:jwiley.psych at gmail.com] 
Sent: Thursday, August 02, 2012 10:40 AM
To: Xuan Zhao
Cc: r-help at r-project.org
Subject: Re: [R] How to link two R packages together

Hi Xuan,

I would expect ~/R/ to be the R_HOME directory, though perhaps I am wrong.  Also, you only need a depends or an imports, not both.  At a simplified level, the difference is that importing PKG2 in PKG1 makes the (exported) functions in PKG2 available to PKG1. Depends also makes the (exported) functions in PKG2 available to PKG1, but it _also_ makes them available to the user.  This can be good or bad, with the recommendation now being not to. The reason it can be good is if you want your users to have access to functions in both packages without explicitly loading both. However, let's say that function foo() is defined in PKG2 and in PKG3. PKG1 does not know about PKG3, and the user had PKG3 loaded prior to loading PKG1. Then when PKG1 loads, PKG2 also loads, and because all the exported functions from PKG2 are included, PKG2::foo() masks PKG3::foo(), which can be annoying for users if your package adds unnecessary functions to the search path potentially masking the versions they wanted to use.

That was a rather convoluted explanation, but hopefully it is somewhat clear.

Sincerely,

Josh
On Thu, Aug 2, 2012 at 7:02 AM, Xuan Zhao <xuan.zhao at sentrana.com> wrote:
--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/