[R] R newbie example code question

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Fri Jan 13 16:45:53 CET 2006

On 13-Jan-06 Michael Friendly wrote:
> Ted:
> Your .xthelp is extremely useful, help on Linux being otherwise
> quite awkward to use since a pager in the same window make it hard
> to cut/paste examples --- where 'more' or 'less' really means
> 'instead of' :-)

Glad you found it useful. I find it indispensable!
For the record: this is not my code but Roger Bivand's,
it being the one out of several suggestions on that thread
which I decided to adopt. I still admire the neat way he
wrapped it all up.

One of the beautiful features is that *anything* which would
be paged comes up in the separate window, so for instance
you could execute in R


and you can then scan up and down, and cut&paste chunks if
you want, etc., and in several different windows for different
things at once (or even the same thing several times over if
you want to see different parts at the same time). Great for
playing with variants.

> Suggestion: include -title
> cat("cat > $HLPFIL\nxterm -title 'R-help' -e less $HLPFIL &\n", 
> file=con)
> <hint>It would be nice if this solution made it into the R-FAQ
> or R-Admin manual.</hint> Failing that, it is a good example of
> something that would work well in a wiki.  But, thankfully, you
> included the subject line from the original thread to make it
> searchable in the news archives.

A good <hint>! In fact a good place for it (or for a URL to it)
could be the help file for "help" and friends. In the circumstances,
this is where I would have looked first.</hint>

Best wishes,

> (Ted Harding) wrote:
>>   [R] help output paged in separate window
>> The solution I finally opted for, and still use,
>> is based (in a Linux environment) on including
>> the following code in your .Rprofile file:
>> .xthelp <- function() {
>>     tdir <- tempdir()
>>     pgr <- paste(tdir, "/pgr", sep="")
>>     con <- file(pgr, "w")
>>     cat("#! /bin/bash\n", file=con)
>>     cat("export HLPFIL=`mktemp ", tdir, "/R_hlp.XXXXXX`\n",
>>          sep="", file=con)
>>     cat("cat > $HLPFIL\nxterm -e less $HLPFIL &\n", file=con)
>>     close(con)
>>     system(paste("chmod 755 ", pgr, sep=""))
>>     options(pager=pgr)
>> }
>> .xthelp()
>> rm(.xthelp)
>> (and it's also specific to the 'bash' shell because
>> of the "#! /bin/bash\n", but you should be able to
>> change this appropriately). The above was posted by
>> Roger Bivand on 27 May.
>> When you start an R session, this code is executed as
>> part of sourcing your .Rprofile, and it has the effect that
>> any output from R which would be paged is stored in a
>> temporary  file which is then read by 'less' in a
>> separate X window which is detached from your R session
>> (i.e. your command interface will not hang while it is
>> being displayed). You can close the X window displaying
>> the 'less' output by closing 'less' (e.g. type "q"), or
>> you can leave it open and any new paged output will go
>> into a new window -- so you can for instance do
>> ?glm
>> ?family
>> ?binomial
>> and you will have three mutually relevant help windows
>> open at once between which you can cross-reference.
>> As to extracting the code for examples, this is easy
>> in X windows since you just use your mouse: left-button
>> drag to hghlight a block of text, middle-button click
>> to paste the block into another window (of course the
>> mouse must be over the correct window!)
>> So you can use the mouse to copy code from the "help"
>> pages to the command window.
>> As I say, this is a Linux-oriented solution, and I don't
>> know what details would be required for anything similar
>> in a Windows environment.
>> It is also worth reading the various contributions to
>> the above thread, since several suggestions were made.
>> Hoping this helps,
>> Ted.
>> --------------------------------------------------------------------
>> E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
>> Fax-to-email: +44 (0)870 094 0861
>> Date: 10-Jan-06                                       Time: 13:30:35
>> ------------------------------ XFMail ------------------------------
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
> -- 
> Michael Friendly     Email: friendly AT yorku DOT ca
> Professor, Psychology Dept.
> York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
> 4700 Keele Street    http://www.math.yorku.ca/SCS/friendly.html
> Toronto, ONT  M3J 1P3 CANADA

E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 13-Jan-06                                       Time: 15:45:47
------------------------------ XFMail ------------------------------

More information about the R-help mailing list