Wouldnt
any_command | more
work fine?
“the bash” has no lines, your terminal has.
You can set the number of lines of your terminal in the settings of that application.
A way to do this in R is also to redirect to a file:
sink("a_file.txt")
...your_commands...
sink()
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...
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")
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)