[R] How to export the examples in help(something) to a file?
Henrik Bengtsson
hb at stat.berkeley.edu
Thu Feb 4 23:34:05 CET 2010
On Thu, Feb 4, 2010 at 9:18 PM, Liaw, Andy <andy_liaw at merck.com> wrote:
> From: Peng Yu
>>
>> On Wed, Feb 3, 2010 at 10:01 AM, Peng Yu <pengyu.ut at gmail.com> wrote:
>> > Some examples in the help page are too long to be copied
>> from screen.
>> > Could somebody let me know some easy way on how to extract
>> the example
>> > to a file so that I can play with them?
>>
>> I forget to mention. I use a terminal version of R.
>
> One possibility is to make a copy of example() to something else, and
> remove the last line where it source() the .Rex file, and modify it to
> suit your need.
Here is a version of that:
readExample <- function(...) {
exampleL <- utils::example;
environment(exampleL) <- new.env();
source <- function(zfile, ...) readLines(zfile);
exampleL(...);
} # readExample()
> readExample(diff);
[1] "### Name: diff"
[2] "### Title: Lagged Differences"
[3] "### Aliases: diff diff.default diff.POSIXt diff.Date"
[4] "### Keywords: arith"
[5] ""
[6] "### ** Examples"
[7] ""
[8] "diff(1:10, 2)"
[9] "diff(1:10, 2, 2)"
[10] "x <- cumsum(cumsum(1:10))"
[11] "diff(x, lag = 2)"
[12] "diff(x, differences = 2)"
[13] ""
[14] "diff(.leap.seconds)"
[15] ""
[16] ""
[17] ""
/H
>
> Andy
> Notice: This e-mail message, together with any attachme...{{dropped:10}}
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list