useR day four and beginner’s odfWeave

I’m a bit late with the report from the last day of the useR conference, I was very busy Thursday getting home and catching up with the housework on Friday. I once again favoured sessions about graphics and best in show must go to Easy interactive ggplots, particularly for a bit of a coding novice like myself. I’m going to take some of the ideas from this talk and use them at work, it will blow everyone’s mind (well, doing it for free with blow everyone’s mind, anyway) so a big thank you to Richie for sharing his ideas and his code.

Since I got home I’ve been manfully struggling with odfWeave again, so I’m going to give a quick guide for new starters like myself in the hope that someone’s Google search for “odfWeave problems” or the suchlike will point them here. It’s for beginners, so if you’re not a beginner then you may as well skip this bit and go for a walk or something.

1) DON’T use windows. Even if you can get the zip/ unzip bit working, which I did eventually, you’ll hit a problem when you want to use an older version of the XML library (which you have to, see below)- unless you’re going to compile it yourself. If you’re going to compile it yourself, you clearly have a different definition of the word “beginner” than I do, and congratulations you on being so modest.

2) DO downgrade your XML version (or if you haven’t installed it yet, never install 3.4 in the first place). It’s dead easy to do, just go here and download the 3.2 version, which works beautifully. (use the install.packages() command with a pointer to the file, or if you use the fabulous RStudio, which I deeply love, then they have an option to use a downloaded file after their install packages button).

I think you should be pretty okay after that. I still got confused by some of the code snippets, so let’s just have a quick round-up of stuff you might want to do and how to do it.

Inline code is just like Sweave, so it’s


Blocks of code, also, are just like Sweave. Just in case you get in a muddle, which to be honest I did:

1) Code you want to print (for presentations etc.:


Code chunk finished with @

2) Code you want a graphic out of:

<<fig=TRUE, echo=FALSE>>=

DON’T forget to encapsulate ggplot2 commands like ggplot and qplot in a print() because of some technical reason that essentially means “that’s just how you do it”. Code chunk finished with @

3) Code you want a table out of:

tempmat=matrix(with(mydata, table(Ethnicity, Control)), ncol=2)
row.names(tempmat)=row.names(with(mydata, table(Ethnicity, Control)))

odfTable(tempmat, useRowNames=TRUE, colnames=c("", "Control", "Treatment"))

You’ll use the odfTable command, which does NOT work on table() objects, just turn them into a matrix or a dataframe and they work fine. Notice how I’ve put the row and column names in as well, it does mention it in the help file, but that’s how you do it anyway. Code chunk finished with @

I think that should be enough to get you started. I wish I’d read this post about 3 months ago, because I’ve been fiddling with odfWeave on and off since then (I started on Windows, I think that was my main mistake really, couldn’t get the zip and unzip commands to work for ages).

Here’s the first bit of the code from a report I’m writing to give you an idea.

This was compared by comparing the distribution and median of the age of individuals in each group.

<<fig=FALSE, echo=FALSE>>=


mydata$Control=factor(mydata$Control, labels=c("Control", "Treatment"))


<<fig=TRUE, echo=FALSE>>=


mydata$DOB2=as.Date(mydata$DOB, format="%Y-%m-%d", origin="1899-12-30")


qplot(DOB2, data=mydata, geom="density", colour= Control, main="Median DOB marked blue for treatment, red for control", xlab="Date of birth", ylab="Density") + 
	geom_vline(xintercept = median(subset(mydata, Control=="Treatment")$DOB-25569), col="blue", lty=2) + 
	geom_vline(xintercept = median(subset(mydata, Control=="Control")$DOB-25569), col="red", lty=2) 


Ethnicity within treatment and control is shown below.

# "Ethnicity"

tempmat=matrix(with(mydata, table(Ethnicity, Control)), ncol=2)
row.names(tempmat)=row.names(with(mydata, table(Ethnicity, Control)))

odfTable(tempmat, useRowNames=TRUE, colnames=c("", "Control", "Treatment"))


5 thoughts on “useR day four and beginner’s odfWeave”

  1. I use Sweave and LaTeX, but my collaborators don’t. I wanted to try odfWeave for their benefit. HOWEVER, your first “Don’t” seems pretty much like a non-starter. While I use Mac and Linux, most of my key collaborators use Windows. Has this (these) issue(s) gotten any better?

    1. As far as I know, they haven’t. I don’t think it’s impossible to use Windows, but it’s fiddly, certainly.

      I have switched away from using ODFWeave myself now and instead write Sweave syntax that produces .png graphics, then use latex2rtf to produce an RTF file. The resulting output needs a little tidying, but it’s pretty painless and simple. Hope that’s of some use.

  2. Hmm, I actually don’t know. I’m guessing that it does not depend on it. I don’t have computer without LaTeX on to test.

    Incidentally, I never could get the GUI working, so you may want to tell your collaborators to use the command line (very simple, so it shouldn’t matter how tech-y there are).

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.