Is there an equivalent to the unix less
command that can be used within the R console?
views:
183answers:
4
+6
A:
Not really. There are the commands
head()
andtail()
for showing the beginning and end of objectsprint()
for explicitly showing an object, and just its name followed by return does the samesummary()
for concise summary that depends on the objectstr()
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
2010-05-16 04:27:29
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
2010-05-16 05:02:00
You can always use `system("less")`... of course, if you use any of *NIX systems...
aL3xa
2010-05-16 05:32:59
fmark: another possibility is provided by `edit()` and `edit.data.frame()` which you could try.
Dirk Eddelbuettel
2010-05-16 11:34:36
aL3xa: Yes, but not for R objects.
Dirk Eddelbuettel
2010-05-16 11:35:00
@Dirk edit(), while not ideal, does what I need. Thanks. If you write that out as an answer I will accept it.
fmark
2010-05-16 12:14:09
@Dirk, yup... that's the catch... =)
aL3xa
2010-05-16 13:46:40
fmark: I augmented my answer with a follow-up edit.
Dirk Eddelbuettel
2010-05-16 13:51:21
+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
2010-05-16 13:06:59
+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
2010-10-01 09:19:30