1

I'm trying to make a small GUI to make it easier for other people to run a script. I'm using gWidgets with tcltk on a Windows machine.

I create a simple window like this:

require(gWidgets)
require(gWidgetstcltk)

options(guiToolkit="tcltk")
win <- gwindow(title="This is a window!")
grp <- ggroup(container=win)
lbl <- glabel("Here you can write stuff:", container=grp)
txt <- gedit(text="Stuff", container=grp)

When I run it on a new session i get the error message:

Error in envRefInferField(x, what, getClass(class(x)), selfEnv) : 
  ‘no_items’ is not a valid field or method name for reference class “Entry”

If i rerun after the error i get this:

<simpleError in envRefInferField(x, what, getClass(class(x)), selfEnv): ‘no_items’ is
not a valid field or method name for reference class “Entry”>

Anyone can explain what is going on?

EDIT: The problem seems to only show up on RStudio and not on RGui.exe. I'm not such an expert programmer, but I guess it is somehow related with the way RStudio manages the environments.

I guess the question now is more: How do i make this work normally in RStudio?

Traceback:

> traceback()
11: stop(gettextf("%s is not a valid field or method name for reference class %s", 
        sQuote(field), dQuote(thisClass@className)), domain = NA)
10: envRefInferField(x, what, getClass(class(x)), selfEnv)
9: r5_widget$no_items
8: r5_widget$no_items
7: .length(x@widget, x@toolkit)
6: .length(x@widget, x@toolkit)
5: FUN(X[[3L]], ...)
4: FUN(X[[3L]], ...)
3: lapply(X = X, FUN = FUN, ...)
2: sapply(globalValues, length, USE.NAMES = FALSE) at SessionWorkspace.R#166
1: (function () 
   {
       globals = ls(envir = globalenv())
       globalValues = lapply(globals, function(name) {
           get(name, envir = globalenv(), inherits = FALSE)
       })
       types = sapply(globalValues, .rs.getSingleClass, USE.NAMES = FALSE)
       lengths = sapply(globalValues, length, USE.NAMES = FALSE)
       values = sapply(globalValues, .rs.valueAsString, USE.NAMES = FALSE)
       extra = sapply(globalValues, .rs.valueDescription, USE.NAMES = FALSE)
       result = list(name = globals, type = types, len = lengths, 
           value = values, extra = extra)
       result
   })()
zelite
  • 1,478
  • 16
  • 37
  • That code snippet works fine for me. And `gWidgets` is based on S4 classes, not reference classes. Are you sure that this is causing the error? Also, what does `traceback()` tell you? – Richie Cotton Oct 07 '13 at 13:09
  • At first i was doing this in RStudio and there I see the problem. in RGui I don't get an error. So i guess it's some problem in RStudio. I'll edit the post with traceback info. – zelite Oct 07 '13 at 14:48
  • This problem can be caused by using `<-` instead of `=` in a reference class definition. http://stackoverflow.com/questions/11596213/r-reference-class-issue (Though unclear if this is the problem here.) – Richie Cotton Oct 07 '13 at 15:02
  • Also, can you just double-double check that you aren't using `gWidgets2` (which uses reference classes) in RStudio. – Richie Cotton Oct 07 '13 at 15:03
  • I'm guessing this is an issue with RStudio. I can't replicate it from the terminal. RStudio and Tk have potential eventloop conflicts that make it potentially troublesome. Not sure where this particular error comes from. As Richie pointed out, it would have to be with gWidgets2 (the rewrite that I still need to publish on CRAN). – jverzani Oct 07 '13 at 15:31
  • I'm using Package: gWidgets; Version: 0.0-52, from CRAN. (Packaged: 2012-10-09 00:00:16 UTC; verzani) – zelite Oct 14 '13 at 07:45
  • Can you let me know which R version you are using? I forgot that there are some things handled with reference classes in gWidgetstcltk. I think that the problem is the method isn't cached for some reason, so look up via get fails. – jverzani Oct 19 '13 at 14:05
  • `$version.string [1] "R version 3.0.2 (2013-09-25)"` – zelite Oct 21 '13 at 06:57

0 Answers0