Benjamin Tyner
2014-Apr-23 00:59 UTC
[R] detecting the sourcing of site profile on Startup versus post-Startup
Greetings,
Is there any way to programmatically detect whether a piece of code is
being run within the initial (Startup) sourcing of the site profile?
For example, say I have a site profile, "/path/to/Rprofile.site". Is
there any function "my_func" which would return different values for
these two instances:
Rscript --no-site-profile --no-init-profile -e
"sys.source('/path/to/Rprofile.site', envir = .BaseNamespaceEnv);
my_func()"
versus:
export R_PROFILE=/path/to/Rprofile.site
Rscript --no-init-profile -e "my_func()"
Regards,
Ben
Duncan Murdoch
2014-Apr-23 10:55 UTC
[R] detecting the sourcing of site profile on Startup versus post-Startup
On 22/04/2014, 8:59 PM, Benjamin Tyner wrote:> Greetings, > > Is there any way to programmatically detect whether a piece of code is > being run within the initial (Startup) sourcing of the site profile? > > For example, say I have a site profile, "/path/to/Rprofile.site". Is > there any function "my_func" which would return different values for > these two instances: > > Rscript --no-site-profile --no-init-profile -e > "sys.source('/path/to/Rprofile.site', envir = .BaseNamespaceEnv); my_func()" > > versus: > > export R_PROFILE=/path/to/Rprofile.site > Rscript --no-init-profile -e "my_func()" >The commandArgs() function could see the different command lines and your function could deduce the difference from that. As far as I know, R keeps no other records of the startup process, but if you can modify other files, you could leave a record when .First was run, and see that it was run before Rprofile.site in the first case. See ?Startup. Duncan Murdoch