找回密码
 注册
查看: 12341|回复: 0

R语言:source()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-17 09:55:29 | 显示全部楼层 |阅读模式
source(base)
source()所属R语言包:base

                                        Read R Code from a File or a Connection
                                         读取一个文件或一个连接R代码

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

source causes R to accept its input from the named file or URL or connection.  Input is read and parsed from that file until the end of the file is reached, then the parsed expressions are evaluated sequentially in the chosen environment.
sourceR来接受从指定的文件或URL或连接的输入。输入读取和parsed从该文件,直至到达文件末尾,然后解析表达式在选定的环境评估顺序。


用法----------Usage----------


source(file, local = FALSE, echo = verbose, print.eval = echo,
       verbose = getOption("verbose"),
       prompt.echo = getOption("prompt"),
       max.deparse.length = 150, chdir = FALSE,
       encoding = getOption("encoding"),
       continue.echo = getOption("continue"),
       skip.echo = 0, keep.source = getOption("keep.source"))



参数----------Arguments----------

参数:file
a connection or a character string giving the pathname of the file or URL to read from.  "" indicates the connection stdin().
一个连接或一个字符串,文件或URL路径读取。 ""表示连接stdin()。


参数:local
TRUE, FALSE or an environment, determining where the parsed expressions are evaluated.  TRUE corresponds to the user's workspace (the global environment) and FALSE to the environment from source is called.
TRUE,FALSE或环境,确定评估的解析表达式。 TRUE对应于用户的工作区(全球环境)和FALSEsource被称为环境。


参数:echo
logical; if TRUE, each expression is printed after parsing, before evaluation.
逻辑;如果TRUE,每个表达式解析印刷后评价前。


参数:print.eval
logical; if TRUE, the result of eval(i) is printed for each expression i; defaults to the value of echo.
逻辑默认值TRUE如果eval(i),i每个表达式echo印。


参数:verbose
if TRUE, more diagnostics (than just echo = TRUE) are printed during parsing and evaluation of input, including extra info for each expression.
如果TRUE,更多的诊断(比echo = TRUE)是印刷过程中的输入,包括每个表达的额外的信息的分析和评价。


参数:prompt.echo
character; gives the prompt to be used if echo = TRUE.
字符;提供要使用的提示,如果echo = TRUE。


参数:max.deparse.length
integer; is used only if echo is TRUE and gives the maximal number of characters output for the deparse of a single expression.
整数;仅用于echo如果是TRUE“给出了一个单一的表达deparse输出的字符的最大数量。


参数:chdir
logical; if TRUE and file is a pathname, the R working directory is temporarily changed to the directory containing file for evaluating.
逻辑;如果TRUE和file是一个路径,在R的工作目录临时更改到该目录包含file评估。


参数:encoding
character vector.  The encoding(s) to be assumed when file is a character string: see file.  A possible value is "unknown" when the encoding is guessed: see the "Encodings" section.
特征向量。时须承担的编码(S)file是一个字符串:“看到file。一个可能的值是"unknown"猜测时编码:看到“编码”一节。


参数:continue.echo
character; gives the prompt to use on continuation lines if echo = TRUE.
字符;给出提示使用续行,如果echo = TRUE。


参数:skip.echo
integer; how many comment lines at the start of the file to skip if echo = TRUE.
整数;多少在文件开头的注释行则跳过echo = TRUE。


参数:keep.source
logical: should the source formatting be retained when echoing expressions, if possible?
逻辑:应保留源格式呼应表达式时,如果可能的话吗?


Details

详情----------Details----------

Note that running code via source differs in a few respects from entering it at the R command line.  Since expressions are not executed at the top level, auto-printing is not done.  So you will need to include explicit print calls for things you want to be printed (and remember that this includes plotting by lattice, FAQ Q7.22).  Since the complete file is parsed before any of it is run, syntax errors result in none of the code being run.  If an error occurs in running a syntactically correct script, anything assigned into the workspace by code that has been run will be kept (just as from the command line), but diagnostic information such as traceback() will contain additional calls to eval.with.vis, an undocumented internal function.
请注意,运行通过source代码的在几个方面不同于在R命令行输入。由于表达式是不是在顶层执行,自动打印不这样做。所以,你需要包括明确print你想要的东西要打印通话(记得,这包括策划lattice,帮助Q7.22)。由于完整的文件被解析之前,它的任何正在运行,正在运行的代码没有语法错误的结果。如果在运行一个语法正确的脚本发生错误,将被分配到工作区的代码已经运行的任何保留(就像在命令行),但诊断信息,如traceback()将包含额外的调用 eval.with.vis,无证的内部功能。

All versions of R accept input from a connection with end of line marked by LF (as used on Unix), CRLF (as used on DOS/Windows) or CR (as used on classic Mac OS) and map this to newline.  The final line can be incomplete, that is missing the final end-of-line marker.
R的所有版本都接受输入行结束(在Unix上使用)由LF标志着连接,CRLF(DOS / Windows的使用)或CR(如经典的Mac OS),并将其映射到换行符。最后一行可以是不完整的,缺少的最终行标记。

If keep.source is true (the default in interactive use), the source of functions is kept so they can be listed exactly as input.
keep.source如果是真实的(交互使用的默认),保持他们完全可以上市作为输入源功能。

Unlike input from a console, lines in the file or on a connection can contain an unlimited number of characters.
从控制台输入不同,在文件中或连接线可以包含无限数量的字符。

When skip.echo > 0, that many comment lines at the start of the file will not be echoed.  This does not affect the execution of the code at all.  If there are executable lines within the first skip.echo lines, echoing will start with the first of them.
当skip.echo > 0,在文件开头的注释行不会被回荡。这并不影响在所有的代码的执行。如果有第一skip.echo行内的可执行线,呼应将开始他们的第一。

If echo is true and a deparsed expression exceeds max.deparse.length, that many characters are output followed by  .... [TRUNCATED] .  
如果echo是真正的和1 deparsed表达超过max.deparse.length,许多字符是由 .... [TRUNCATED] 输出。


编码----------Encodings----------

By default the input is read and parsed in  the current encoding of the R session.  This is usually what it required, but occasionally re-encoding is needed, e.g. if a file from a UTF-8-using system is to be read on Windows (or vice versa).
默认情况下,输入在R会话的当前编码读取和解析。这通常是需要的,但偶尔需要重新编码,例如:如果一个文件是UTF-8使用的系统是在Windows(或反之亦然)读取。

The rest of this paragraph applies if file is an actual filename or URL (and not "" nor a connection).  If encoding = "unknown", an attempt is made to guess the encoding: the result of localeToCharset() is used as a guide.  If encoding has two or more elements, they are tried in turn until the file/URL can be read without error in the trial encoding.  If an actual encoding is specified (rather than the default or "unknown") in a Latin-1 or UTF-8 locale then character strings in the result will be translated to the current encoding and marked as such (see Encoding).
本段其余部分适用于file如果是一个实际的文件名或URL(而不是""也不是连接)。如果encoding = "unknown",试图猜测编码:localeToCharset()为指导的结果。如果encoding有两个或两个以上的元素,它们依次尝试,直到没有在审判编码错误的文件/ URL可以读。如果实际encoding指定(而不是默认或"unknown")中的Latin-1或UTF-8语言环境,然后在结果字符串将被转换为当前的编码和标记等(看到Encoding)。

If file is a connection (including one specified by "", it is not possible to re-encode the input inside source, and so the encoding argument is just used to mark character strings in the parsed input in Latin-1 and UTF-8 locales: see parse.
如果file是一个连接(包括指定的一个由"",这是不可能的重新编码,输入内source,所以encoding参数只是用来解析Latin-1的输入和UTF-8语言环境标志字符串:parse。


参考文献----------References----------

The New S Language. Wadsworth & Brooks/Cole.

参见----------See Also----------

demo which uses source; eval, parse and scan; options("keep.source").
demo使用source;eval,parse和scan;options("keep.source")。

sys.source which is a streamlined version to source a file into an environment.
sys.source这是一个精简版本的源文件到一个环境。

"The R Language Definition" for a discussion of source directives.  
“R语言定义为源指令的讨论。


举例----------Examples----------


## If you want to source() a bunch of files, something like[#如果你要源()一堆文件,类似]
## the following may be useful:[#以下可能是有用的:]
sourceDir <- function(path, trace = TRUE, ...) {
    for (nm in list.files(path, pattern = "\\.[RrSsQq]$")) {
       if(trace) cat(nm,":")           
       source(file.path(path, nm), ...)
       if(trace) cat("\n")
    }
}

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-23 05:56 , Processed in 0.021755 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表