Peng Yu
2010-Feb-03 16:01 UTC
[R] How to export the examples in help(something) to a file?
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?
Peng Yu
2010-Feb-03 16:02 UTC
[R] How to export the examples in help(something) to a file?
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.
Jorge Ivan Velez
2010-Feb-03 17:11 UTC
[R] How to export the examples in help(something) to a file?
Hi Peng, May be this is not the best way to do what you want, but it works for my proposes:> sink('example_lm.txt') > example(lm)Hit <Return> to see next plot:> sink()Then, I just look at the file "example_lm.txt" on my working directory. HTH, Jorge On Wed, Feb 3, 2010 at 11:01 AM, Peng Yu <> 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? > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Liaw, Andy
2010-Feb-04 20:18 UTC
[R] How to export the examples in help(something) to a file?
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. Andy Notice: This e-mail message, together with any attachme...{{dropped:10}}
Henrik Bengtsson
2010-Feb-04 22:34 UTC
[R] How to export the examples in help(something) to a file?
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. >
Peng Yu
2010-Feb-04 22:46 UTC
[R] How to export the examples in help(something) to a file?
On Thu, Feb 4, 2010 at 4:34 PM, Henrik Bengtsson <hb at stat.berkeley.edu> wrote:> 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] ""Thank you for the code!