[R] Help with importing scripts within the same package?
macqueen1 at llnl.gov
Fri Jan 24 20:49:26 CET 2014
As Jeff Newmiller and Duncon Murdoch indicated, you can't modify the
contents of one part of a loaded package on the fly, and have the other
parts of the loaded package recognize the modifications. It's just not set
up that way. You have to repeat the build and install steps.
However, the devtools package makes it considerably more convenient to
re-build and re-load. In my limited experience with devtools and a small
simple package, it's really easy to use. You could think of as, in effect,
an easy way to re-source all your files after making changes to any one of
them, while the files are located within the package structure.
Otherwise, I think the best approach is to do all your debugging outside
the package context -- in which case one file can source the other as much
as you desire -- and then when it's good, put the functions into a package
(as Jeff Newmiller also suggested).
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
On 1/23/14 8:35 PM, "Charlie Xia" <li.xia at stanford.edu> wrote:
>Ah.. I see your point. That's interesting. Thanks a lot!
>But still kind of annoying for debugging, as you still need to source the
>code from the other file. Then you need to disable that part when you
>install. Need to figure out an elegant way for switching?
>On Thu, Jan 23, 2014 at 8:08 PM, Jeff Newmiller
><jdnewmil at dcn.davis.ca.us>wrote:
>> You keep talking about "including" and "sourcing" and now
>> Stop that. Don't do it, don't think that. All functions in all R files
>> package are loaded together in one namespace. Your separation of
>> 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
>> DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live
>> Live: OO#.. Dead: OO#.. Playing
>> Research Engineer (Solar/Batteries O.O#. #.O#. with
>> /Software/Embedded Controllers) .OO#. .OO#.
>> 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.
> [[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