[英]I placed a function into my .Rprofile file, but it doesn't appear when I load R? I don't understand why
[英]How can I load my .RProfile using Textmate's R Bundle
該問題針對的是那些在Mac上碰巧結合Macromate的[Textmate](http://macromates.com/)文本編輯器和“ R”捆綁軟件一起使用R的用戶。 所有這些都是很漂亮的,不用說,但是現在還不重要:-)
我有一個.RProfile文件位於默認的“〜”啟動目錄中,並且其中包含許多有用的函數,我希望在編寫R腳本時可以使用它們。 但是我在大部分寫作中也使用Textmate,並使用cmd-R功能在Textmate中運行腳本。
有沒有一種方法(很可能是通過Textmate的Bundle設置完成的),我可以將Textmate指向我的.RProfile,這樣就不必在每個腳本的基礎上將函數寫入每個腳本了?
要么
在我編寫的任何腳本中包含任何自定義函數實際上是否更好,以便具有基本R設置的任何人都可以獲取和運行我的腳本?
我覺得我一定在Textmate或調用我的腳本的R環境中缺少一個容易設置的設置或配置文件。
非常感謝!
R Bundle Developer顯然正在為此工作(請參閱郵件列表中的此帖子 ),但目前尚不可用。
同時,您有兩種選擇。
首先,您可以創建一個新的捆綁軟件(例如“ briandk-R”),然后使用“ source($ 1)”在該捆綁軟件中創建一個代碼段,也可以僅硬編碼要獲取的文件而不是占位符(因此,例如,“ source(“〜/ some_file_to_source.R”)。如果您要進行后者,則可以將TM配置為通過選項卡觸發器來獲取文件(在捆綁包編輯器中,切換到“設置”(上方左上角),然后在“范圍選擇器”字段中鍵入“ source.r,source.rd.console”,然后為制表觸發選擇幾個字母(例如“ src”)。
如果您不想這樣做,請轉到“ Rdaemon”目錄(位於您的主目錄或〜/ Library / Application Support / Rdaemon中)。 查看該目錄,您將看到另一個名為“守護程序”的目錄。 在其中有一個名為“ start.r”的文件,其中列出了從Rdaemon啟動R時獲得的文件。您知道從那里開始的工作。(注意:該目錄還包含幾個其他腳本,這些腳本包含初始設置。您可能也希望看看這些)
道格回應的第一部分提供了最簡單的即時解決方案...添加
source('/Users/briandk/.Rprofile')
在您想要這些功能的任何.r文件的開頭...使用那一行代碼,即可獲得實用程序功能。 當然,這僅在運行整個TM文件時才有用。
理想情況下,捆綁軟件將被更新……也許可以通過TM的首選項來支持shell變量???
TM_RPROFILE
可以將其設置為您的.Rprofile文件的路徑。
我只是用兩行代碼將其破解到了tmR.rb中。 要實現此目的,請轉至〜/ Library / Application Support / TextMate / Pristine Copy / Bundles /並顯示R.tmbundle的內容
在這里,您可以找到support / tmR.rb
在我的版本中,在112行附近,您應該更改
tmpDir = File.join(ENV['TMP'] || "/tmp", "TM_R")
recursive_delete(tmpDir) if File.exists?(tmpDir) # remove the temp dir if it's already there
Dir::mkdir(tmpDir)
# Mechanism for dynamic reading
# stdin, stdout, stderr = popen3("R", "--vanilla", "--no-readline", "--slave", "--encoding=UTF-8")
stdin, stdout, stderr, pid = my_popen3("R --vanilla --slave --encoding=UTF-8 2>&1")
# init the R slave
stdin.puts(%{options(device="pdf")})
stdin.puts(%{options(repos="#{cran}")})
至
tmpDir = File.join(ENV['TMP'] || "/tmp", "TM_R")
recursive_delete(tmpDir) if File.exists?(tmpDir) # remove the temp dir if it's already there
Dir::mkdir(tmpDir)
rprofile = (ENV['TM_RPROFILE'] == nil) ? "" : "source('" + ENV['TM_RPROFILE'] + "')"
# Mechanism for dynamic reading
# stdin, stdout, stderr = popen3("R", "--vanilla", "--no-readline", "--slave", "--encoding=UTF-8")
stdin, stdout, stderr, pid = my_popen3("R --vanilla --slave --encoding=UTF-8 2>&1")
# init the R slave
stdin.puts("#{rprofile}")
stdin.puts(%{options(device="pdf")})
stdin.puts(%{options(repos="#{cran}")})
只需在其中添加2行...以“ rprofile =“開頭的行和包含“#{rprofile}”的行
-會
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.