3

I use odfWeave for purposes of reproducible research. I've discovered it generally works well on MS Office 2007 using .odt files generated in Word, but \Sexpr{} commands almost always fail. I suspect Word is treating the underlying XML in a strange way, but I'm curious if anyone has seen that problem and figured out how to make it work.

Thanks,

Bill

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
Bill
  • 533
  • 1
  • 4
  • 16
  • A reproducible example would help. – Dirk Eddelbuettel Mar 20 '11 at 03:28
  • Fair request, Dirk. The next time I'm at that Windows machine (likely early next week), I'll generate something. – Bill Mar 20 '11 at 03:36
  • I did a simple document that says "<>= library(arm) @ Lorem ipsum \Sexpr{mean(rnorm(50))} and more lorem ipsum. "What I get out is "Lorem ipsum mean(rnorm(50))} and more lorem ipsum." – Bill Mar 21 '11 at 19:21
  • The problem is that, at least in some cases, Word puts XML markup around the \Sexpr. For example, content.xml includes `text:style-name="T19">\Sexpr{mean(rnorm(50))} – Bill Mar 21 '11 at 19:31
  • That's not so easy, Dirk. If I create a memo, I end up with small text blocks in Word that break odfWeave. If I create a document from scratch, I don't, probably because my example documents are too simple. I found an O'Reilly article yesterday that pointed out a similar problem with Word and odt, but I can't find it. Their solution involved finding a way to configure Word to not issue certain page breaks on certain styles. – Bill Mar 22 '11 at 20:48
  • Now I find it: [link](http://broadcast.oreilly.com/2009/05/is-sp2-no-good-or-is-odf-no-go.html). I don't think it directly applies, but the solution (tear apart the odt file and search for ways to get Word to stop breaking the Sexpr{} tag apart) seems promising. It also seems like a good way to lose a lot of time. Any ideas? – Bill Mar 22 '11 at 20:51

2 Answers2

2

My not use odfCat? E.g.:

> odfCat(mean(runif(100)))
<text:p text:style-name="ArialNormal">0.4411</text:p>

Also see this post, might be related. Good luck anyway!

daroczig
  • 28,004
  • 7
  • 90
  • 124
  • Thanks! odfCat worked, although it's not quite the inline code of \Sexpr. Now I have to read up on how to format the results of code chunks. :-) If anyone knows how to keep Word from breaking up \Sexpr expressions, I'm still interested, but this certainly suffices. – Bill Mar 24 '11 at 23:38
0

I've had the same problem. And I have found (by examining content.xml inside the .odt) that often LibreOffice will insert various inline formatting markup inside \Sexpr{...}, thereby preventing odfWeave() from working.

The solution to that is simply to mark the \Sexpr{...} (or the entire paragraph, or the entire document) inside LibreOffice Writer and click on "Clear direct formatting". I've never had an \Sexpr{...} that didn't work after doing this!

Theodore Lytras
  • 3,955
  • 1
  • 18
  • 25