[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,
>for
>example for organizing the functions into separate files, or just
>because
>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
>directory
>by double quote and call its functions. Just wonder how R is handling
>this
>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
>R
>file will cause complain of file not found after installation.
>
>Thanks
>
>
>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
>you
>>> 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
>exceptions
>> 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
>scripts.
>>
>> Duncan Murdoch
>>
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>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.




More information about the R-help mailing list