Question

I'm trying to display a large data.table but I'm getting caught between the sluggishness of a gtable from gWidgets with RGtk2 and the inflexibility of View from base. As an example I could have

ex<-data.table(AA=runif(50000,-10,10),
               BB=runif(50000,-10,10),
               CC=runif(50000,-10,10),
               DD=runif(50000,-10,10),
               EE=runif(50000,-10,10),
               FF=runif(50000,-10,10),
               GG=runif(50000,-10,10),
               HH=runif(50000,-10,10),
               II=runif(50000,-10,10),
               JJ=runif(50000,-10,10),
               KK=runif(50000,-10,10),
               LL=runif(50000,-10,10),
               MM=runif(50000,-10,10))

when I do View(ex) it takes a second to populate. If I do

gwin<-gwindow(title="example")
gtab<-gtable(ex,container=gwin)

it will take 59 seconds.

My problem with a View window is that if my script needs to update it, the user has to manually close the window and a new one has to be reopened. My problem with the gWidgets gtable is that in my actual script the output is about a million rows (give or take) which often causes R to crash before the results are populated and always takes longer than is acceptable.

I don't need, or want, the user to be able to edit the underlying table through the display. Really, what View displays is all I need except if the underlying table changes I want to be able to have the window change as opposed to being forced to close the old and open a new.

I saw this question Programmatically close the window created by `View(x)` which implies there's no way to update View windows.

I saw in that same question someone made reference to the plotrix package but I don't want any plots, I just want the table which it doesn't seem to do.

Is there another package that will give me the speed of a View with the ability to programmatically change the window after it is displayed?

Was it helpful?

Solution

Try gdfedit. It is a simple front end to dfedit on RGtk2Extras. Otherwise, there is a model in Rgtk2 that makes this easy enough. Here is a fairly minimal example:

df <- data.frame(x=rnorm(1e5), y = rnorm(1e5))

library(RGtk2)
model <- rGtkDataFrame(df)
view <- gtkTreeView(model)
mapply(view$insertColumnWithAttributes,  -1, colnames(model), 
       list(gtkCellRendererText()), 
       text = seq_len(ncol(model)) - 1)

sw <- gtkScrolledWindow()
sw$add(view)

win <- gtkWindow(show=FALSE)
win$add(sw)
win$show()

This should display this size data set very quickly. I would guess 1e6 is no problem too. I'll let you try. This example comes from the ProgGUIinR package where the code from the book Programming GUIs in R is given. Not plugging the book, but giving you a place to look for some other things that can be done.

This does not synchronize the GUI to the data frame, though the model itself (model) can be accessed through [<- and those changes are reflected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top