R:gWidgets:嵌入其他包

时间:2012-01-23 17:34:09

标签: r

我想知道是否有办法从其他包中嵌入gwidgets对象。 例如,从包utils。

options(guiToolkit = "RGtk2")
library(RGtk2)
library(gWidgets)
library(gWidgetsRGtk2)

library(utils)

w <- gwindow() # gwindow {gWidgets}
e <- edit(InsectSprays) # edit.data.frame {utils} 

提前谢谢

1 个答案:

答案 0 :(得分:0)

这是不可能的,因为gWidgets仅支持某些类的对象,例如gButtongWindow等。gWidgets不包含用于导入\嵌入外部库的文档函数\打包GUI对象。例如

options(guiToolkit = "RGtk2")
library(RGtk2)
library(gWidgets)
library(gWidgetsRGtk2)

library(utils)

win <- gwindow("Window example",
               handler=function(h,...) {
                 print("See ya")
               })
but <- gbutton("cancel", container=win,
        handler = function(h,...) dispose(win))

str(but)  # gButton class object structure

# Formal class 'gButton' [package "gWidgets"] with 2 slots
# ..@ toolkit:Formal class 'guiWidgetsToolkitRGtk2' [package "gWidgets"] with 1 slot
# .. .. ..@ toolkit: chr  ...
# ..@ widget :Warning in str.default(obj, ...) :
#   'str.default': 'le' -- это NA, так что беру как 0
# Formal class 'gButtonRGtk' [package "gWidgetsRGtk2"] with 3 slots
# .. .. ..@ block  :Classes 'GtkAlignment', 'GtkBin', 'GtkContainer', 'GtkWidget', 'GtkObject', 'GInitiallyUnowned', 'GObject', 'RGtkObject' <externalptr> 
#   .. .. .. ..- attr(*, "interfaces")= chr [1:2]  ...
# .. .. ..@ widget :Classes 'GtkButton', 'GtkBin', 'GtkContainer', 'GtkWidget', 'GtkObject', 'GInitiallyUnowned', 'GObject', 'RGtkObject' <externalptr> 
#   .. .. .. ..- attr(*, "interfaces")= chr [1:3]  ...
# .. .. ..@ toolkit:Formal class 'guiWidgetsToolkitRGtk2' [package "gWidgets"] with 1 slot
# .. .. .. .. ..@ toolkit: chr  ...

代码执行后,代码将控制权返回给R编程环境。

相反,utils::edit函数返回data.frame对象并挂起R执行环境。