# Yet another R report generator, and more!

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!

## 5 thoughts on “Yet another R report generator, and more!”

1. HenrikB

See also the R.rsp package for RSP markup language (very similar to what brew also introduced; yes, I'm the author). Contrary to *weave-like markup languages, it handles also the important user case of looping over mixtures of code and text chunks, e.g.

Counting to ten: .

> library("R.rsp");
> sourceRsp(text="Counting to ten: ");
Counting to ten: 1 2 3 4 5 6 7 8 9 10

1. BioStatMatt Post author

Henrik,

I just noticed R.rsp yesterday while browsing the task views. This package (yarr) doesn't support 'incomplete' R expressions in a way that allows this type of looping, like brew (and apparently R.rsp) does. That is, all delimited code must consist of complete R expressions. I haven't implemented this feature, mostly because it adds significant complexity to the parser. Also, yarr has at least one feature that isn't compatible with this type of looping, namely on-the-fly modification of it's syntax (see for example the citation.yarr file that comes with the package).

Best,
Matt

P.S. Sorry your code didn't post well, I recently updated WordPress to 3.1 and there are some lingering issues. If you email me the code how it should have read, I'll fix it.

2. HenrikB

I guess your blog does not allow for pasting in "HTML-like" markup code snippets; so my reply is complete useless. Cheers

3. float

The site for mortcalc is down. I'd really like to see that as it sounds extremely cool.

regards