With this in .Rprofile (first line copied from ?Startup examples):
.First <- function() cat("\n Welcome to R!\n\n")
foo <- "bar"
I do not see the Welcome text. The following shows that .Rprofile executes.
ls()
[1] "foo"
Apparently .First()
does not execute. Any idea why not?
I'm running in an Rgui console on win7pro with R v3.6.1 x64.
I already learned that I will not be able to do what I wanted to do in .First(), but I still want to know why it is not even executing. I might want to use it for something in the future. I haven't made any fancy configuration changes, and I launch the console from a shortcut to Rgui.exe.
Solved: Early on I had bad code in .First(). While troubleshooting I cleared the workspace with
rm(list=ls())
q('yes')
That way the assignment foo<-"bar"
more clearly showed that .Rprofile was executing. What I didn't realize was that the bad .First() got saved in some hidden environment in .RData. After that, no matter what I did with .First() in .Rprofile, it always got replaced with the bad one. To solve the problem, I just needed to delete .RData.
Update: .First() does not go into a hidden environment, but the starting dot makes it hide from ls(). To exit with a completely clear workspace, the code would be:
rm( list=ls(all.names=T) )
q('yes')
That's a lot of typing. In the future, I think I'll just delete .RData.
To me this seems a lot like a bug. Anytime you change .First() in .Rprofile, you need to delete .RData from every folder where you use R or execute rm(.First)
and `q('yes') in every folder. That just begs for something to be missed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.