[R] Speeding up the transfer of a tcl character array to R

Gabor Grothendieck ggrothendieck at gmail.com
Fri Jun 18 03:00:33 CEST 2010


What is the best way to transfer a character array from tcl to R.

1. This works but its very slow if the tcl variable, r, is long:

n <- as.numeric(tclvalue(.Tcl("llength $r")))
sapply(seq(0, length = n), function(i) tclvalue(.Tcl(paste("lindex $r", i))))

2. This also works and is fast but having to set r to itself seems
somewhat ugly:

as.character(.Tcl("set r $r"))

3. The following does not work as I want as it returns all the
elements of r as one big character string separated with spaces:

tclvalue("r")

Any alternatives?



More information about the R-help mailing list