[R] R newbie example code question

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Tue Jan 10 14:30:37 CET 2006


On 09-Jan-06 Mark Leeds wrote:
> Sometimes I print out a package
> and read about it and there
> are sometimes nice examples
> that I would like to run myself.
>  
> Is there a way to bring them
> into R from the package or
> are they only meant to be typed
> in manually ? If manual is the
> only way, that's fine. I was
> just checking whether there was
> a quicker way. Thanks.
>  
>                            Mark

I had the same issue many moons ago, and for the
same reasons! It was discussed in a fairly extended,
and interesting, thread from 24-27 May 2003 -- go to
the R-help archives for that month, by thread, and
find the thread

  [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 ------------------------------




More information about the R-help mailing list