A: 

Wouldnt

any_command | more 

work fine?

matt_tm
Probably the guy is inside R, so bash commands are not possible at that stage.
Benoit
Forgot to make it clear: I am using R in bash in interactive mode, bash commands don't work there.
gojira
A: 

“the bash” has no lines, your terminal has.

You can set the number of lines of your terminal in the settings of that application.

Benoit
Still, how do I prevent the output from scrolling away if the output has more lines than the currently set number of lines of the terminal? Do you seriously suggest setting the number of lines of the currently used shell according to the length of R's output?
gojira
+1  A: 

A way to do this in R is also to redirect to a file:

sink("a_file.txt")
...your_commands...
sink()
Benoit
A: 

It might be possible to wrap your expression in capture.output, and then page the result to the terminal.

pager <- function(cmd,nlines=10){
  output = capture.output(cmd)
  pages = seq(1,length(output),by=nlines)
  for(p in pages){
    f = p
    l = min(p+nlines-1,length(output))
    cat(paste(output[f:l],"\n"))
    readline("*more*")
  }
  return(invisible(0))
}

Usage: pager(ls()), then hit Return (not space or anything else) at each 'more' prompt.

currently it doesn't return the value. Oh and it fails if there's no output. But you can fix these :)

Or use emacs with ESS and let it all scroll back...

Spacedman
+1  A: 

I think the page() function is like having | less in an R session. It allows two representations of the object; i) a version you'd get from dput(), and ii) a version you'd get if you print()-ed the object.

dat <- data.frame(matrix(rnorm(2000), ncol = 5))
page(dat, method = "print")
Gavin Simpson
A: 

Your question is unclear. If you're talking about using R interactively and accidentally running a command which spits out a huge number of lines, run something like this in your R session: options(max.print=4000)

atp