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

R语言 scriptests包 source.pkg()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-9-29 23:06:24 | 显示全部楼层 |阅读模式
source.pkg(scriptests)
source.pkg()所属R语言包:scriptests

                                         Quickly load code and data of a package
                                         快速加载的代码和数据包

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

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

source() all of the source files and data files in a package into a specially created environment.  It also loads DLLs if requested, and if those DLLs can be found.   This function is intended for use in code development, in situations where code from a package can be tested without worrying about imports, namespaces, etc.
source()所有的源文件和数据文件包到一个专门设立的环境。它还加载的DLL如果要求的话,可以发现,如果这些DLL。此功能是用于在代码开发,代码包的情况下,可以进行测试,无需担心进口,命名空间等


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


source.pkg(pkg.dir = getOption("scriptests.pkg.dir", "pkg"),
           pattern = ".*",
           suffix = "\\.R$",
           dlls = c("no", "check", "build", "src"),
           pos = NA, all = FALSE,
           reset.function.envirs=TRUE,
           path=getOption("scriptests.pkg.path", default=getwd()))



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

参数:pkg.dir
The directory where the package code lives.  This is remembered and the same value used as the default in subsequent invocations. This can be different from the package name, which is read from <pkg.dir>/DESCRIPTION.
目录下的包代码的生活。这被记下并在以后的调用默认使用的值相同。这可能是不同的包的名称,读取<pkg.dir>/DESCRIPTION。


参数:pattern
A regular expression specifying the R files to source  
正则表达式指定的R文件源


参数:suffix
The suffix for the R code files.  Files are sourced only if they match both pattern and suffix.  
R代码文件的后缀。源文件,如果它们匹配两个pattern和suffix。


参数:dlls
Indicates where to look for DLLs or shared-objects:   
表示在哪里寻找DLL或共享对象:

no: don't load any DLLs  
no:不加载任何DLL

check: look in <pkg.dir>.Rcheck/<pkg.name>/libs and  <pkg.name>.Rcheck/<pkg.name>/libs  
check:<pkg.dir>.Rcheck/<pkg.name>/libs和<pkg.name>.Rcheck/<pkg.name>/libs

build: look in the directory build (can be created with R CMD INSTALL -l build <package-tarball>)  
build:看目录中的build(可创建R CMD INSTALL -l build <package-tarball>)


参数:pos
Which environment on the search path to source R code into  
环境上的搜索路径源R代码


参数:all
If TRUE, all files matching the pattern and suffix are sourced, if FALSE, only files that have changed since last sourced are sourced again.  
如果TRUE,模式和后缀匹配的所有文件的来源,如果FALSE,只有已更改的文件自去年采购的货源再次。


参数:reset.function.envirs
If TRUE the environments on all functions sourced are set to the global environment.  See NOTE below for explanation.
如果TRUE来源的所有功能设置为全球环境的环境。注意下面的解释。


参数:path
The file system path to the directory in which the package is located.  The initial default for path is the current directory.  By default, R source files are looked for in the directory found by appending pkg.dir to path, i.e. <path>/<pkg.dir>/R/*.R. If path contains the string $PKG, pkg.dir is substituted for $PKG instead of being appended to path.  path is remembered and the same value used as the default in subsequent invocations.  
包所在的目录中的文件系统路径。 path的初始默认是当前目录。默认情况下,R查找源文件的目录中发现的附加pkg.dirpath,即<path>/<pkg.dir>/R/*.R。如果path包含字符串$PKG,pkg.dir代替$PKG,而不是被追加到path的。 path被记下并在以后的调用中作为默认使用的值相同。


Details

详细信息----------Details----------

The package directory (pkg.dir) does not need to be the same as the package name.  The package name (refered to here as pkg.name) is found by reading the DESCRIPTION file.
包目录(pkg.dir)并不需要是相同的包名。包的名称(在这里作为参考,以pkg.name)通过阅读DESCRIPTION文件。

All the objects created by the .R files are created in a special environment named pkgcode:<pkg.name>.  If this environment does not already exist, it will be created and attached to the search path in position pos.  If it does exist, no attempt is made to clean it before sourcing the .R files.  All functions and objects defined in the .R files will be visible &ndash; namespaces are not implemented.
一个特殊的环境中创建名为.Rpkgcode:<pkg.name>文件中创建的所有对象。如果这个环境已经不存在,它会被创建和附加的搜索路径在位置pos。如果它确实存在,没有试图来清洁它,之前采购.R文件。所有的功能和对象定义在.R文件将是可见的 - 不落实的命名空间。

The easiest way to use this function is when the working directory of the R session is the directory where each package lives, i.e., the R code for package mypackage will be in the directory ./mypackage/R (relative to the working directory of the R session.)  However, if the package directory is located elsewhere, supply it as path=, and this will be remembered for future invocations of source.pkg().
使用此功能的最简单的方法是,当R会话的工作目录的目录,其中每个包的生命,即R代码包mypackage将目录中的./mypackage/R(相对于工作目录的R会话。)但是,如果包的目录位于其他位置,提供path=,这将记住将来调用的source.pkg()。

This function does not attempt to replicate all the actions involved in creating and attaching a package.  It does the following:
此功能不会试图复制所有的行动参与创建和安装包。执行以下操作:

creates a environment named pkgcode:<pkg.name> where <pkg.name> is the name of the package (if it doesn't already exist)
创建一个环境命名pkgcode:<pkg.name><pkg.name>的名字是包(如果它已经不存在)

looks for a Depends line in the DESCRIPTION file and loads specified packages
寻找一个Depends行DESCRIPTION文件,并加载指定的包

looks for .R files in the R subdirectory of the package, and, as appropriate, the R/windows or R/unix subdirectories, and uses sys.source() to read these into the pkgcode:<pkg.name> environment.  If there is a Collate field in the DESCRIPTION files, this is used to sort the files before sourcing them.
寻找.RR子目录中的包文件,及(如适用),R/windows或R/unix子目录,并使用sys.source()阅读到这些pkgcode:<pkg.name>环境。如果有一个Collate领域的DESCRIPTION文件,这是用来对文件进行排序前采购。

looks for .Rdata and .rda files in the data subdirectory, and uses load() to read these into the pkgcode:<pkg.name> environment
寻找.Rdata和.rdadata子目录中的文件,并使用load()到pkgcode:<pkg.name>环境中阅读这些

if dlls=="check" (not the default), source.pkg() looks for DLLs (SO files under Unix) in the directory left by R   CMD check <pkg.dir>, i.e., in <pkg.dir>.Rcheck/<pkg.name>/libs or <pkg.name>.Rcheck/<pkg.name>/libs, and uses dyn.load() to load these DLLs.  If the DLL was already loaded (as indicated by getLoadedDLLs()), dyn.unload() is called first.  Be aware that unloading and reloading a DLL is not a reliable operation under many OS's, and even when the call completes without apparent error, the R session can be corrupted.
如果dlls=="check"(而不是默认值),source.pkg()看起来的DLL(SO Unix下的文件)的目录中留下的R   CMD check <pkg.dir>,即,在<pkg.dir>.Rcheck/<pkg.name>/libs或<pkg.name>.Rcheck/<pkg.name>/libs ,并使用dyn.load()加载这些DLL。如果已经加载的DLL(表示getLoadedDLLs()),dyn.unload()被称为第一。请注意,卸载和重新加载DLL是不可靠的操作在很多操作系统的,而且,即使在调用完成时没有明显的错误,R会话可能会被破坏。


值----------Value----------

A list of the problems encountered when sourcing the files.
列表采购文件时遇到的问题。


副作用----------Side effects----------

An environment is created and attached to the search path (or if it already exists, it is modified.) A variable named scriptests.pkg.dir is set in the global environment to the directory of the package whose code was sourced.
的环境中创建并附加到搜索路径(或如果它已经存在,它将被修改。)在全球环境中的变量名为scriptests.pkg.dir的设置的目录是源代码包的。


注意----------Note----------

If reset.function.envirs=FALSE is supplied, the environments on the functions sourced will be the environment where they live on the search path.  Functions with their environment set like this will not be able to see objects in the global environment or in any environment earlier on the search path.  The default behavior of setting their environment to be the global environment produces behavior that is more similar to when the functions are sourced directly into the global environment.
如果reset.function.envirs=FALSE提供的功能来源,环境是环境,让他们住在搜索路径。这样的环境设置的功能将无法看到的物体在全球环境中,或在任何环境上的搜索路径。他们的环境是全球环境产生的默认行为是比较类似的功能时,可直接进入全球环境的行为。


(作者)----------Author(s)----------


Tony Plate <a href="mailto:tplate@acm.org">tplate@acm.org</a>



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

http://n4.nabble.com/Lightweight-package-idea-td924000.html#a924000
http://gist.github.com/180883, reads DESCRIPTION, loads dependencies, respects collation order

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

runtests() shares the options() variables scriptests.pkg.dir and scriptests.pkg.path that provide defaults for the pkg.dir and path arguments.
runtests()股份options()变量scriptests.pkg.dir和scriptests.pkg.path提供pkg.dir和path参数的默认值。

scriptests-package gives and overview of the package.
scriptests包提供和介绍的包。


实例----------Examples----------


## Not run: [#不运行:]
# sourcing the code in a package stored in &lt;mypackage&gt;/{DESCRIPTION,R,man,tests}:[包中的源代码存储在<mypackage> / {DESCRIPTION,R,人,测试}]
source.pkg("<mypackage>")
# sourcing the code in a package stored in path/to/dir/&lt;mypackage&gt;/{DESCRIPTION,R,man,tests}:[源代码包中的路径存储在/ /目录/ <mypackage>的/ {DESCRIPTION,R,人,测试}:]
source.pkg("<mypackage>", path="path/to/dir")
# sourcing the code in a package stored in pkg/{DESCRIPTION,R,man,tests}:[包中的源代码存储在pkg / {DESCRIPTION,R,男人,测试}]
# where "pkg" is unrelated to the name of the pacakage[是的名称的pacakage无关其中“的pkg”]
source.pkg("pkg", path="path/to/dir")
# sourcing the code in a package stored in &lt;mypackage&gt;/pkg/{DESCRIPTION,R,man,tests}:[包中的源代码存储在<mypackage> /封装/ {DESCRIPTION,R,人,测试}]
source.pkg("<mypackage>", path="$PKG/pkg")

## End(Not run)[#(不执行)]

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-29 22:42 , Processed in 0.019567 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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