[R] Trying tkscript, more info
Kenneth Cabrera
krcabrer at perseus.unalmed.edu.co
Tue Jul 23 18:46:05 CEST 2002
Kenneth Cabrera wrote:
> I am trying the function tkscript, that apears in "A primer on the
> R-Tcl/Tk Package" on
> The Newsletter of the R Project of September 2001.
>
> But I am a newbee and I don´t know how to handle some problems.
>
> 1. When I "Load" a file, such a file appears without newline (All the
> text in a line) and
> only the first and the last line.
> 2. When I "Run" a ? symbol appears and I don't know what to do there.
> 3. If I type any letter and press return then this message appears:
>
> Executing from script window:
> -----
> Error in cat(list(...), file, sep, fill, labels, append) :
> argument 3 not yet handled by cat
>
> The file I try to use with the tkscript function is attached too
>
> Thank you for your help
>
> Kenneth Cabrera
>
>I am using W2K and R 1.5.1 version and ActiveState Active Tcl version 8.3.4.3
>------------------------------------------------------------------------
>
>require(tcltk) || stop("tcltk support is absent")
>
>tkscript <- function() {
> wfile <- ""
> tt<-tktoplevel()
> txt<-tktext(tt,height=10)
> tkpack(txt)
> save<-function() {
> file <- tkcmd("tk_getSaveFile",
> initialfile=tkcmd("file","tail",wfile),
> initialdir=tkcmd("file","dirname",wfile))
> if (!length(file)) return()
> chn<-tkcmd("open",file,"w")
> tkcmd("puts",chn,tkget(txt,"0.0","end"))
> tkcmd("close",chn)
> wfile <<-file
> }
> load <-function() {
> file <-tkcmd("tk_getOpenFile")
> if (!length(file)) return()
> chn<-tkcmd("open",file,"r")
> tkinsert(txt,"0.0",tkcmd("read",chn))
> tkcmd("close",chn)
> wfile <<-file
> }
> run <- function() {
> code<-tkget(txt,"0.0","end")
> e<-try(parse(text=code))
> if (inherits(e,"try-error")) {
> tkcmd("tk_messageBox",message="Syntax error",icon="error")
> return()
> }
> cat("Executing from script window:","-----",code,"result:",sep="\n")
> print(eval(e))
> }
> topMenu <- tkmenu(tt)
> tkconfigure(tt,menu=topMenu)
> fileMenu <- tkmenu(topMenu, tearoff=FALSE)
> tkadd(fileMenu,"command",label="Load",command=load)
> tkadd(fileMenu,"command",label="Save",command=save)
> tkadd(topMenu,"cascade",label="File",menu=fileMenu)
> tkadd(topMenu,"command",label="Run",command=run)
>}
>
>
>------------------------------------------------------------------------
>
>x<-seq(1,10,length=200)
>y<-x^2
>plot(x,y)
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list