8

I encounter the following problem:

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

aa <- c(1,2,3)
bb <- c(4,5,6)
cc <- cbind(aa,bb)
cc <-as.data.frame(cc)

t1 <- gtable(cc, container=TRUE)

I want to refresh the content of t1 with:

dd <- c(7,8,9)
dd <- as.data.frame(dd)

But when I run

t1[] <- dd

I receive: Can't replace with fewer columns

Apostolos

f3lix
  • 29,500
  • 10
  • 66
  • 86
Apostolos
  • 101
  • 3
  • 7
    Puzzled by the comment above. It certainly "looks" like an [r] question – IRTFM Jul 03 '11 at 20:40
  • 4
    @meteorainer, it is an R question. `gWidgets` is an R package (http://cran.r-project.org/web/packages/gWidgets/index.html). I think the user doesn't deserve -1. In fact, he provided a complete reproducible example, which is a thumb up! – Roman Luštrik Jul 04 '11 at 08:03

3 Answers3

3

To expand upon John's answer, here's an example.

#Data
cc <- data.frame(aa = 1:3, bb = 4:6)
dd <- data.frame(X = 7:9)

#Wigdets
win <- gwindow()
grp <- ggroup(container = win)
t1 <- gtable(cc, container = grp)

#Refresh widget
delete(grp, t1)
t1 <- gtable(dd, container = grp)

Note that the sample code in the question works fine under gWidgetstcltk; it's a purely GTK issue.

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
2

The gtk widget makes you pick the type of column at construction, so gtable doesn't let you have fewer columns or change column types. If you really want to do this, put the widget in a ggroup container, then delete and add a new widget.

jverzani
  • 5,600
  • 2
  • 21
  • 17
0

If it is only about refreshing instead of completely changing its content I made very nice experience with something like this:

win <- gtable(data.frame(a=rnorm(100),b=runif(100)),container=T)
win[1,1] <- 5
win[1:10,2] <- 6
win[seq(dim(win)[1]),seq(dim(win)[2])] <- win[seq(dim(win)[1]),seq(dim(win)[2])] +1 

a complete 'refresh' might look like this:

win <- gtable(data.frame(a=rnorm(100),b=runif(100),d=FALSE),container=T)
petermeissner
  • 12,234
  • 5
  • 63
  • 63