File: ex-gformlayout.R

package info (click to toggle)
r-cran-gwidgets 0.0-54.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 2,360 kB
  • sloc: sh: 13; makefile: 2
file content (92 lines) | stat: -rw-r--r-- 3,501 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
w <- gwindow("gformlayout test", visible=FALSE)

## layout a collection of widgets to generate a t.test
tTest <- list(type = "ggroup",
              horizontal = FALSE,
              children = list(
                list(type="fieldset",
                     columns = 2,
                     label = "Variable(s)",
                     label.pos = "top",
                     label.font = c(weight="bold"),
                     children = list(
                       list(name = "x",
                            label = "x",
                            type = "gedit",
                            text = ""),
                       list(name = "y",
                            label = "y",
                            type = "gedit",
                            text = "",
                            depends.on = "x",
                            depends.FUN = function(value) nchar(as.character(value)) > 0,
                            depends.signal = "addHandlerBlur"
                            )
                       )
                     ),
                list(type = "fieldset",
                     label = "Hypotheses",
                     columns = 2, 
                     children = list(
                       list(name = "mu",
                            type = "gedit",                            
                            label = "Ho: mu=",
                            text = "0",
                            coerce.with = as.numeric),
                       list(name = "alternative",
                            type="gcombobox",
                            label = "HA: ",
                            items = c("two.sided","less","greater")
                            )
                       )
                     ),
                list(type = "fieldset",
                     label = "two sample test",
                     columns = 2,
                     depends.on = "y",
                     depends.FUN = function(value) nchar(as.character(value)) > 0,
                     depends.signal = "addHandlerBlur",                     
                     children = list(
                       list(name = "paired",
                            label = "paired samples",
                            type = "gcombobox",
                            items = c(FALSE, TRUE)
                            ),
                       list(name = "var.equal",
                            label = "assume equal var",
                            type = "gcombobox",
                            items = c(FALSE, TRUE)
                            )
                       )
                     ),
                list(type = "fieldset",
                     columns = 1,
                     children = list(
                       list(name = "conf.level",
                            label = "confidence level",
                            type = "gedit",
                            text = "0.95",
                            coerce.with = as.numeric)
                       )
                     )
                )
              )


g <- ggroup(horizontal = FALSE, cont = w)
fl <- gformlayout(tTest, cont = g, expand=TRUE)
bg <- ggroup(cont = g)
addSpring(bg)
b <- gbutton("run t.test", cont = bg)
addHandlerChanged(b, function(h,...) {
  out <- svalue(fl)
  out$x <- svalue(out$x) # turn text string into numbers via get()
  if(out$y == "") {
    out$y <- out$paired <- NULL 
  } else {
   out$y <- svalue(out$y)
  }
  print(do.call("t.test",out))
})

visible(w) <- TRUE