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

R语言 scriptests包 scriptests-package()函数中文帮助文档(中英文对照)

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

                                         Support for running transcript-style tests
                                         支持运行成绩单风格的测试

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

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

Support for running transcript-style tests
支持运行成绩单风格的测试


Details

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

Transcript-style tests are text files containing R commands and output, as though copied verbatim from an interactive R session.  The output in the transcript file must match the actual output from running the command for the test to pass (with some exceptions - see "Control over matching" below).  This testing framework is identical in concept to the standard .R/.Rout.save tests that are run by the R CMD check, but with some enhancements that are intended to make test development and maintanance faster, more convenient, and easier to automate:
成绩单风格的测试是文本文件,其中包含R命令和输出,虽然一字不差地复制,从一个交互式的R会话。记录文件中的输出必须符合实际的测试运行该命令的输出通过(有一些例外 - 匹配“下面的”控制过度)。该测试框架,在概念上是相同的标准.R/.Rout.saveR CMD check,但有一些改进,目的是为了让测试开发和maintanance更快,更方便,并且容易实现自动化:测试运行

Only the output file is needed - the inputs are parsed from the output file (i.e., .Rt file, which is analogous to an .Rout.save file)
只有输出文件 - 输入被解析的输出文件(即.Rt文件,该文件是类似的.Rout.save文件)

Test output matching is more lenient on white space differences, and more flexible in that some test output can be transformed by regular expressions prior to matching, or ignored entirely
测试输出匹配是较为宽松的在白色空间差异,在一些测试输出可以转化前的正则表达式匹配和更灵活的,或者被完全忽略

directives can specify whether a test-case output mismatch should be noted as an informational message, a warning, or an error (one or more errors results in R CMD check stopping with an indication of error after running all tests).  Unlike the standard tests in R CMD check, output mismatch detected by scriptests results in R CMD check stopping with an error.
指令可以指定是否应注意测试情况下的输出不匹配,信息性消息,警告,或错误(一个或多个错误的结果R CMD check错误的指示后停止运行所有测试)。与标准的测试,R CMD check,scriptests结果R CMD check停止错误检测到的输出失配。

A concise summary of warnings and errors is given at the end
在最后的警告和错误的简明摘要

Testing can continue after errors and can report multiple errors at the end, rather than stopping at the first error.
测试后,可以继续错误,并能报告多个错误的结束,而不是停在第一个错误。

To make it so that "R CMD check" will run transcript-style tests, do the following:
为了让这个“R CMD检查”将转录风格的测试运行,请执行以下操作:

Make sure the scriptests package is installed on your system
确保您的系统上安装了scriptests包

Put a file named "runtests.R" in the "tests" directory in your own package with the following contents:
把一个文件名为“runtests.R”中的“测试”自己的包目录中包含以下内容:

add transcript files ending in .Rt in the "tests" directory in your own package, e.g.:
添加成绩单结尾的文件。RT在自己的软件包,例如在“测试”目录:

add the line Suggests: scriptests to DESCRIPTION file. If there is an existing "Suggests:" line, just add scriptests to it.  (It's better to use the Suggests: than the Depends: fields, because packages listed in the depends field are loaded when the package is loaded for normal use, and the scriptests package is usually not needed for normal use of a package – the scriptests package will only be needed for testing.
Suggests: scriptests说明文件。如果有一个现成的“建议:”行,只需添加scriptests。 (这是更好地使用Suggests:比Depends:领域,因为包中列出的依赖领域的包时,加载正常使用,scriptests包通常是不需要的加载正常使用包 -  scriptests包,只需要进行测试。

At the end of testing, the file test-summary.txt will be left in the tests directory.  To be entirely sure that the tests were run, also check for the existence of test-summary.txt.
在测试结束,该文件test-summary.txt将留在tests目录。要完全确定测试运行,检查存在的test-summary.txt。

If any tests fail, the file test-summary.fail (a copy of test-summary.txt) will also be left in the tests directory – the existence of this file can be used in a programmatic check for whether all tests passed.
如果任何测试失败,文件test-summary.fail(副本test-summary.txt)也将被留在tests目录 - 这个文件存在,可以使用的纲领性检查是否所有测试都通过了。

Tests can be run interactively using the function runtests().  The function source.pkg() can be useful to quickly re-read the function definitions in a package during code development.  See the section "Running tests" in the documentation for runtests() for further details.
测试可以交互使用的功能runtests()。的功能source.pkg()可以迅速重新读取功能定义包中的代码开发过程中的。请参阅一节“运行测试”的文档中runtests()为进一步的细节。

Notes:
注:

All commands in the transcript file must be prefixed with command or continuation prompts, exactly as they appear in a transcript.
记录文件中的所有命令必须加上前缀命令或继续提示,正是因为他们出现在成绩单。

scriptests uses simple heuristics to identify commands, comments and output.  If the transcript cannot be separated into comments, commands and output by these heuristics (e.g., if a command prints out a line starting with the command prompt "> "), things will not work properly.
scriptests使用简单的启发式识别的命令,意见和输出。如果谈话内容不能分开的意见,命令和输出这些启发式(例如,如果一个命令打印出命令提示符“>”开始的行),将无法正常工作。

When running tests in a package, scriptests uses a heuristic to guess the package name and automatically include an appropriate library(package-being-tested) command before the tests.  If this heuristic fails, the functions from the package being tested may not be accessible.  If this problem occurs, it can be worked around by explicitly including a library(package-being-tested) command at the beginning of each .Rt file.
scriptests包中的运行测试时,采用了启发式猜测包的名称,并自动包含适当的library(package-being-tested)命令在测试前。如果这种启发式失败,从包中被测试的功能可能无法访问。如果出现此问题,可以通过显式包括一个library(package-being-tested)命令在每个.Rt文件的开头来解决。

To have tests continue to run after encountering an error, put the command options(error=function() NULL) at the beginning of the transcript file.  This will cause the non-interactive R session that runs the commands in the scripts to continue after an error, instead of stopping, which is the default behavior for non-interactive R.
为了测试继续运行,当遇到一个错误之后,命令options(error=function() NULL)的记录文件开始的。这将导致非交互式运行的命令脚本中的错误后,继续的R会话,而不是停止,这是默认行为的非交互式R.

Control over matching
控制权匹配

Actual output is matched to desired output extracted from the transcript file in a line-by-line fashion.  If text is wrapped differently over multiple lines, the tests will fail (unless ignore-linebreaks is used). Different output width can easily happen if options("width") was different in the session that generated the desired output. Before trying to match, scriptests converts all white-space to single white-space, unless a control line specifies otherwise.
实际输出相匹配的记录文件中提取所需的输出中的行由行时尚。如果文本是多行,包裹着不同的测试将失败(除非ignore-linebreaks)。不同的输出宽度可以很容易地发生,如果options("width")是不同的会话生成所需的输出。 scriptests在尝试匹配之前,将所有空白单一的白色空间,控制线,除非另有规定的除外。

The following control lines can be present in the transcript after a command and before its output:
以下控制线可以是本在转录后的命令之前,它的输出:




#@ignore-output Ignore the output of this particular command – a test with this control line will always pass (unless it causes an R error, and options(error=function()
#@忽略输出忽略这个特殊的命令的输出 - 一个测试,该控制线会始终通过(除非它使得一个R错误,和<code>的选项(错误=函数()




#@gsub(pattern, replacement, WHAT) where WHAT is target, actual or both (without quotes). Make a global substitution of replacement text for pattern text (a regular expression) in the desired
#@ GSUB(图案,更换,WHAT)WHAT是target,actual或both(不带引号)。 replacement文本pattern文本(正则表达式)所需的全局替换

E.g.,
例如,




#@warn-only: OPTIONAL-TEXT A mismatch is treated as an
#@只警告:OPTIONAL-TEXT被视为不匹配




#@info-only: OPTIONAL-TEXT A mismatch is treated as an
#@信息:OPTIONAL-TEXT被视为不匹配




#@diff-msg: OPTIONAL-TEXT Output OPTIONAL-TEXT if the
#@差异味精:如果可选文本输出可选-TEXT




#@keep-whitespace Leave the whitespace as-is in the
#@保持空白留下的空白,是在




#@ignore-linebreaks Target and actual will match even
#@忽略换行符的目标和实际甚至将匹配

The tests directory can also contain a CONFIG file, which can specify the functions to call for testing.  The defaults are equivalent to the following lines in the CONFIG file:
tests目录也包含CONFIG文件,可以指定调用的函数进行测试。默认值是相当于CONFIG文件中的以下行:


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

The standard Emacs ESS functions for writing out ".Rt" files will strip trailing white space, which can result in many unimportant mismatches when using ediff to compare ".Rt" and ".Rout" files (e.g., because an R transcript will have "> " for empty command lines). Also, ".Rt" files are read-only by default, and the return key is bound to a command to send the current line to an R interpreter.  It is more convenient if all these special behaviors are turned off. Put the following in your .emacs file to tell ESS not mess with ".Rt" files prior to saving them:
标准的Emacs ESS写出".Rt"文件的功能,将去掉尾随空白,这可能会导致在许多不重要的不匹配时,使用ediff比较".Rt"和".Rout"文件(如,因为一个R的成绩单将有"> "空命令行)。此外,".Rt"文件是只读的,默认情况下,和返回键被绑定到当前行的命令发送的R解释。如果所有这些特殊行为被关断,这是更方便。告诉ESS不是好惹的.emacs文件之前,将它们保存在你的".Rt"文件,把下面的:


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



Tony Plate &lt;tplate@acm.org&gt;


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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-30 00:48 , Processed in 0.024799 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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