Yet another R report generator, and more!

[This article was first published on BioStatMatt » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I recently uploaded some code to R-forge related to an R package I’ve been working on, titled yarr. The work was motivated by a desire to embed R code and output within my HTML blog posts! Months ago, I wrote about a potential solution to this using the brew package.

yarr is a new, but fully operational battle station R package that facilitates mixing delimited R code with text, including text with other markup (e.g. HTML, LaTeX). The functionality of yarr has some intersection with that of the brew package and the R function Sweave. However, the yarr package is designed with flexibility and extensibility in mind. No other R package of this kind offers flexible syntax, on-the-fly extension, and facilities for handling various types of input and output simultaneously.

Like the brew package, yarr is designed to work with the Apache module rapache to facilitate dynamic web applications powered by R. This mortgage calculator demonstrates the combined use of yarr and rapache. By the way, this mortgage calculator upgrades and extends some R code I posted earlier. In that post, there are graphics I thought were OK at the time. But soon afterward, Dirk Eddelbuettel posted a beautiful graphic that made mine look like toddler scribbles. The new mortgage amortization graphic improves on the original. Here’s the mortgage calculator source; 100% R and HTML: MortCalc.yarr.

Download the nightly build of yarr here yarr_0.0.tar.gz. Or, install from R with

> install.packages("yarr", repos="http://R-Forge.R-project.org")

The following yarr file (from the package examples) illustrates a simple case where R code delimited by ‘<<’ and ‘>>’ is mixed with text to form an email message to the R-help mailing list.

Dear R-Help,
<<
# Function to format and cat the date
d <- function() cat(format(Sys.time(), "%m-%d-%Y"))
>>
I want to write an email that contains R code and output, as if I
had entered the code at the R prompt. For example:
<<@
f <- function(x) {
    x+1
}
f(1)
stem(rnorm(50))
>>
Is there a way to do that without copy and pasting from R?
Also, is there a way to include the date (<<= d() >>) in the
text of my email?

Regards,
useR

Evaluating this file with a call to yarr, say yarr::yarr('email.yarr') yields the following output, which could be pasted into an email editor and mailed to the R-help list.

Dear R-Help,

I want write an email that contains R code and output, as if I
had entered the code at the R prompt. For example:
> f <- function(x) {
+     x+1
+ }
> f(1)
[1] 2
> stem(rnorm(50))

  The decimal point is at the |

  -2 | 1
  -1 | 97766
  -1 | 4320
  -0 | 8887655
  -0 | 4321100
   0 | 000122344
   0 | 566777
   1 | 00003344
   1 | 568

Is there a way to do that without copy and pasting from R?
Also, is there a way to include the date (03-03-2011) in the
text of my email?

Regards,
useR

Suggestions, ideas, and contributions to yarr are very welcome!

To leave a comment for the author, please follow the link and comment on their blog: BioStatMatt » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)