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

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

[复制链接]
发表于 2012-2-16 21:04:58 | 显示全部楼层 |阅读模式
TclInterface(tcltk)
TclInterface()所属R语言包:tcltk

                                        Low-level Tcl/Tk Interface
                                         低层次的Tcl / Tk接口

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

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

These functions and variables provide the basic glue between R and the Tcl interpreter and Tk GUI toolkit. Tk windows may be represented via R objects. Tcl variables can be accessed via objects of class tclVar and the C level interface to Tcl objects is accessed via objects of class tclObj.
这些函数和变量之间的R和Tcl解释和Tk的GUI工具包提供的基本胶水。 Tk的窗口可以通过R对象代表。 Tcl变量可以通过类对象访问tclVar和C级接口Tcl对象的访问通过类对象tclObj。


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


.Tcl(...)
.Tcl.objv(objv)
.Tcl.args(...)
.Tcl.args.objv(...)
.Tcl.callback(...)
.Tk.ID(win)
.Tk.newwin(ID)
.Tk.subwin(parent)
.TkRoot

tkdestroy(win)
is.tkwin(x)

tclvalue(x)
tclvalue(x) <- value

tclVar(init="")
## S3 method for class 'tclVar'
as.character(x, ...)
## S3 method for class 'tclVar'
tclvalue(x)
## S3 replacement method for class 'tclVar'
tclvalue(x) <- value

tclArray()
## S3 method for class 'tclArray'
x[[...]]
## S3 replacement method for class 'tclArray'
x[[...]] <- value
## S3 method for class 'tclArray'
x$i
## S3 replacement method for class 'tclArray'
x$i <- value

## S3 method for class 'tclArray'
names(x)
## S3 method for class 'tclArray'
length(x)

tclObj(x)
tclObj(x) <- value
## S3 method for class 'tclVar'
tclObj(x)
## S3 replacement method for class 'tclVar'
tclObj(x) <- value

as.tclObj(x, drop=FALSE)
is.tclObj(x)

## S3 method for class 'tclObj'
as.character(x, ...)
## S3 method for class 'tclObj'
as.integer(x, ...)
## S3 method for class 'tclObj'
as.double(x, ...)
## S3 method for class 'tclObj'
as.logical(x, ...)
## S3 method for class 'tclObj'
as.raw(x, ...)
## S3 method for class 'tclObj'
tclvalue(x)

## Default S3 method:[默认方法]
tclvalue(x)
## Default S3 replacement method:
tclvalue(x) <- value


addTclPath(path = ".")
tclRequire(package, warn = TRUE)



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

参数:objv
a named vector of Tcl objects
一个Tcl对象的命名向量


参数:win
a window structure
一个窗口结构


参数:x
an object
对象


参数:i
character or (unquoted) name
字符或(非上市)的名称


参数:drop
logical. Indicates whether a single-element vector should be made into a simple Tcl object or a list of length one
逻辑。指示一个单元素的向量是否应该将一个简单的TCL对象或一个长度为1的列表


参数:value
For tclvalue assignments, a character string. For tclObj assignments, an object of class tclObj
tclvalue任务,一个字符串。 tclObj任务,对象类tclObj


参数:ID
a window ID
一个窗口的ID


参数:parent
a window which becomes the parent of the resulting window
成为结果窗口的父窗口


参数:path
path to a directory containing Tcl packages
路径的目录,其中包含的Tcl包


参数:package
a Tcl package name
Tcl包名称


参数:warn
logical. Warn if not found?
逻辑。警告说,如果没有发现呢?


参数:...
Additional arguments. See below.
额外的参数。见下文。


参数:init
initialization value
初始值


Details

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

Many of these functions are not intended for general use but are used internally by the commands that create and manipulate Tk widgets and Tcl objects.  At the lowest level .Tcl sends a command as a text string to the Tcl interpreter and returns the result as an object of class tclObj (see below).  A newer variant .Tcl.objv accepts arguments in the form of a named list of tclObj objects.
许多这些功能不适用于一般用途,但所使用的内部命令Tk组件和Tcl对象的创建和操纵。在最低级的.Tcl作为一个文本字符串命令发送到Tcl解释器作为一个类的对象并返回结果tclObj(见下文)。一个新的变种.Tcl.objv接受命名一个tclObj对象的列表的形式参数。

.Tcl.args converts an R argument list of tag=value pairs to the Tcl -option value style, thus enabling a simple translation between the two languages. To send a value with no preceding option flag to Tcl, just use an untagged argument. In the rare case one needs an option with no subsequent value tag=NULL can be used. Most values are just converted to character mode and inserted in the command string, but window objects are passed using their ID string, and callbacks are passed via the result of .Tcl.callback. Tags are converted to option flags simply by prepending a -
.Tcl.argstag=value对R参数列表转换到TCL-option value风格,从而使简单的两种语言之间的翻译。发送到Tcl没有前面的选项标志值,只需使用无标记的参数。在极少数情况下需要可以被用于没有后续价值tag=NULL选项。最值转换为字符模式和插入命令字符串,但通过使用自己的ID字符串的窗口对象,回调通过.Tcl.callback的结果通过。标签转换为选项标志,只是在前面加上一个-

.Tcl.args.objv serves a similar purpose as .Tcl.args but produces a list of tclObj objects suitable for passing to .Tcl.objv. The names of the list are converted to Tcl option style internally by .Tcl.objv.
.Tcl.args.objv作为.Tcl.args类似的目的,但产生了tclObj适合传递.Tcl.objv的对象名单。名单上的名字被转换为TCL选项的风格,内部.Tcl.objv。

Callbacks can be either atomic callbacks handled by .Tcl.callback or expressions. An expression is treated as a list of atomic callbacks, with the following exceptions: if an element is a name, it is first evaluated in the callers frame, and likewise if it is an explicit function definition; the break expression is translated directly to the Tcl counterpart. .Tcl.callback converts R functions and unevaluated calls to Tcl command strings.  The argument must be either a function closure or an object of mode "call" followed by an environment.  The return value in the first case is of the form R_call   0x408b94d4 in which the hexadecimal number is the memory address of the function. In the second case it will be of the form R_call_lang 0x8a95904 0x819bfd0. For expressions, a sequence of similar items is generated, separated by semicolons. .Tcl.args takes special precautions to ensure that functions or calls will continue to exist at the specified address by assigning the callback into the relevant window environment (see below).
回调可以.Tcl.callback或表达式处理或者原子回调。表达式被视为一个原子回调名单,但有以下例外:如果一个元素是一个名字,它是第一次评估在呼叫者帧,同样,如果它是一个明确的功能定义;break表达直接转换到对应的Tcl。 .Tcl.callbackR函数和不计算调用Tcl命令字符串转换。参数必须是一个功能关闭或模式"call"随后由环境中的对象。在第一种情况下返回值的形式是R_call   0x408b94d4十六进制数是函数的内存地址。在第二种情况下,这将是形式R_call_lang 0x8a95904 0x819bfd0。表达式生成一个类似的项目序列,用分号隔开。 .Tcl.args采取特别的预防措施,以确保功能或电话将继续存在回调分配到相关的窗口环境(见下文)在指定的地址。

Tk windows are represented as objects of class tkwin which are lists containing  a ID field and an env field which is an R environments, enclosed in the global environment.  The value of the ID field is identical to the Tk window name. The env environment contains a parent variable and a num.subwin variable.  If the window obtains sub-windows and  callbacks, they are added as variables to the environment.   .TkRoot is the top window with ID "."; this window is not  displayed in order to avoid ill effects of closing it via window  manager controls. The parent variable is undefined for .TkRoot.
Tk的窗口类对象代表tkwin这是包含一个ID场env领域,这是一个R的环境,在全球环境内的名单。 ID字段的值是相同的Tk的窗口名称。包含一个env变parent变num.subwin环境。如果窗口获取子窗口和回调,它们添加到环境变量。 .TkRoot是窗口上方的ID“。”为了避免不良影响,通过窗口管理器控制关闭此窗口不显示。 parent变量是未定义.TkRoot。

.Tk.ID extracts the ID of a window, .Tk.newwin creates a new window environment with a given ID and .Tk.subwin creates a new window which is a sub-window of a given parent window.
.Tk.ID提取ID窗口,,.Tk.newwin创建一个新的窗口环境,与一个给定的ID和.Tk.subwin创建一个新的窗口,这是一个给定的父子窗口窗口。

tkdestroy destroys a window and also removes the reference to a window from its parent.
tkdestroy摧毁一个窗口,也消除了从它的父窗口。

is.tkwin can be used to test whether a given object is a window environment.
is.tkwin可以用来测试一个给定的对象是否是一个窗口环境。

tclVar creates a new Tcl variable and initializes it to init.  An R object of class tclVar is created to represent it.  Using as.character on the object returns the Tcl variable name.  Accessing the Tcl variable from R is done using the  tclvalue function, which can also occur on the left-hand side of assignments.  If tclvalue is passed an argument which is not a tclVar object, then it will assume that it is a character string explicitly naming global Tcl variable. Tcl variables created by  tclVar are uniquely named and automatically unset by the garbage collector when the representing object is no longer in use.
tclVar创建一个新的Tcl变量,并将它初始化init。一个R对象的类tclVar创建来代表它。使用as.character返回对象的Tcl变量名。从R访问Tcl变量是使用tclvalue功能,还可以发生在左侧的任务。 tclvalue如果传递一个参数,它是不是一个tclVar对象,然后它会假设它是一个字符串,明确命名全局Tcl变量。 tclVar创建Tcl变量是唯一的命名和由垃圾收集器会自动取消设置时,表示对象是不再使用。

tclArray creates a new Tcl array and initializes it to the empty array.  An R object of class tclArray and inheriting from class tclVar is created to represent it. You can access elements of the Tcl array using indexing with [[ or $, which also allow replacement forms.  Notice that Tcl arrays are associative by nature and hence unordered; indexing with a numeric index i refers to the element with the name as.character(i).  Multiple indices are pasted together separated by commas to form a single name.  You can query the length and the set of names in an array using methods for length and names, respectively; these cannot meaningfully be set so assignment forms exist only to print an error message.
tclArray创建一个新的Tcl数组和空数组初始化。一个一流的研发对象tclArray“从继承tclVar类的被创建来代表它。您可以使用与[[或$,这也让替代形式索引访问的Tcl数组元素。请注意,Tcl数组是关联的性质,并因此无序;索引数字索引i是指元素的名称as.character(i)。粘贴在一起,形成一个单一的名称由逗号分隔多个指数。您可以查询的长度和一个数组中的名称length和names,分别设置使用方法;这些不能有意义的设置,使分配形式存在,只打印错误消息。

It is possible to access Tcl's "dual-ported" objects directly, thus avoiding parsing and deparsing of their string representation. This works by using objects of class tclObj.  The string representation of such objects can be extracted (but not set) using tclvalue and conversion to vectors of mode "character", "double", "integer", "logical".  Conversely, such vectors can be converted using as.tclObj.  There is an ambiguity as to what should happen for length one vectors, controlled by the drop argument; there are cases where the distinction matters to Tcl, although mostly it treats them equivalently.  Notice that tclvalue and as.character differ on an object whose string representation has embedded spaces, the former is sometimes to be preferred, in particular when applied to the result of tclread, tkgetOpenFile, and similar functions.  The as.raw method returns a raw vector or a list of raw vectors and can be used to return binary data from Tcl.
这是可能的访问Tcl的“双端口”对象直接,从而避免了解析和其字符串表示形式deparsing。这工作使用类tclObj的对象。这些对象的字符串表示形式可以提取(但不设置)使用tclvalue和转换模式向量"character","double","integer","logical"。相反,这些向量可以转换成使用as.tclObj。有一个模糊的长度应该发生的一个向量,drop参数控制;有区别重要的Tcl的情况下,虽然大多对待他们等效。通知tclvalue和as.character对象的字符串表示形式嵌入的空格上有所不同,前者是有时,特别是要优先应用于tclread时,tkgetOpenFile ,和类似的功能。 as.raw方法返回原始向量或原始向量,可用于从Tcl返回二进制数据。

The object behind a tclVar object is extracted using tclObj(x) which also allows an assignment form, in which the right hand side of the assignment is automatically converted using as.tclObj.  There is a print method for tclObj objects; it prints <Tcl> followed by the string representation of the object.  Notice that as.character on a tclVar object is the name of the corresponding Tcl variable and not the value.
tclVar对象后面的对象提取使用tclObj(x)这也允许转让的形式,在转让的右侧被自动转换成使用as.tclObj。有一个tclObj对象的打印方法,它打印<Tcl>随后由该对象的字符串表示。请注意,as.charactertclVar对象的名称和相应的Tcl变量值。

Tcl packages can be loaded with tclRequire; it may be necessary to add the directory where they are found to the Tcl search path with addTclPath.  The return value is a class "tclObj" object if it succeeds, or FALSE if it fails (when a warning is issued).
TCL包可以装用tclRequire;可能需要添加目录,他们在那里发现与addTclPathTcl的搜索路径。返回值是类"tclObj"对象,如果它成功,或FALSE如果失败(时发出警告)。


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

Strings containing unbalanced braces are currently not handled well in many circumstances.
含不平衡括号的字符串目前没有处理好,在许多情况下。


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

TkWidgets, TkCommands, TkWidgetcmds.
TkWidgets,TkCommands,TkWidgetcmds。

capabilities("tcltk") to see if Tcl/Tk support was compiled into this build of R.
capabilities("tcltk")看看Tcl / Tk支持编译到这个R的构建


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


## Not run: [#无法运行:]
## These cannot be run by example() but should be OK when pasted[#这些不能运行(例如),但粘贴时,应确定]
## into an interactive R session with the tcltk package loaded[tcltk装载包的互动R会话#]
.Tcl("format \"%s\n\" \"Hello, World!\"")
f <- function()cat("HI!\n")
.Tcl.callback(f)
.Tcl.args(text="Push!", command=f) # NB: Different address[注:不同的地址]

xyzzy <- tclVar(7913)
tclvalue(xyzzy)
tclvalue(xyzzy) <- "foo"
as.character(xyzzy)
tcl("set", as.character(xyzzy))

top &lt;- tktoplevel() # a Tk widget, see Tk-widgets[一个Tk小部件,看到TK-部件]
ls(envir=top$env, all=TRUE)
ls(envir=.TkRoot$env, all=TRUE)# .Tcl.args put a callback ref in here[在这里提出。Tcl.args回调文献]

## End(Not run)[#结束(不运行)]

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-24 02:21 , Processed in 0.028353 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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