简体   繁体   English

.First()不执行; Win7 Rgui

[英].First() does not execute; win7 Rgui

With this in .Rprofile (first line copied from ?Startup examples): 在.Rprofile中使用它(从?Startup示例复制的第一行):

.First <- function() cat("\n   Welcome to R!\n\n")
foo <- "bar"

I do not see the Welcome text. 我没有看到欢迎文本。 The following shows that .Rprofile executes. 下面显示了.Rprofile的执行。

ls()
[1] "foo"

Apparently .First() does not execute. 显然.First()不执行。 Any idea why not? 知道为什么不吗?

I'm running in an Rgui console on win7pro with R v3.6.1 x64. 我在带有R v3.6.1 x64的win7pro上的Rgui控制台中运行。

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. 我已经了解到,我将无法执行.First()中想做的事情,但是我仍然想知道为什么它甚至没有执行。 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. 我没有进行任何高级配置更改,而是从Rgui.exe的快捷方式启动了控制台。

Solved: Early on I had bad code in .First(). 解决了:早期我在.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. 这样,赋值foo<-"bar"更清楚地表明.Rprofile正在执行。 What I didn't realize was that the bad .First() got saved in some hidden environment in .RData. 我没有意识到的是,糟糕的.First()已保存在.RData中的某个隐藏环境中。 After that, no matter what I did with .First() in .Rprofile, it always got replaced with the bad one. 之后,无论我对.Rprofile中的.First()做什么,它总是被坏的替换。 To solve the problem, I just needed to delete .RData. 为了解决这个问题,我只需要删除.RData。

Update: .First() does not go into a hidden environment, but the starting dot makes it hide from ls(). 更新:.First()不会进入隐藏环境,但是起始点使它对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. 将来,我想我只会删除.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. 每当在.Rprofile中更改.First()时,都需要从使用R的每个文件夹中删除.RData,或者在每个文件夹中执行rm(.First)和`q('yes')。 That just begs for something to be missed. 那就乞求要错过的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM