[R] question about possibility with R - Tcl/tk library

Peter Dalgaard p.dalgaard at biostat.ku.dk
Mon May 10 16:03:08 CEST 2004


Julien Glenat <julien.glenat at imag.fr> writes:

> Hi , i am using the R(1.8.1)  tcl/tk library in order to build a graphical 
> user interface to mathematic function and i would like to know if it is 
> possible to retrieve the value of a  tkentry to make a R vector
> 
> for exemple with an entry containing "1,2,3,4,5" i want to make a vector 
> which contains 1 2 3 4 5 
> 
> i tried as.vector , as.list and even to write the object to a file with 
> write.table and then re reading it with read.table(...,sep=",")
> but nothing worked
> so if you have an idea....

Nothing to do with tcl/tk really. You have a character sting and want
a numeric vector:

> txt <- "1,2,3,4,5"
> as.numeric(strsplit(txt,",")[[1]])
[1] 1 2 3 4 5
> scan(textConnection(txt),sep=",")
Read 5 items
[1] 1 2 3 4 5

(possibly add quiet=TRUE in the latter case to get rid of the message)

Actually, now that you obviously have the string as a Tcl object and a
Tcl interpreter running, you might do the split on the Tcl side:

> x <- as.tclObj("1,2,3,4,5")
> as.numeric(tkcmd("split", x, ","))
[1] 1 2 3 4 5


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list