tags:

views:

183

answers:

4

Is there an equivalent to the unix less command that can be used within the R console?

+6  A: 

Not really. There are the commands

  • head() and tail() for showing the beginning and end of objects
  • print() for explicitly showing an object, and just its name followed by return does the same
  • summary() for concise summary that depends on the object
  • str() for its structure

and more. An equivalent for less would be a little orthogonal to the language and system. Where the Unix shell offers you less to view the content of a file (which is presumed to be ascii-encoded), it cannot know about all types.

R is different in that it knows about the object types which is why summary() -- as well as the whole modeling framework -- are more appropriate.

Follow-up edit: Another possibility is provided by edit() as well as edit.data.frame().

Dirk Eddelbuettel
Thanks for the informative answer. I would disagree that "less" would be inappropriate - the main function for which I use less is to scroll string buffers in a console. The R console outputs lots of string buffers. I thought perhaps there might be a use here for buffer scrolling functionality.
fmark
You can always use `system("less")`... of course, if you use any of *NIX systems...
aL3xa
fmark: another possibility is provided by `edit()` and `edit.data.frame()` which you could try.
Dirk Eddelbuettel
aL3xa: Yes, but not for R objects.
Dirk Eddelbuettel
@Dirk edit(), while not ideal, does what I need. Thanks. If you write that out as an answer I will accept it.
fmark
@Dirk, yup... that's the catch... =)
aL3xa
fmark: I augmented my answer with a follow-up edit.
Dirk Eddelbuettel
+1  A: 

I save the print output to a file and then read it using an editor or less.

Type the following in R

sink("Routput.txt")
print(varname)
sink()

Then in a shell:

less Routput.txt
Sameer
A: 

If the file is already on disk, then you can use file.show

hadley
+4  A: 

There is also page() which displays a representation of an object in a pager, like less.

dat <- data.frame(matrix(rnorm(1000), ncol = 10))
page(dat, method = "print")
Gavin Simpson
Perfect, exactly what I was looking for!
fmark