[R] Help with importing scripts within the same package?

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Fri Jan 24 05:08:31 CET 2014

You keep talking about "including" and "sourcing" and now "dependencies". Stop that. Don't do it, don't think that. All functions in all R files of a package are loaded together in one namespace. Your separation of functions between R files in the package source is entirely for your editing convenience. Dependencies only apply between packages, not within them.
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
Sent from my phone. Please excuse my brevity.

Charlie Xia <li.xia at stanford.edu> wrote:
>Hi Duncan,
>Thanks for replying. I may need to clarify.
>What I want is something that can let one R file in a package aware of
>another R file in the same package. It does happen a lot in real life,
>example for organizing the functions into separate files, or just
>you need to include a third party provided R file containing functions.
>Something alike in C you can include a file and within the same
>by double quote and call its functions. Just wonder how R is handling
>type of include so that the included function will work even after the
>package is deployed.
>load the package itself will cause cyclic load error. direct source the
>file will cause complain of file not found after installation.
>On Thu, Jan 23, 2014 at 6:08 PM, Duncan Murdoch
><murdoch.duncan at gmail.com>wrote:
>> On 14-01-23 7:54 PM, Charlie Xia wrote:
>>> Hi all,
>>> I have a very quick question yet found no answers with google.
>>> Say you when you are writing a package and have R/A.r and R/B.r, if
>>> want to load B.r in A.r, is there an obvious way to do so?
>> That question doesn't make sense.  You should think of package code
>as all
>> being executed when the package is installed.  (There are some
>> to this, e.g. functions that are called when the package is loaded.)
>> The user may choose to call some of your functions, and they may call
>> others, but it's not a good idea to think of the source for them as
>> Duncan Murdoch
>	[[alternative HTML version deleted]]
>R-help at r-project.org mailing list
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list