Cleber N.Borges
2015-Dec-09 00:37 UTC
[R] [tcltk][tktable] How to make an efficient data transfer from R to Tcl?
hello all, I intend transfer a big data.frame, more than 1e4 rows, more than 100 columns... I found solutions (in internet and help pages) for small data.frame like the showed bellow. Big data.frames is very expensive in computation time in my approach I would like to optimize this transfer anyway ... I saw a function named "as.tclObj" that seems to me a promising form but hard to code... Somebody know a way more clever to do it? thanks for tips cleber ########################################## library( tcltk ) nrow <- 10 ; ncol <- 100 # simulated data: data is originally a data frame DF <- as.data.frame(matrix(round(runif(nrow*ncol),3),nr=nrow,nc=ncol)) ###### # DF_tcl <- as.tclObj( as.matrix( DF ) ) tableDataTclArray <- tclArray() for( i in 1:nrow( DF ) ) tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', rownames( DF )[ i ] , '"') ) ) for( i in 1:ncol( DF ) ) tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', colnames( DF )[ i ] , '"') ) ) for( i in 1:nrow( DF ) ) for( j in 1:ncol( DF ) ) tableDataTclArray[[ i, j ]] <- DF[i,j] ###### ############################################## ############################################## ############################################## # my full code: ############### library( tcltk ); tclRequire("Tktable") wDataOrg <- tktoplevel() tcl('wm', 'geometry', wDataOrg, "1024x600+175+80" ) fmTableData <- ttklabelframe( wDataOrg, text=' Data ', padding=c( 8, 5, 8, 15 ) ) height <- -1; width <- -1 nrowDefault <- 1e4+1; ncolDefault <- 100+1 tableDataTclArray <- tclArray() tableData <- tkwidget( fmTableData, "table", rows=nrowDefault, cols=ncolDefault, height=height+1,width=width+1, xscrollcommand=function(...) tkset( scrX, ... ), yscrollcommand=function(...) tkset( scrY, ... ), rowstretchmode='unset', colstretchmode='unset', multiline=0, cache=1, background="white", selectmode="extended", selecttitle=0, font='{Arial} 10', ipadx=5, ipady=5, anchor='e', borderwidth=c( 0, 1, 0, 1 ), drawmode='slow', variable=tableDataTclArray ) tcl( tableData, "tag", "celltag", "ZeroZero", "0,0" ) tcl( tableData, "tag", "rowtag", "rowtitle", "0" ) tcl( tableData, "tag", "coltag", "coltitle", "0" ) tcl( tableData, "tag", "configure", "ZeroZero", bg='SystemButtonFace', relief="raised", state='disabled' ) tcl( tableData, "tag", "configure", "rowtitle", bg='lightgreen', relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='center' ) tcl( tableData, "tag", "configure", "coltitle", bg='lightgreen', relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='w' ) tcl( tableData, "tag", "configure", "active", fg='yellow', bg='red' ) tcl( tableData, "width", "0", "20" ) scrX <- tkscrollbar( fmTableData, orient="horizontal", command=function(...) tkxview( tableData, ... ) ) scrY <- tkscrollbar( fmTableData, orient="vertical", command=function(...) tkyview( tableData, ... ) ) scrYwidth <- as.integer( tkcget( scrY, width = NULL ) ) tcl( "pack", scrY, side = "right", fill = "y", expand = FALSE, pady = c(0, scrYwidth + 2) ) tcl( "pack", scrX, side = "bottom", fill = "x", expand = FALSE ) tcl( "pack", tableData, anchor='n', side="right", expand=TRUE, fill="both" ) tcl( "pack", fmTableData, fill="both", expand = TRUE, padx=10, pady=10 ) ########################################## expensive time computation [[elided Yahoo spam]] DF <- as.data.frame( matrix( round(runif(1e4 * 100),3), nr=1e4, nc=100 ) ) #### simulated data for( i in 1:nrow( DF ) ){ tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', rownames( DF )[ i ] , '"') ) ) } for( i in 1:ncol( DF ) ){ tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', colnames( DF )[ i ] , '"') ) ) } for( i in 1:nrow( DF ) ) { for( j in 1:ncol( DF ) ){ tableDataTclArray[[ i, j ]] <- DF[i,j] } } # --- Este email foi escaneado pelo Avast antiv?rus. https://www.avast.com/antivirus
Bert Gunter
2015-Dec-09 00:51 UTC
[R] [tcltk][tktable] How to make an efficient data transfer from R to Tcl?
Define: "transfer" ( save/load should be efficient and fast within R, but you appear to have something else in mind. What?) Apologies if it's obvious and I just don't get it. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Tue, Dec 8, 2015 at 4:37 PM, Cleber N.Borges <klebyn at yahoo.com.br> wrote:> hello all, > I intend transfer a big data.frame, more than 1e4 rows, more than 100 > columns... > I found solutions (in internet and help pages) for small data.frame like the > showed bellow. > Big data.frames is very expensive in computation time in my approach > I would like to optimize this transfer anyway ... > I saw a function named "as.tclObj" that seems to me a promising form but > hard to code... > Somebody know a way more clever to do it? > > thanks for tips > cleber > > ########################################## > library( tcltk ) > nrow <- 10 ; ncol <- 100 > # simulated data: data is originally a data frame > DF <- as.data.frame(matrix(round(runif(nrow*ncol),3),nr=nrow,nc=ncol)) > ###### > # DF_tcl <- as.tclObj( as.matrix( DF ) ) > > tableDataTclArray <- tclArray() > for( i in 1:nrow( DF ) ) > tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', > rownames( DF )[ i ] , '"') ) ) > > for( i in 1:ncol( DF ) ) > tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', > colnames( DF )[ i ] , '"') ) ) > > > for( i in 1:nrow( DF ) ) > for( j in 1:ncol( DF ) ) > tableDataTclArray[[ i, j ]] <- DF[i,j] > ###### > > > > > > ############################################## > ############################################## > ############################################## > # my full code: > ############### > library( tcltk ); tclRequire("Tktable") > wDataOrg <- tktoplevel() > tcl('wm', 'geometry', wDataOrg, "1024x600+175+80" ) > fmTableData <- ttklabelframe( wDataOrg, text=' Data ', padding=c( 8, 5, 8, > 15 ) ) > height <- -1; width <- -1 > nrowDefault <- 1e4+1; ncolDefault <- 100+1 > tableDataTclArray <- tclArray() > tableData <- tkwidget( fmTableData, "table", rows=nrowDefault, > cols=ncolDefault, > height=height+1,width=width+1, > xscrollcommand=function(...) tkset( scrX, ... ), > yscrollcommand=function(...) tkset( scrY, ... ), > rowstretchmode='unset', colstretchmode='unset', > multiline=0, cache=1, > background="white", selectmode="extended", > selecttitle=0, > font='{Arial} 10', ipadx=5, ipady=5, anchor='e', > borderwidth=c( 0, 1, 0, 1 ), drawmode='slow', > variable=tableDataTclArray ) > tcl( tableData, "tag", "celltag", "ZeroZero", "0,0" ) > tcl( tableData, "tag", "rowtag", "rowtitle", "0" ) > tcl( tableData, "tag", "coltag", "coltitle", "0" ) > tcl( tableData, "tag", "configure", "ZeroZero", bg='SystemButtonFace', > relief="raised", state='disabled' ) > tcl( tableData, "tag", "configure", "rowtitle", bg='lightgreen', > relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='center' ) > tcl( tableData, "tag", "configure", "coltitle", bg='lightgreen', > relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='w' ) > tcl( tableData, "tag", "configure", "active", fg='yellow', bg='red' ) > tcl( tableData, "width", "0", "20" ) > scrX <- tkscrollbar( fmTableData, orient="horizontal", command=function(...) > tkxview( tableData, ... ) ) > scrY <- tkscrollbar( fmTableData, orient="vertical", command=function(...) > tkyview( tableData, ... ) ) > scrYwidth <- as.integer( tkcget( scrY, width = NULL ) ) > tcl( "pack", scrY, side = "right", fill = "y", expand = FALSE, pady = c(0, > scrYwidth + 2) ) > tcl( "pack", scrX, side = "bottom", fill = "x", expand = FALSE ) > tcl( "pack", tableData, anchor='n', side="right", expand=TRUE, fill="both" > ) > tcl( "pack", fmTableData, fill="both", expand = TRUE, padx=10, pady=10 ) > ########################################## expensive time computation > [[elided Yahoo spam]] > DF <- as.data.frame( matrix( round(runif(1e4 * 100),3), nr=1e4, nc=100 ) ) > #### simulated data > for( i in 1:nrow( DF ) ){ > tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', > rownames( DF )[ i ] , '"') ) ) > } > for( i in 1:ncol( DF ) ){ > tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', > colnames( DF )[ i ] , '"') ) ) > } > for( i in 1:nrow( DF ) ) { > for( j in 1:ncol( DF ) ){ > tableDataTclArray[[ i, j ]] <- DF[i,j] > } > } > # > > > --- > Este email foi escaneado pelo Avast antiv?rus. > https://www.avast.com/antivirus > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Cleber N.Borges
2015-Dec-09 02:04 UTC
[R] [tcltk][tktable] How to make an efficient data transfer from R to Tcl?
my objective is to show data in screen inside a tktable... for that, the data must be in a TCL variable and not only in a R variable like that:> library( tcltk ) > mtcars_in_TCL <- tclArray() > for( i in 1:5 ) for( j in 1:5 ) mtcars_in_TCL[[ i,j ]] <-as.matrix(mtcars)[ i,j ] i thank by attention cleber Em 08/12/2015 22:51, Bert Gunter escreveu:> Define: "transfer" > > ( save/load should be efficient and fast within R, but you appear to > have something else in mind. What?) > > Apologies if it's obvious and I just don't get it. > > Cheers, > > Bert > > > Bert Gunter > > "Data is not information. Information is not knowledge. And knowledge > is certainly not wisdom." > -- Clifford Stoll > > > On Tue, Dec 8, 2015 at 4:37 PM, Cleber N.Borges <klebyn at yahoo.com.br> wrote: >> hello all, >> I intend transfer a big data.frame, more than 1e4 rows, more than 100 >> columns... >> I found solutions (in internet and help pages) for small data.frame like the >> showed bellow. >> Big data.frames is very expensive in computation time in my approach >> I would like to optimize this transfer anyway ... >> I saw a function named "as.tclObj" that seems to me a promising form but >> hard to code... >> Somebody know a way more clever to do it? >> >> thanks for tips >> cleber >> >> ########################################## >> library( tcltk ) >> nrow <- 10 ; ncol <- 100 >> # simulated data: data is originally a data frame >> DF <- as.data.frame(matrix(round(runif(nrow*ncol),3),nr=nrow,nc=ncol)) >> ###### >> # DF_tcl <- as.tclObj( as.matrix( DF ) ) >> >> tableDataTclArray <- tclArray() >> for( i in 1:nrow( DF ) ) >> tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', >> rownames( DF )[ i ] , '"') ) ) >> >> for( i in 1:ncol( DF ) ) >> tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', >> colnames( DF )[ i ] , '"') ) ) >> >> >> for( i in 1:nrow( DF ) ) >> for( j in 1:ncol( DF ) ) >> tableDataTclArray[[ i, j ]] <- DF[i,j] >> ###### >> >> >> >> >> >> ############################################## >> ############################################## >> ############################################## >> # my full code: >> ############### >> library( tcltk ); tclRequire("Tktable") >> wDataOrg <- tktoplevel() >> tcl('wm', 'geometry', wDataOrg, "1024x600+175+80" ) >> fmTableData <- ttklabelframe( wDataOrg, text=' Data ', padding=c( 8, 5, 8, >> 15 ) ) >> height <- -1; width <- -1 >> nrowDefault <- 1e4+1; ncolDefault <- 100+1 >> tableDataTclArray <- tclArray() >> tableData <- tkwidget( fmTableData, "table", rows=nrowDefault, >> cols=ncolDefault, >> height=height+1,width=width+1, >> xscrollcommand=function(...) tkset( scrX, ... ), >> yscrollcommand=function(...) tkset( scrY, ... ), >> rowstretchmode='unset', colstretchmode='unset', >> multiline=0, cache=1, >> background="white", selectmode="extended", >> selecttitle=0, >> font='{Arial} 10', ipadx=5, ipady=5, anchor='e', >> borderwidth=c( 0, 1, 0, 1 ), drawmode='slow', >> variable=tableDataTclArray ) >> tcl( tableData, "tag", "celltag", "ZeroZero", "0,0" ) >> tcl( tableData, "tag", "rowtag", "rowtitle", "0" ) >> tcl( tableData, "tag", "coltag", "coltitle", "0" ) >> tcl( tableData, "tag", "configure", "ZeroZero", bg='SystemButtonFace', >> relief="raised", state='disabled' ) >> tcl( tableData, "tag", "configure", "rowtitle", bg='lightgreen', >> relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='center' ) >> tcl( tableData, "tag", "configure", "coltitle", bg='lightgreen', >> relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='w' ) >> tcl( tableData, "tag", "configure", "active", fg='yellow', bg='red' ) >> tcl( tableData, "width", "0", "20" ) >> scrX <- tkscrollbar( fmTableData, orient="horizontal", command=function(...) >> tkxview( tableData, ... ) ) >> scrY <- tkscrollbar( fmTableData, orient="vertical", command=function(...) >> tkyview( tableData, ... ) ) >> scrYwidth <- as.integer( tkcget( scrY, width = NULL ) ) >> tcl( "pack", scrY, side = "right", fill = "y", expand = FALSE, pady = c(0, >> scrYwidth + 2) ) >> tcl( "pack", scrX, side = "bottom", fill = "x", expand = FALSE ) >> tcl( "pack", tableData, anchor='n', side="right", expand=TRUE, fill="both" >> ) >> tcl( "pack", fmTableData, fill="both", expand = TRUE, padx=10, pady=10 ) >> ########################################## expensive time computation >> [[elided Yahoo spam]] >> DF <- as.data.frame( matrix( round(runif(1e4 * 100),3), nr=1e4, nc=100 ) ) >> #### simulated data >> for( i in 1:nrow( DF ) ){ >> tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', >> rownames( DF )[ i ] , '"') ) ) >> } >> for( i in 1:ncol( DF ) ){ >> tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', >> colnames( DF )[ i ] , '"') ) ) >> } >> for( i in 1:nrow( DF ) ) { >> for( j in 1:ncol( DF ) ){ >> tableDataTclArray[[ i, j ]] <- DF[i,j] >> } >> } >> # >> >> >>--- Este email foi escaneado pelo Avast antiv?rus. https://www.avast.com/antivirus
phgrosjean at sciviews.org
2015-Dec-09 07:42 UTC
[R] [tcltk][tktable] How to make an efficient data transfer from R to Tcl?
Are you sure this is the right way to go for your use case? Even if you got a quick solution to display an 1e4 x 100 table in TkTable, what is the purpose of it? Will the user browse the whole dataset that way? Even if the answer is yes, you would probably need to implement sorting and filtering features to ease access to the data? and you will end up reinventing a database. Have you considered to put your data in, say SQLite, using RSQLite? Then, you could feed your data page by page (10, 20, 50, or 100 items per page) into your TkTable widget. You still you will got a bunch of programming in tcltk. But it may be a necessity if you have to integrate the table display in a larger Tk GUI. Another approach, still with the database backend, is to use HTML + Javascript and the numerous solutions that exist to display the content of your database. If you need close interaction with R, you may like the Shiny reactive programming approach. Look at the DT package, although I have not tested it with very large tables. Best, Philippe Grosjean> On 09 Dec 2015, at 01:37, Cleber N.Borges <klebyn at yahoo.com.br> wrote: > > hello all, > I intend transfer a big data.frame, more than 1e4 rows, more than 100 columns... > I found solutions (in internet and help pages) for small data.frame like the showed bellow. > Big data.frames is very expensive in computation time in my approach > I would like to optimize this transfer anyway ... > I saw a function named "as.tclObj" that seems to me a promising form but hard to code... > Somebody know a way more clever to do it? > > thanks for tips > cleber > > ########################################## > library( tcltk ) > nrow <- 10 ; ncol <- 100 > # simulated data: data is originally a data frame > DF <- as.data.frame(matrix(round(runif(nrow*ncol),3),nr=nrow,nc=ncol)) > ###### > # DF_tcl <- as.tclObj( as.matrix( DF ) ) > > tableDataTclArray <- tclArray() > for( i in 1:nrow( DF ) ) > tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', rownames( DF )[ i ] , '"') ) ) > > for( i in 1:ncol( DF ) ) > tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', colnames( DF )[ i ] , '"') ) ) > > > for( i in 1:nrow( DF ) ) > for( j in 1:ncol( DF ) ) > tableDataTclArray[[ i, j ]] <- DF[i,j] > ###### > > > > > > ############################################## > ############################################## > ############################################## > # my full code: > ############### > library( tcltk ); tclRequire("Tktable") > wDataOrg <- tktoplevel() > tcl('wm', 'geometry', wDataOrg, "1024x600+175+80" ) > fmTableData <- ttklabelframe( wDataOrg, text=' Data ', padding=c( 8, 5, 8, 15 ) ) > height <- -1; width <- -1 > nrowDefault <- 1e4+1; ncolDefault <- 100+1 > tableDataTclArray <- tclArray() > tableData <- tkwidget( fmTableData, "table", rows=nrowDefault, cols=ncolDefault, > height=height+1,width=width+1, > xscrollcommand=function(...) tkset( scrX, ... ), > yscrollcommand=function(...) tkset( scrY, ... ), > rowstretchmode='unset', colstretchmode='unset', multiline=0, cache=1, > background="white", selectmode="extended", selecttitle=0, > font='{Arial} 10', ipadx=5, ipady=5, anchor='e', > borderwidth=c( 0, 1, 0, 1 ), drawmode='slow', > variable=tableDataTclArray ) > tcl( tableData, "tag", "celltag", "ZeroZero", "0,0" ) > tcl( tableData, "tag", "rowtag", "rowtitle", "0" ) > tcl( tableData, "tag", "coltag", "coltitle", "0" ) > tcl( tableData, "tag", "configure", "ZeroZero", bg='SystemButtonFace', relief="raised", state='disabled' ) > tcl( tableData, "tag", "configure", "rowtitle", bg='lightgreen', relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='center' ) > tcl( tableData, "tag", "configure", "coltitle", bg='lightgreen', relief='raised', borderwidth=c( 0, 1, 0, 1 ), anchor='w' ) > tcl( tableData, "tag", "configure", "active", fg='yellow', bg='red' ) > tcl( tableData, "width", "0", "20" ) > scrX <- tkscrollbar( fmTableData, orient="horizontal", command=function(...) tkxview( tableData, ... ) ) > scrY <- tkscrollbar( fmTableData, orient="vertical", command=function(...) tkyview( tableData, ... ) ) > scrYwidth <- as.integer( tkcget( scrY, width = NULL ) ) > tcl( "pack", scrY, side = "right", fill = "y", expand = FALSE, pady = c(0, scrYwidth + 2) ) > tcl( "pack", scrX, side = "bottom", fill = "x", expand = FALSE ) > tcl( "pack", tableData, anchor='n', side="right", expand=TRUE, fill="both" ) > tcl( "pack", fmTableData, fill="both", expand = TRUE, padx=10, pady=10 ) > ########################################## expensive time computation [[elided Yahoo spam]] > DF <- as.data.frame( matrix( round(runif(1e4 * 100),3), nr=1e4, nc=100 ) ) #### simulated data > for( i in 1:nrow( DF ) ){ > tableDataTclArray[[ i, 0 ]] <- .Tcl( noquote( paste('format "', rownames( DF )[ i ] , '"') ) ) > } > for( i in 1:ncol( DF ) ){ > tableDataTclArray[[ 0, i ]] <- .Tcl( noquote( paste('format "', colnames( DF )[ i ] , '"') ) ) > } > for( i in 1:nrow( DF ) ) { > for( j in 1:ncol( DF ) ){ > tableDataTclArray[[ i, j ]] <- DF[i,j] > } > } > # > > > --- > Este email foi escaneado pelo Avast antiv?rus. > https://www.avast.com/antivirus > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.