[R] Print to the cmd line in a script

Michael Bedward michael.bedward at gmail.com
Wed Nov 24 12:10:55 CET 2010


Is this what you want ?

printCount <- function(N) {
  for (i in 1:N) {
    cat(i, "\n")
  }
}

Depending on your platform, output from the print function may not
appear until after your function has finished. You can try using
flush.console() to give it a nudge...

printCount <- function(N) {
  for (i in 1:N) {
    print(i)
    flush.console()
  }
}

Michael


On 24 November 2010 21:15, Joel <joda2457 at student.uu.se> wrote:
>
> Hi Ive written a script that loopes throu some data, but what I want to do is
> to print to the cmd line how many times it has looped to the cmd line. And
> as it is just a counter from 1 this should be quite easy :P
>
> but ive tried things like print(counter) and so on but it dossent print
> anything to the cmd prompt, so what is the command to print from inside a
> script?
> --
> View this message in context: http://r.789695.n4.nabble.com/Print-to-the-cmd-line-in-a-script-tp3057009p3057009.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>



More information about the R-help mailing list