2017-07-19 20 views
0

在Ubuntu(16.04)下使用Rstudio(版本1.0.143),如果我將system("echo 'Hello world'")添加到我的/usr/lib/R/etc/Rprofile.site文件中,啓動時R Studio中沒有顯示Hello world消息。
如果我從終端啓動R,我有Hello world消息。RStudio不執行來自Rprofile.site的`system`命令

似乎是R工作室從Rprofile.site忽略system命令(同上從.Rprofile文件中的home目錄)

是否有可能使系統命令執行或者是有一個很好的理由,以避免這種行爲?

回答

1

簡而言之,RStudio根本不會收到Rprofile.site文件。 (我使用Ubuntu 17.04和編譯R-3.4.1自己)

測試Rprofile.site

要簡單的問題,你可以在Rprofile.site文件中使用x=1system("echo 'Hello world'")。然後,你打開RStudio:

> x 
Error: object 'x' not found 

,告訴你RStudio是否忽略了system()命令在Rprofile.site或R工作室忽略整個Rprofile.site文件。

測試system()

如果你發現你的RStudio源Rprofile.site文件來代替。您可以嘗試system("echo haha > x")system2('echo', 'haha', stdout = T) -> x

這會告訴您RStudio是否忽略system()命令,或者由於其他原因而看不到該消息。

什麼RStudio說

最後,看到https://support.rstudio.com/hc/en-us/community/posts/200643758-Rprofile-site-

我們並沒有實際實現代碼採購Rprofile.site(R一樣)

由Ian Pylvainen,支持工程師在RStudio,Inc.

+0

在我的配置中,Rstudio似乎從Rprofile.site中找到所有的東西,但不是'system'命令。如果我在此文件中添加'x = 1',則該對象在Rstudio中可用。 'cat(「Hello world」)'也會打印這條消息。另請參閱[這個問題](https://stackoverflow.com/questions/45119432/more-meaningfull-window-title-for-rstudio)我們使用'Rprofile.site'來攻擊RStudio窗口標題,使其更具信息性。 – Gilles

+0

這非常有趣。你可以嘗試我添加的內容。 –

+0

聰明的主意!事實上,x文件是用system(「echo haha​​> x」)'在光盤上創建的。所以系統功能確實被執行,但輸出在RStudio R控制檯中不可見。我錯過了,因爲我想執行的系統命令嘗試操作RStudio窗口標題,但是從Rprofile.site內部執行,它剛好在RStudio窗口出現之前執行!但我找到了另一種方式。 – Gilles