On Thu, Feb 4, 2010 at 4:34 PM, Henrik Bengtsson <h...@stat.berkeley.edu> wrote:
> On Thu, Feb 4, 2010 at 9:18 PM, Liaw, Andy <andy_l...@merck.com> wrote:
>> From: Peng Yu
>>>
>>> On Wed, Feb 3, 2010 at 10:01 AM, Peng Yu <pengyu...@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] ""

Thank you for the code!

______________________________________________
R-help@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.

Reply via email to