Startup(base)
Startup()所属R语言包:base
Initialization at Start of an R Session
在R会话开始初始化
译者:生物统计家园网 机器人LoveR
描述----------Description----------
In R, the startup mechanism is as follows.
在R,启动机制如下。
Unless --no-environ was given on the command line, R searches for site and user files to process for setting environment variables. The name of the site file is the one pointed to by the environment variable R_ENVIRON; if this is unset, "<VAR>R_HOME</VAR>/etc/Renviron.site" is used (if it exists, which it does not in a "factory-fresh" installation). The name of the user file can be specified by the R_ENVIRON_USER environment variable; if this is unset, the files searched for are ".Renviron" in the current or in the user's home directory (in that order). See "Details" for how the files are read.
除非--no-environ是在命令行上,R搜索网站和用户文件处理设置环境变量。网站文件的名称是指出通过环境变量R_ENVIRON;如果这是未设置,<VAR>R_HOME</VAR>/etc/Renviron.site使用(如果它存在,它不会在“工厂新鲜“的安装)。 R_ENVIRON_USER环境变量可以指定用户文件的名称,如果这是设置,搜索的文件是.Renviron在当前或在用户的家目录(在这顺序)。如何读取文件中的“详细资料”。
Then R searches for the site-wide startup profile file of R code unless the command line option --no-site-file was given. The path of this file is taken from the value of the R_PROFILE environment variable (after tilde expansion). If this variable is unset, the default is "<VAR>R_HOME</VAR>/etc/Rprofile.site", which is used if it exists (it contains settings from the installer in a "factory-fresh" installation). This code is sourced into the base package. Users need to be careful not to unintentionally overwrite objects in base, and it is normally advisable to use local if code needs to be executed: see the examples.
然后R搜索的站点范围内的R代码的启动配置文件,除非该命令行选项--no-site-file给予。该文件的路径采取从R_PROFILE环境变量(波浪线扩建后)的价值。如果这个变量没有设置,默认是<VAR>R_HOME</VAR>/etc/Rprofile.site,如果它存在,它是用来(它包含在“工厂新鲜”的安装设置安装)。此代码到base包采购。用户需要小心不要无意地覆盖在base对象,并使用local如果需要执行的代码:看到的例子,它通常是可取的。
Then, unless --no-init-file was given, R searches for a user profile, a file of R code. The path of this file can be specified by the R_PROFILE_USER environment variable (and tilde expansion will be performed). If this is unset, a file called ".Rprofile" is searched for in the current directory or in the user's home directory (in that order). The user profile file is sourced into the workspace.
然后,除非--no-init-file,R搜索,为用户的个人主页上,R代码文件。该文件的路径可以指定R_PROFILE_USER环境变量(和波浪线的扩建将进行)。如果这是设置,一个名为.Rprofile在当前目录搜索,或在用户的主目录(按顺序)。用户配置文件源到工作区。
Note that when the site and user profile files are sourced only the base package is loaded, so objects in other packages need to be referred to by e.g. utils::dump.frames or after explicitly loading the package concerned.
请注意,网站和用户配置文件的来源时,只base包装,所以被称为如其他包中的对象需要utils::dump.frames或明确载入有关的软件包。
R then loads a saved image of the user workspace from ".RData" in the current directory if there is one (unless --no-restore-data or --no-restore was specified on the command line).
ŕ然后加载的用户工作区保存的图像,从.RData在当前目录中,如果有一个(除非--no-restore-data或--no-restore在命令行上指定)。
Next, if a function .First is found on the search path, it is executed as .First(). Finally, function .First.sys() in the base package is run. This calls require to attach the default packages specified by options("defaultPackages"). If the methods package is included, this will have been attached earlier (by function .OptRequireMethods()) so that namespace initializations such as those from the user workspace will proceed correctly.
接下来,如果一个函数.First搜索路径上发现,它是执行.First()。最后,函数.First.sys()base包中运行。这就要求require附加指定默认options("defaultPackages")的包。如果methods包包括在内,这将受到重视早期(函数.OptRequireMethods()),因此,如从用户工作区的命名空间初始化将进行正确的。
A function .First (and .Last) can be defined in appropriate ".Rprofile" or "Rprofile.site" files or have been saved in ".RData". If you want a different set of packages than the default ones when you start, insert a call to options in the ".Rprofile" or "Rprofile.site" file. For example, options(defaultPackages = character()) will attach no extra packages on startup (only the base package) (or set R_DEFAULT_PACKAGES=NULL as an environment variable before running R). Using options(defaultPackages = "") or R_DEFAULT_PACKAGES="" enforces the R system default.
函数.First(和.Last)可以定义在适当.Rprofile或Rprofile.site文件或已被保存在“<X >。如果你想默认的一组不同的包比你在什么时候开始,插入到.RDataoptions或.Rprofile文件的调用。例如,Rprofile.site将启动(options(defaultPackages = character())包)(或设置base作为一个环境变量在运行R)没有附加额外的软件包。使用R_DEFAULT_PACKAGES=NULL或options(defaultPackages = "")强制R系统默认。
On front-ends which support it, the commands history is read from the file specified by the environment variable R_HISTFILE (default ".Rhistory" in the current directory) unless --no-restore-history or --no-restore was specified.
在支持它的前端,命令的历史记录读取指定的文件中的环境变量R_HISTFILE(默认为.Rhistory在当前目录),除非--no-restore-history或 --no-restore指定。
The command-line option --vanilla implies --no-site-file, --no-init-file, --no-environ and (except for R CMD) --no-restore Under Windows, it also implies --no-Rconsole, which prevents loading the "Rconsole" file.
命令行选项--vanilla指--no-site-file,--no-init-file,--no-environ(R CMD)--no-restore在Windows下,它也意味着除外 --no-Rconsole,从而防止Rconsole文件加载。
Details
详情----------Details----------
Note that there are two sorts of files used in startup: environment files which contain lists of environment variables to be set, and profile files which contain R code.
请注意,有两类在启动时使用的文件:环境文件,其中包含要设置环境变量的名单,和profile文件,其中包含R代码。
Lines in a site or user environment file should be either comment lines starting with #, or lines of the form <VAR>name</VAR>=<VAR>value</VAR>. The latter sets the environmental variable <VAR>name</VAR> to <VAR>value</VAR>, overriding an existing value. If <VAR>value</VAR> contains an expression of the form ${foo-bar}, the value is that of the environmental variable foo if that exists and is set to a non-empty value, otherwise bar. (If it is of the form ${foo}, the default is "".) This construction can be nested, so bar can be of the same form (as in ${foo-${bar-blah}}). Note that the braces are essential: for example $HOME will not be interpreted.
站点或用户环境文件中的线应该是无论是注释行开始,用#或形式<VAR>name</VAR>=<VAR>value</VAR>线。后者设置环境变量<VAR>name</VAR><VAR>value</VAR>,覆盖现有的值。如果<VAR>value</VAR>包含一个表达形式${foo-bar},该值是环境变量foo如果存在,并设置为一个非空值,否则bar 。 (如果它的形式是${foo},默认是""),这种结构可以嵌套,所以bar可以是相同的形式(如在${foo-${bar-blah}}) 。请注意,括号是必不可少的:例如$HOME不会被解释。
Leading and trailing white space in <VAR>value</VAR> are stripped. <VAR>value</VAR> is then processed in a similar way to a Unix shell: in particular the outermost level of (single or double) quotes is stripped, and backslashes are removed except inside quotes.
<VAR>value</VAR>被剥离的前导和尾随空白。 <VAR>value</VAR>然后在一个Unix shell类似的方式来处理:(单或双)引号的最外层,特别是被剥离,和的反斜杠除引号内删除。
On systems with sub-architectures (mainly Mac OS X and Windows), the files "Renviron.site" and "Rprofile.site" are looked for first in architecture-specific directories, e.g. "<VAR>R_HOME</VAR>/etc/i386/Renviron.site". And e.g. ".Renviron.i386" will be used in preference to ".Renviron".
子体系结构(主要的Mac OS X和Windows)的系统上,文件Renviron.site和Rprofile.site首先考虑在特定于体系结构的目录,例如“<VAR>R_HOME</VAR>/etc/i386/Renviron.site。和如“.Renviron.i386将.Renviron优先使用。
注意----------Note----------
The startup options are for Rgui, Rterm and R but not for Rcmd: attempting to use e.g. --vanilla with the latter will give a warning or error.
启动选项Rgui,Rterm和R而不是Rcmd:尝试使用如--vanilla后者将给予警告或错误。
Unix versions of R have a file "<VAR>R_HOME</VAR>/etc/Renviron" which is read very early in the start-up processing. It contains environment variables set by R in the configure process, and is not used on R for Windows.
R的Unix版本有文件<VAR>R_HOME</VAR>/etc/Renviron,这是读很早就在启动处理。它包含由R在配置过程中设置的环境变量,并没有在研发用于Windows。
R CMD check and R CMD build do not always read the standard startup files, but they do always read specific Renviron files such as "~/.R/check.Renviron", "~/.R/build.Renviron" or sub-architecture-specific versions.
R CMD check和R CMD build不要总是读标准的启动文件,但他们总是读具体Renviron如的~/.R/check.Renviron,~/.R/build.Renviron文件或子结构的特定版本。
If you want ~/.Renviron or ~/.Rprofile to be ignored by child R processes (such as those run by R CMD check and R CMD build), set the appropriate environment variable R_ENVIRON_USER or R_PROFILE_USER to (if possible, which it is not on Windows) "" or to the name of a non-existent file.
如果你想~/.Renviron或~/.Rprofile由的孩子ŕ进程(如那些运行R CMD check和R CMD build),设置适当的环境变量R_ENVIRON_USER忽略 R_PROFILE_USER(如果可能的话,它不是在Windows上)""或到一个不存在的文件的名称。
参见----------See Also----------
For the definition of the "home" directory on Windows see the "rw-FAQ" Q2.14. It can be found from a running R by Sys.getenv("R_USER").
Windows上的家目录定义为rw-FAQQ2.14。可以发现,从运行RSys.getenv("R_USER")。
.Last for final actions at the close of an R session. commandArgs for accessing the command line arguments.
.LastR会话结束的最后行动。 commandArgs访问命令行参数。
There are examples of using startup files to set defaults for graphics devices in the help for windows.options.
使用启动文件设置默认为图形设备在windows.options的帮助下,有例子。
An Introduction to R for more command-line options: those affecting memory management are covered in the help file for Memory.
更多的命令行选项到R简介:那些影响内存管理覆盖在记忆的帮助文件。
readRenviron to read ".Renviron" files.
readRenviron读.Renviron文件。
For profiling code, see Rprof.
有关分析代码,看到Rprof。
举例----------Examples----------
## Not run: [#无法运行:]
## Example ~/.Renviron on Unix[#例如〜/。Renviron在Unix]
R_LIBS=~/R/library
PAGER=/usr/local/bin/less
## Example .Renviron on Windows[#范例。Renviron在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范例(从R加利福尼亚支票)]
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.[以相反的顺序搜索路径。]
## Example of .Rprofile[#。Rprofile范例]
options(width=65, digits=5)
options(show.signif.stars=FALSE)
setHook(packageEvent("grDevices", "onLoad"),
function(...) grDevices::ps.options(horizontal=FALSE))
set.seed(1234)
.First <- function() cat("\n Welcome to R!\n\n")
.Last <- function() cat("\n Goodbye!\n\n")
## Example of Rprofile.site[#的Rprofile.site范例]
local({
# add MASS to the default packages, set a CRAN mirror[默认包的质量,树立了CRAN的镜子]
old <- getOption("defaultPackages"); r <- getOption("repos")
r["CRAN"] <- "http://my.local.cran"
options(defaultPackages = c(old, "MASS"), repos = r)
## (for Unix terminal users) set the width from COLUMNS if set[#(Unix终端的用户)设置列的宽度,如果设置]
cols <- Sys.getenv("COLUMNS")
if(nzchar(cols)) options(width = as.integer(cols))
# interactive sessions get a fortune cookie (needs fortunes package)[互动环节得到幸运饼干(需要财富包)]
if (interactive())
fortunes::fortune()
})
## if .Renviron contains[#如果。Renviron包含的]
FOOBAR="coo\bar"doh\ex"abc\"def'"
## then we get[#然后我们得到]
# > cat(Sys.getenv("FOOBAR"), "\n")[猫(Sys.getenv(“foobar”的),“\ N”)]
# coo\bardoh\exabc"def'[COO \ bardoh \ exabc“高清”]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|