0

I'm testing the use of custom GUI to get user feedback before performing tasks in R and doing the latter via a batch script. The following code was adapted from another post on SO. After the R function executes, the custom GUI appears for a few seconds then disappears and no errors is reported in the .Rout file.

The R code

library(gWidgets2)
library(gWidgets2tcltk)
items <- data.frame(id=numeric(0), gender=character(0), age=numeric(0), race=character(0), stringsAsFactors=FALSE)
genders <- c("Male", "Female")
race <- c("Black", "Hispanic", "Other")

w <- gwindow("Capn's GUI", visible=FALSE)
g <- ggroup(cont=w, horizontal=FALSE)
lyt <- glayout(cont=g)
lyt[1,1] <- "Gender:"
lyt[1,2] <- gradio(genders, cont=lyt)

lyt[2,1] <- "Age:"
lyt[2,2] <- gedit("40", coerce.with=as.numeric, cont=lyt)

lyt[3,1] <- "Race:"
lyt[3,2] <- gcombobox(race, selected=0L, cont=lyt)

lyt[4,2] <- gbutton("Add", cont=lyt, handler=function(h,...) {
  vals <- lapply(lyt[1:3, 2], svalue)
  id <- nrow(items) + 1                 # or roll your own
  items[id, ] <<- c(id, vals)
  tbl[] <- items
})
gseparator(cont=g)
tbl <- gtable(items, cont=g)


visible(w) <- TRUE

Batch script

@echo off
"C:\Users\???\R\R-4.1.0\bin\x64\R.exe" CMD BATCH --ess "C:\Users\???\script.R"

What am I missing?

user2566907
  • 99
  • 10

0 Answers0