Hello R users! I like to use cat in a loop. I know, loops are not the best way in R ... but my question: It is possible to overwrite the expression "Reading row: i" in each iteration of the loop (print out in the below loop on the screen) or more particulary to overwrite the counter "i". for(i in 1:header$M){ cat("Reading row: ", i) SparseIndex[[i]] <- readBin( con, integer(), n=MIndexNumber[i], size=4 ) SparseSignal[[i]] <- readBin( con, numeric(), n=MIndexNumber[i], size=4 ) } Many thanks J?rn Schulz. -- View this message in context: http://www.nabble.com/cat-and-positioning-of-the-output-tf1869521.html#a5109359 Sent from the R help forum at Nabble.com.
On Windows XP this works for me: for(i in 1:3) { if (i > 1) cat("\b"); cat(i); flush.console(); Sys.sleep(1) }; cat("\n") It displays 1, then it overwrites it with 2 and then overwrites that with 3. On 6/29/06, J?rn Schulz <noah78 at web.de> wrote:> > Hello R users! > > I like to use cat in a loop. I know, loops are not the best way in R ... but > my question: It is possible to overwrite the expression "Reading row: i" in > each iteration of the loop (print out in the below loop on the screen) or > more particulary to overwrite the counter "i". > > for(i in 1:header$M){ > cat("Reading row: ", i) > SparseIndex[[i]] <- readBin( con, integer(), n=MIndexNumber[i], size=4 ) > SparseSignal[[i]] <- readBin( con, numeric(), n=MIndexNumber[i], size=4 ) > } > > Many thanks > J?rn Schulz. > -- > View this message in context: http://www.nabble.com/cat-and-positioning-of-the-output-tf1869521.html#a5109359 > Sent from the R help forum at Nabble.com. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
=?ANSI_X3.4-1968?Q?J=3Frn_Schulz?= wrote:> Hello R users! > > I like to use cat in a loop. I know, loops are not the best way in R ... but > my question: It is possible to overwrite the expression "Reading row: i" in > each iteration of the loop (print out in the below loop on the screen) or > more particulary to overwrite the counter "i".In package svMisc (SciViews bundle): > ?progress > example(progress) Best, Philippe Grosjean> for(i in 1:header$M){ > cat("Reading row: ", i) > SparseIndex[[i]] <- readBin( con, integer(), n=MIndexNumber[i], size=4 ) > SparseSignal[[i]] <- readBin( con, numeric(), n=MIndexNumber[i], size=4 ) > } > > Many thanks > J?rn Schulz.
=?ANSI_X3.4-1968?Q?J=3Frn_Schulz?= wrote:> Hello R users! > > I like to use cat in a loop. I know, loops are not the best way in R ... but > my question: It is possible to overwrite the expression "Reading row: i" in > each iteration of the loop (print out in the below loop on the screen) or > more particulary to overwrite the counter "i". > > for(i in 1:header$M){ > cat("Reading row: ", i) > SparseIndex[[i]] <- readBin( con, integer(), n=MIndexNumber[i], size=4 ) > SparseSignal[[i]] <- readBin( con, numeric(), n=MIndexNumber[i], size=4 ) > } > > Many thanks > J?rn Schulz. >On a UNIX terminal, adding '\r' will cause the cursor to go back to the beginning of the same line. I can't speak for Windows. e.g. for ( i in 1:10 ) { cat("Number",i,"\r"); Sys.sleep(1) }; cat("\n") -Dan -- Dan Gunter. voice:510-495-2504 fax:510-486-6363 dsd.lbl.gov/~dang