[R] read.table in TCL/TK interface

christian ozric at web.de
Mon Feb 11 16:34:40 CET 2002


hello,
i would like program userfriendly tcl/tk widgets like
the t-test example in  a more complex way !

(1) Is it not possible to combine tk_getOpenFile with
the R function read.table  to select in userfriendly way data sets ?
(I'm newbie and take code-parts from t-test example and scripting example.)

(2) Is it possible to use a variableSelection widget
to select a special variable which  i can use to  replace in R commands 
like:
rpart( selectedVar ~.,data) ?

(3) What occur the difference run tcl/tk code
in R-Winedt , i get  the results only  when i use paste !

$ source("D:/Statsoft/rw1041/code/TCL-TK.R")
******************************************************
 The source for this demo can be found in the file:
 D:/Statsoft/rw1041/library/tcltk/demo/tkttest.R
******************************************************
### Command executed via Tk ###
t.test(Ozone[Month == 5], Ozone[Month == 8], alternative = "two.sided",
    var.equal = FALSE)
### -----
...what is happen here ?

Thanks for advance and suggestions
regards Christian Schulz


tktree <- function() {
wfile <- ""
tt <- tktoplevel()
tktitle(tt) <- "Tcl/TK Decision Tree Window "
yvar <- "EKV"
y.entry <- tkentry(tt,textvariable=yvar)
submit.but <- tkbutton(tt, 
text="submit",command=function()tclvalue(done)<-1)
done <- tclVar(0)
tkpack(y.entry)
topMenu <- tkmenu(tt)
tkconfigure(tt,menu=topMenu)
fileMenu <- tkmenu(topMenu,tearoff=FALSE)


       load <- function() {
       file <- tkcmd("tk_getOpenFile")
       if (!length(file)) return()
       chn <- tkcmd("open", file, "r")
       #tkinsert(txt,"0.0",tkcmd("read",chn))
       chn <- read.table(file,na.strings="?",headers=TRUE)
       tkcmd("close",chn)
       wfile <<- file
       }

                exit <- function() {
                tkdestroy(tt)}

                build <- function()
                {
                y  <- parse(text=tclvalue(yvar))[[1]]
                substitute(rpart(yvar ~.,data=file))
                }

                tkadd(fileMenu,"command",label="Load",command=load)
                #tkadd(fileMenu,"command",label="Save",command=save)
                tkadd(fileMenu,"command",label="Exit",command=exit)
                tkadd(topMenu,"cascade",label="File",menu=fileMenu)
                #tkadd(topMenu,"command",label="Run",command=run)


                tkgrid(tklabel(tt,text="Recursive Partioning"),columnspan=1)
                tkgrid(tklabel(tt,text="y variable"), y.entry)
                tkgrid(submit.but)

        ## capture destroy (e.g. from window controls
        ## otherwise the tkwait hangs with nowhere to go
        tkbind(tt, "<Destroy>", function()tclvalue(done)<-2)

        tkwait.variable(done)

        if(tclvalue(done)=="2") stop("aborted")

        tkdestroy(tt)
        cmd <- build()
        cat("### Command executed via Tk ###\n")
        cat(deparse(build()),sep="\n")
        cat("### -----\n")
        eval.parent(cmd)
                
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://stat.ethz.ch/pipermail/r-help/attachments/20020211/3a0869dc/attachment.html


More information about the R-help mailing list