[R] Question in R

John Fox jfox at mcmaster.ca
Sat Feb 2 16:15:20 CET 2008


NO

Dear Oliver,

I'm not sure why you'd want to do this rather than just scrolling the
console after the output is completed (assuming, of course, that you
can scroll your console), but here's a function (not extensively
tested) that might do what you want:

more <- function(command, lines=20){
  output <- capture.output(eval(command, envir=.GlobalEnv))
  outputlines <- length(output)
  screens <- ceiling(outputlines/lines)
  if (screens < 1) {
    return(invisible(NULL))
    }
  for (i in 1:screens){
    first <- (i - 1)*lines + 1
    last <- min(outputlines, i*lines)
    sapply(output[first:last], function(x) cat(x, "\n"))
    if (i < screens){
      value <- readline("<Enter 'q' to quit, Enter to continue>")
      if (value == "q") break()
      }
    }
  invisible(NULL)
  } 
  
You'd use this as in more(cars), where you can substitute the command
that you want for "cars".

I hope this helps,
 John

On Sat, 2 Feb 2008 13:21:15 +0100
 "Oliver Herbst" <oliverherbst at gmx.de> wrote:
> HI, 
> 
>  
> 
> can anybody help me how to observe or read the output of an r command
> pagewise? (E.g. to make a break after the first page of output data
> and then
> continue by putting a key on the console)
> 
>  
> 
> Thanks a lot.
> 
> Oliver 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.

--------------------------------
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/



More information about the R-help mailing list