evalSource(methods)
evalSource()所属R语言包:methods
Use Function Definitions from a Source File without Reinstalling a Package
使用函数定义,而无需重新安装包从一个源文件
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Definitions of functions and/or methods from a source file are inserted into a package, using the trace mechanism. Typically, this allows testing or debugging modified versions of a few functions without reinstalling a large package.
插入包从源文件中的职能和/或方法的定义,使用trace机制。通常情况下,这使得测试和调试,而无需重新安装了一大包的几个功能的修改后的版本。
用法----------Usage----------
evalSource(source, package = "", lock = TRUE, cache = FALSE)
insertSource(source, package = "", functions = , methods = ,
force = )
参数----------Arguments----------
参数:source
A file to be parsed and evaluated by evalSource to find the new function and method definitions. The argument to insertSource can be an object of class "sourceEnvironment" returned from a previous call to evalSource If a file name is passed to insertSource it calls evalSource to obtain the corresponding object. See the section on the class for details.
要解析的文件和评估,以寻找新的功能和方法定义evalSource。 insertSource参数可以是一个对象类"sourceEnvironment"从以前调用返回evalSource如果一个文件名称被传递insertSource的,它调用evalSource获得相应的对象。看到细节类的部分。
参数:package
Optionally, the name of the package to which the new code corresponds and into which it will be inserted. Although the computations will attempt to infer the package if it is omitted, the safe approach is to supply it. In the case of a package that is not attached to the search list, the package name must be supplied.
可选包的名称,新的代码对应,它将被插入。虽然计算将尝试推断出包,如果它被省略,安全的做法是提供。在未连接到搜索列表中的一个包的情况下,包的名称必须提供。
参数:functions, methods
Optionally, the character-string names of the functions to be used in the insertion. Names supplied in the functions argument are expected to be defined as functions in the source. For names supplied in the methods argument, a table of methods is expected (as generated by calls to setMethod, see the details section); methods from this table will be inserted by insertSource. In both cases, the revised function or method is inserted only if it differs from the version in the corresponding package as loaded. If what is omitted, the results of evaluating the source file will be compared to the contents of the package (see the details section).
可选功能字符的字符串名称要使用插入。预计在functions参数提供的名称被定义为源的功能。在methods参数提供的名称,一个表的方法,预计(setMethod,看到细节部分的调用生成)本表中的方法将插入insertSource。在这两种情况下,修改后的函数或方法插入,只有当它作为加载相应的软件包版本不同。如果what省略,将源文件的评估结果相比,包(见细节部分)的内容。
参数:lock, cache
Optional arguments to control the actions taken by evalSource. If lock is TRUE, the environment in the object returned will be locked, and so will all its bindings. If cache is FALSE, the normal caching of method and class definitions will be suppressed during evaluation of the source file. The default settings are generally recommended, the lock to support the credibility of the object returned as a snapshot of the source file, and the second so that method definitions can be inserted later by insertSource using the trace mechanism.
可选参数到控制evalSource采取的行动。 lock如果是TRUE,在返回对象的环境将被锁定,所以将其所有的绑定。如果cache是FALSE,正常的方法和类的定义,高速缓存将被压制在评价档案source。 lock支持对象的信誉返回的默认设置一般都建议,作为快照源文件,第二,这样的方法定义后可以插入insertSource使用的跟踪机制。
参数:force
If FALSE, only functions currently in the environment will be redefined, using trace. If TRUE, other objects/functions will be simply assigned. By default, TRUE if neither the functions nor the methods argument is supplied.
如果FALSE,只有功能在目前的环境将被重新定义,使用trace。如果TRUE,其他对象/函数将被简单地分配。默认情况下,TRUE如果没有functions还是methods参数提供。
Details
详情----------Details----------
The source file is parsed and evaluated, suppressing by default the actual caching of method and class definitions contained in it, so that functions and methods can be tested out in a reversible way. The result, if all goes well, is an environment containing the assigned objects and metadata corresponding to method and class definitions in the source file.
source文件进行分析和评估,默认情况下,方法和类的定义,它包含的实际缓存,使函数和方法,可以测试出一个可逆的方式抑制。结果,如果一切顺利,是一个环境,分配对象在源文件的方法和类的定义和相应的元数据。
From this environment, the objects are inserted into the package, into its namespace if it has one, for use during the current session or until reverting to the original version by a call to untrace. The insertion is done by calls to the internal version of trace, to make reversion possible.
从这种环境中,对象被插入到包,将其命名空间,如果它有一个在本届会议期间使用,或直至恢复到原始版本调用untrace由。通过插入调用trace,使回归可能的内部版本。
Because the trace mechanism is used, only function-type objects will be inserted, functions themselves or S4 methods.
因为用于跟踪机制,只有功能类型的对象将被插入,函数本身或S4方法。
When the functions and methods arguments are both omitted, insertSource selects all suitable objects from the result of evaluating the source file.
当functions和methods参数都省略,insertSource选择所有合适的对象,从评估source文件的结果。
In all cases, only objects in the source file that differ from the corresponding objects in the package are inserted. The definition of “differ” is that either the argument list (including default expressions) or the body of the function is not identical. Note that in the case of a method, there need be no specific method for the corresponding signature in the package: the comparison is made to the method that would be selected for that signature.
在所有情况下,从包中的相应对象的不同源文件中的唯一对象插入。 “不同”的定义是参数列表(包括默认表达式)或身体的功能是不完全相同的。请注意,在方法的情况下,需要有相应的签名包中的具体方法是没有比较的方法,将选择该签名。
Nothing in the computation requires that the source file supplied be the same file as in the original package source, although that case is both likely and sensible if one is revising the package. Nothing in the computations compares source files: the objects generated by evaluating source are compared as objects to the content of the package.
计算中的任何要求,所提供的源文件相同的文件,如在原包源,虽然这种情况下,可能是明智的,如果一个正在修订包。没有什么比在计算源文件:通过评估产生的对象source包的内容为对象进行比较。
值----------Value----------
An object from class "sourceEnvironment", a subclass of "environment" (see the section on the class) The environment contains the versions of all object resulting from evaluation of the source file. The class also has slots for the time of creation, the source file and the package name. Future extensions may use these objects for versioning or other code tools.
从类"sourceEnvironment",一个子类的对象:"environment"(见类部分)环境包含所有从源文件的评价对象的版本。类也有插槽的创作时间,源文件和包名称。未来的扩展版本或其他代码工具可以使用这些对象。
The object returned can be used in debugging (see the section on that topic) or as the source argument in a future call to insertSource. If only some of the revised functions were inserted in the first call, others can be inserted in a later call without re-evaluating the source file, by supplying the environment and optionally suitable functions and/or methods argument.
返回的对象,可用于调试(见该主题的部分)或source在未来的呼叫参数insertSource。如果只有部分修订后的功能被插入在第一次调用,其他人可以在以后的调用插入的源文件不重新评估,提供环境,可选择合适的functions和/或methods参数。
调试----------Debugging----------
Once a function or method has been inserted into a package by insertSource, it can be studied by the standard debugging tools; for example, debug or the various versions of trace.
一旦一个函数或方法已插入到一个包insertSource,它可以研究的标准调试工具;例如,debugtrace或各种版本。
Calls to trace should take the extra argument edit = env, where env is the value returned by the call to evalSource. The trace mechanism has been used to install the revised version from the source file, and supplying the argument ensures that it is this version, not the original, that will be traced. See the example below.
调用trace应该采取额外的参数edit = env,其中env是由evalSource调用的返回值。跟踪机制,已被用于从源文件安装修订版,并提供参数,确保它是这个版本,而不是原来的,将追溯到。请看下面的例子。
To turn tracing off, but retain the source version, use trace(x, edit = env) as in the example. To return to the original version from the package, use untrace(x).
关闭跟踪,但保留源版本,使用的例子trace(x, edit = env)。从包返回到原来的版本,使用untrace(x)。
类“sourceEnvironment”----------Class "sourceEnvironment"----------
Objects from this class can be treated as environments, to extract the version of functions and methods generated by evalSource. The objects also have the following slots:
从这个类的对象可以被视为环境中,提取的版本的功能和生成的方法evalSource。对象也有以下插槽:
packageName: The character-string name of the package to which the source code corresponds.
packageName:包的源代码对应的字符的字符串名称。
dateCreated: The date and time that the source file was evaluated (usually from a call to Sys.time).
dateCreated:评估源文件(通常是从一个调用Sys.time)的日期和时间。
sourceFile: The character-string name of the source file used.
sourceFile:使用源文件的字符的字符串名称。
Note that using the environment does not change the dateCreated.
请注意,使用环境不改变dateCreated。
参见----------See Also----------
trace for the underlying mechanism, and also for the edit= argument that can be used for somewhat similar purposes; that function and also debug and setBreakpoint, for techniques more oriented to traditional debugging styles. The present function is directly intended for the case that one is modifying some of the source for an existing package, although it can be used as well by inserting debugging code in the source (more useful if the debugging involved is non-trivial). As noted in the details section, the source file need not be the same one in the original package source.
trace为基础的机制,也为edit=参数,可以有点类似用途使用,功能也debug和setBreakpoint更为导向,以技术,传统的调试风格。目前的功能是直接目的的情况下,一个是修改现有包的源,但它也可以作为源(更多有用的,如果涉及的调试是不平凡的)中插入调试代码。在细节部分所指出的,源文件不一定是在同一个原包源。
举例----------Examples----------
## Not run: [#无法运行:]
## Suppose package P0 has a source file "all.R"[#假设P0包源文件“all.R”]
## First, evaluate the source, and from it[#首先,评估源,并从它]
## insert the revised version of methods for summary()[#插入方法摘要(修订版)]
env <- insertSource("./P0/R/all.R", package = "P0",
methods = "summary")
## now test one of the methods, tracing the version from the source[#现在测试的方法之一,从源头上跟踪版本]
trace("summary", signature = "myMat", browser, edit = env)
## After testing, remove the browser() call but keep the source[#测试后,删除浏览器()调用,但保留源]
trace("summary", signature = "myMat", edit = env)
## Now insert all the (other) revised functions and methods[#现在插入所有的(其他)修改函数和方法]
## without re-evaluating the source file.[#没有重新评估的源文件。]
## The package name is included in the object env.[#包名包含在包膜对象。]
insertSource(env)
## End(Not run)[#结束(不运行)]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|