[R] Redirect/pipe output to less

Ali Tofigh alix.tofigh at gmail.com
Fri Mar 12 17:45:33 CET 2010


On Fri, Mar 12, 2010 at 11:18, David Winsemius <dwinsemius at comcast.net> wrote:
>
> On Mar 12, 2010, at 11:15 AM, Ali Tofigh wrote:
>
>> I'm using R under Linux. Since the help function in R can use the
>> program less to display text, I'd like to know if it is possible for a
>> user to do the same. It would be very helpful to be able to view large
>> objects (matrices/dataframes etc) using less. This is preferable to
>> redirecting output to file or to clutter the workspace with too much
>> output. I have tried to use functions pipe and sink, but I have had no
>> luck getting it to work. Can this be done?
>
> ?capture.output

Thanks for the pointer. For all the lazy users out there, here is what
worked for me:

capture.output(big.matrix, file=pipe("less"))

Or even better, define a function

less <- function(x) {capture.output(x, file=pipe("less"))}

Then you can just do:

less(big.matrix)

Cheers,
/Ali



More information about the R-help mailing list