example(utils)
example()所属R语言包:utils
Run an Examples Section from the Online Help
从联机帮助运行示例一节
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Run all the R code from the Examples part of R's online help topic topic with two possible exceptions, dontrun and dontshow, see "Details" below.
运行所有的R代码R的联机帮助主题的“示例”部分topic有两种可能的例外,dontrun和dontshow,看到下面的“详细资料”。
用法----------Usage----------
example(topic, package = NULL, lib.loc = NULL,
character.only = FALSE, give.lines = FALSE, local = FALSE,
echo = TRUE, verbose = getOption("verbose"),
setRNG = FALSE, ask = getOption("example.ask"),
prompt.prefix = abbreviate(topic, 6))
参数----------Arguments----------
参数:topic
name or literal character string: the online help topic the examples of which should be run.
应运行的名称或文字字符串:在线help主题,其中的例子。
参数:package
a character vector giving the package names to look into for the topic, or NULL (the default), when all packages on the search path are used.
字符向量,给包名称为主题,或NULL(默认)时,使用搜索路径上的所有包。
参数:lib.loc
a character vector of directory names of R libraries, or NULL. The default value of NULL corresponds to all libraries currently known. If the default is used, the loaded packages are searched before the libraries.
特征向量的研发图书馆的目录名,或NULL。默认值的NULL对应于目前已知的所有库。如果使用默认值,装包库前搜索。
参数:character.only
a logical indicating whether topic can be assumed to be a character string.
逻辑是否topic可以被假定为一个字符串。
参数:give.lines
logical: if true, the lines of the example source code are returned as a character vector.
逻辑:如果属实,例如源代码的行特征向量作为返回。
参数:local
logical: if TRUE evaluate locally, if FALSE evaluate in the workspace.
逻辑:如果TRUE评估本地,如果FALSE评估工作区中。
参数:echo
logical; if TRUE, show the R input when sourcing.
逻辑;如果TRUE,显示R输入时采购。
参数:verbose
logical; if TRUE, show even more when running example code.
逻辑;如果TRUE,显示更在运行示例代码。
参数:setRNG
logical or expression; if not FALSE, the random number generator state is saved, then initialized to a specified state, the example is run and the (saved) state is restored. setRNG = TRUE sets the same state as R CMD check does for running a package's examples. This is currently equivalent to setRNG = {RNGkind("default", "default"); set.seed(1)}.
逻辑或表达式,如果不是FALSE,随机数发生器的状态被保存,然后初始化为一个特定的状态,例如运行和恢复状态(保存)。 setRNG = TRUE设置为相同的状态R CMD check不运行包的例子。这是目前相当于setRNG = {RNGkind("default", "default"); set.seed(1)}。
参数:ask
logical (or "default") indicating if devAskNewPage(ask=TRUE) should be called before graphical output happens from the example code. The value "default" (the factory-fresh default) means to ask if echo == TRUE and the graphics device appears to be interactive. This parameter applies both to any currently opened device and to any devices opened by the example code.
逻辑(或"default")表示devAskNewPage(ask=TRUE)如果应该被称为图形输出前发生的例子代码。值"default"(新鲜出厂默认)意味着要问,如果echo == TRUE和图形设备似乎是互动的。此参数适用于任何当前打开的设备和示例代码打开任何设备。
参数:prompt.prefix
character; prefixes the prompt to be used if echo = TRUE.
字符;前缀提示要使用的,如果echo = TRUE。
Details
详情----------Details----------
If lib.loc is not specified, the packages are searched for amongst those already loaded, then in the libraries given by .libPaths(). If lib.loc is specified, packages are searched for only in the specified libraries, even if they are already loaded from another library. The search stops at the first package found that has help on the topic.
lib.loc如果不指定,包搜索其中包括那些已经加载,然后由.libPaths()库。如果lib.loc指定,包搜查只在指定库,即使他们已经从另一个库加载。停止搜索时发现,已帮助主题的第一个包。
An attempt is made to load the package before running the examples, but this will not replace a package loaded from another location.
试图加载之前运行的例子包,但不会取代从另一个位置加载的包。
If local = TRUE objects are not created in the workspace and so not available for examination after example completes: on the other hand they cannot overwrite objects of the same name in the workspace.
如果local = TRUE对象在工作区中没有创建等不审查后example完成:另一方面,他们在工作区中的相同名称的对象不能覆盖。
As detailed in the manual Writing R Extensions, the author of the help page can markup parts of the examples for two exception rules
详细的手册写R扩展,帮助页面作者可以标记零件的例子有两个例外规则
dontrun encloses code that should not be run.
dontrun封闭不应该运行的代码。
dontshow encloses code that is invisible on help pages, but will be run both by the package checking tools, and the example() function. This was previously
dontshow包围,是无形的帮助页面上的代码,但将运行检查工具包,example()功能。这是以前
值----------Value----------
The value of the last evaluated expression, unless give.lines is true, where a character vector is returned.
最后一个表达式的值,除非give.lines是真实的,在character向量返回。
作者(S)----------Author(s)----------
Martin Maechler and others
参见----------See Also----------
demo
demo
举例----------Examples----------
example(InsectSprays)
## force use of the standard package 'stats':[#强制使用的标准包统计:]
example("smooth", package="stats", lib.loc=.Library)
## set RNG *before* example as when R CMD check is run:[#设置RNG的*之前*当R加利福尼亚检查运行的例子:]
r1 <- example(quantile, setRNG = TRUE)
x1 <- rnorm(1)
u <- runif(1)
## identical random numbers[#相同的随机数]
r2 <- example(quantile, setRNG = TRUE)
x2 <- rnorm(1)
stopifnot(identical(r1, r2))
## but x1 and x2 differ since the RNG state from before example()[#但X1和X2的RNG的状态,从之前的例子不同,因为()]
## differs and is restored![#不同和恢复!]
x1; x2
## Exploring examples code:[#探索的例子代码:]
## How large are the examples of "lm...()" functions?[#如何大都是“LM ...()”函数的例子?]
lmex <- sapply(apropos("^lm", mode="function"),
example, character.only=TRUE, give.lines=TRUE)
sapply(lmex, length)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|