Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to paginate R output?

Tags:

r

I've been reading the R source code trying to understand how it paginates help pages (for example ?c). I think it's using less, but I haven't been able to find the function that does this. I guess I could do system(gettextf("echo %s | less", my_text)), but it won't work in Windows.

like image 838
nachocab Avatar asked Jul 06 '13 20:07

nachocab


2 Answers

Have a look at ?page and ?file.show:

page(runif(1e5))
like image 111
sgibb Avatar answered Oct 22 '22 11:10

sgibb


+1 to @sgibb, page() is really useful. There are some cases where I want to go with a more complicated solution though. You can also use ?sink in conjunction with ?file.show:

sink(file="tempSink", type="output")
  ...
  # various commands
  ...
sink()
file.show(file="tempSink", delete.file=TRUE, title="my output")

For example, page() only displays one output, but you may want to look at several together. I've also noted that sometimes page() doesn't work, but the above will (I don't know why--it might just be a bug).

like image 33
gung - Reinstate Monica Avatar answered Oct 22 '22 10:10

gung - Reinstate Monica