Hello,
I am noticing different behavior with respect to .First when working in
Terminal or working with the R gui on Mac OSX, and I am wondering if
someone might clarify for me the intention behind this. In both cases, I
am running 3.0.2 on the same machine.
In my ~/.Rprofile I have a function .First( )
I then create a new function .First in my workspace, and save the image on
exit.
If I do this in Terminal, the .First from my saved image will execute,
while the .First from my .Rprofile will not.
If I do this in the R gui, BOTH .First functions execute. (obviously, if
the two functions are identical, the "same" function executes twice.)
It appears that there is a function .First in tools:RGUI (see below). The
one saved here is the .First loaded from .Rprofile. Inspecting the two
reveals that the one in .GlobalEnv is the function manually created.
My questions are:
(1) Is the intended behavior that a .First in a restored image will take
precedence over a .First in .Rprofile. (I assume so, since according to
?Startup the image loads after the .Rprofile is sourced)
(2) Why is the .First function from .Rprofile saved to tools:RGUI?
(3) If a package contains a function .First, will both that function and
the user's .First (assuming it exists) be executed at startup?
Below are sessionInfo and some additional details:
Thank you,
Rick
Mac OSX 10.9
I created a new user. In that users ~/.Rprofile, I have only the following
function
## .Rprofile
.First <- function() {
cat("\n\nThis 'First' is from .Rprofile\n\n")
}
In my workspace, I then create a different function .First
## .Rprofile
.First <- function() {
cat("\n\nThis 'First' is manually created in the
workspace\n\n")
}
quit("yes")
Then re open R. Between execution in R.app & R in Terminal, I rm ~/.Rdata
# -------
THIS IS FROM R.app> for (i in seq(search()))
+ cat(sprintf("%20s : %17s", search()[[i]],
paste(ls(pattern="\\.First",
all=TRUE, pos=i), collapse=", ")), "\n")
.GlobalEnv : .First
tools:RGUI : .__RGUI__..First
package:stats :
package:graphics :
package:grDevices :
package:utils :
package:datasets :
package:methods :
Autoloads :
package:base : .First.sys
THIS IS FROM TERMINAL> for (i in seq(search()))
+ cat(sprintf("%20s : %17s", search()[[i]],
paste(ls(pattern="\\.First",
all=TRUE, pos=i), collapse=", ")), "\n")
.GlobalEnv : .First
package:stats :
package:graphics :
package:grDevices :
package:utils :
package:datasets :
package:methods :
Autoloads :
package:base : .First.sys
# ------ SESSION INFO ------- #
## TERMINAL> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
## R.app
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
# ------ END ------- #
Ricardo Saporta
Graduate Student, Data Analytics
Rutgers University, New Jersey
e: saporta@rutgers.edu
[[alternative HTML version deleted]]