[英]How to create .Renviron file?
我需要使用我的用户定义文件夹来存储我的包。 我已经提到了下面给出的链接。
我已经应用了相同的但它对我不起作用。 我创建了一个名为 .Renviron 的文件,其中包含数据 R_LIBS=c:/Rpackages ,其中安装了我的软件包。 但是,它仍然显示不存在这样的包“RODBC”。 另外,我将此文件放在我的 C 驱动器的 Documents 文件夹中并尝试过。 这也给出了同样的错误。 文件类型仍然显示为文本文档。 如何更改此文件类型?
打开终端并输入
touch $HOME/.Renviron
要打开您刚刚创建的文件,请通过 finder 导航到/Users/<your-user-name>/.Renviron
,或者只需打开终端并键入
open $HOME/.Renviron
单击开始并打开powershell。 将此代码复制到powershell
Add-Content c:\Users\$env:USERNAME\Documents\.Renviron "TEST_VARIABLE_1=my_username"
Add-Content c:\Users\$env:USERNAME\Documents\.Renviron "TEST_VARIABLE_2=123"
现在,您将在Documents
文件夹中拥有一个名为.Renviron
的文件。 关闭并重新打开 RStudio 。 然后运行Sys.getenv('TEST_VARIABLE_1')
以访问 R 中的变量(显然这也适用于您设置的任何其他环境变量)。
看看help(Startup)
,它在最后有一个例子:
## Example ~/.Renviron on Unix
R_LIBS=~/R/library
PAGER=/usr/local/bin/less
## Example .Renviron on Windows
R_LIBS=C:/R/library
MY_TCLTK="c:/Program Files/Tcl/bin"
## Example of setting R_DEFAULT_PACKAGES (from R CMD check)
R_DEFAULT_PACKAGES='utils,grDevices,graphics,stats'
# this loads the packages in the order given, so they appear on
# the search path in reverse order.
但请注意拼写: Renviron
小写 e。 只需使用文本编辑器并编辑文件。 另请注意,R 在其RHOME
下方的系统文件夹etc/
中有一个变体:
edd@bud:~$ R RHOME
/usr/lib/R
edd@bud:~$ cat $(R RHOME)/etc/Renviron.site
## Emacs please make this -*- R -*-
## empty Renviron.site for R on Debian
##
## Copyright (C) 2008 Dirk Eddelbuettel and GPL'ed
##
## see help(Startup) for documentation on ~/.Renviron and Renviron.site
# ## Example ~/.Renviron on Unix
# R_LIBS=~/R/library
# PAGER=/usr/local/bin/less
# ## Example .Renviron on Windows
# R_LIBS=C:/R/library
# MY_TCLTK="c:/Program Files/Tcl/bin"
# ## Example of setting R_DEFAULT_PACKAGES (from R CMD check)
# R_DEFAULT_PACKAGES='utils,grDevices,graphics,stats'
# # this loads the packages in the order given, so they appear on
# # the search path in reverse order.
edd@bud:~$
嗯。 看起来我是为 Debian 软件包编写的,它确实一直存在。 你仍然可以复制它。
值得补充的是,包usethis
现在提供了一系列功能,便于轻松编辑和打开 R 启动文件。 edit_*
函数系列可用于方便地编辑所需的启动和配置文件。 要编辑.Renviron
,这是存储相关配置的合适位置,请使用:
# Edit Renviron
usethis::edit_r_environ()
# You can also consider creating project-specific settings:
usethis::edit_r_environ(scope = "project")
Usethis提供了其他对管理 R 配置有用的函数。 例如,为了编辑Makevars
您可以执行以下操作:
# Edit .R/Makevars
usethis::edit_r_makevars()
在 Mac 上, Renviron文件位于
/Library/Frameworks/R.framework/Versions/Current/Resources/etc/
在用户的主目录中创建 .Renviron 文件将无济于事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.