[R] Source awareness?
William Dunlap
wdunlap at tibco.com
Wed Oct 6 18:05:36 CEST 2010
Over the years I've seen lots of requests concerning
how to conveniently call scripts from other scripts.
The S (R & S+) language is oriented towards functions,
not scripts (or macros), and many of the requests are
for things easy to do in functions (or packages of functions)
but not in scripts. Some would be easier if one used
a package of scripts (built with the usual R package
building tools).
I'd like to know from people who do this sort of thing
what pushes them toward using sets of scripts instead
of functions. I can think of several possible reasons
but would like to hear from people who actually do this
sort of thing. E.g., is the clarity and concreteness
of a script the important thing? Is it difficult to
make a package of functions? Is it that people are
used to another language where scripts or macros are
the preferred way to go? Or are other reasons?
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Ralf B
> Sent: Wednesday, October 06, 2010 8:50 AM
> To: r-help Mailing List
> Subject: [R] Source awareness?
>
> Here the general (perhaps silly question) first: Is it possible for a
> script to find out if it was sourced by another script or run
> directly?
>
> Here a small example with two scripts:
>
> # script A
> print ("This is script A")
>
> # script B
> source("C:/scriptA.R")
> print ("This is script B")
>
> I would like to modify script A in a way so that it only outputs 'This
> is script A' if it was called directly, but keeps quiet in the other
> case.
>
> In addition to that, is it possible to access the stack of script
> calls from the environment?
>
> Ralf
>
> ______________________________________________
> 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