Yet another R report generator, and more!

March 4, 2011
By

(This article was first published on BioStatMatt » R, and kindly contributed to R-bloggers)

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 his blog: BioStatMatt » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , , , ,

Comments are closed.