25 Apr 2012

Reproducible Research: Running odfWeave with 7-zip

odfWeave is an R-package that is used for making dynamic reports by Sweave processing of Open Document Format (ODF) files. For anyone new to report generation and lacking knowledge of markup languages this might be a good starting point or even a true alternative to sweave / LATEX and others.

Now, anyone who recently tried to install the required zipping program for odfWeave might have noticed that there are currently no info-zip executables available (zip and unzip by info-zip software are suggested in the odfWeave manual). There are several other free zipping programs - but if you use these the default syntax for odfWeave changes. Looking into the internals it is revealed that the OS command specified for running the zipping program has to be adapted. There are some postings on the R-help mailing list concerning these topic, but none of them worked for me. After some trial and error I managed to get around this problem by using 7-zip with an adapted syntax and will share this here:

# write an in-file and save it to a folder:
dir()
[1] "Example_1_in.odt"

# testing the :
system("\"C:\\Program Files\\7-Zip\\7z.exe\" t -tzip Example_1_in.odt")

7-Zip 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Processing archive: Example_1_in.odt

Testing     mimetype
Testing     Configurations2\statusbar
Testing     Configurations2\accelerator\current.xml
Testing     Configurations2\floater
Testing     Configurations2\popupmenu
Testing     Configurations2\progressbar
Testing     Configurations2\menubar
Testing     Configurations2\toolbar
Testing     Configurations2\images\Bitmaps
Testing     content.xml
Testing     manifest.rdf
Testing     styles.xml
Testing     meta.xml
Testing     Thumbnails\thumbnail.png
Testing     settings.xml
Testing     META-INF\manifest.xml

Everything is Ok

Folders: 7
Files: 9
Size:       30139
Compressed: 9572

# setting up cmd prompt:
library(odfWeave)
ctrl <- odfWeaveControl(zipCmd =
           c("\"C:\\Program Files\\7-Zip\\7z.exe\" a $$file$$",
             "\"C:\\Program Files\\7-Zip\\7z.exe\" x -tzip $$file$$"))
# running:
odfWeave("Example_1_in.odt", "Example_1_out.odt", control = ctrl)

  Copying  Example_1_in.odt
  Setting wd to  C:\Users\Kay\AppData\Local\Temp\RtmpghYef5/odfWeave2223195249
  Unzipping ODF file using "C:\Program Files\7-Zip\7z.exe" x -tzip "Example_1_in.odt"

7-Zip 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Processing archive: Example_1_in.odt

Extracting  mimetype
Extracting  Configurations2\statusbar
Extracting  Configurations2\accelerator\current.xml
Extracting  Configurations2\floater
Extracting  Configurations2\popupmenu
Extracting  Configurations2\progressbar
Extracting  Configurations2\menubar
Extracting  Configurations2\toolbar
Extracting  Configurations2\images\Bitmaps
Extracting  content.xml
Extracting  manifest.rdf
Extracting  styles.xml
Extracting  meta.xml
Extracting  Thumbnails\thumbnail.png
Extracting  settings.xml
Extracting  META-INF\manifest.xml

Everything is Ok

Folders: 7
Files: 9
Size:       30139
Compressed: 9572

  Removing  Example_1_in.odt
  Creating a Pictures directory

  Pre-processing the contents
  Sweaving  content.Rnw

  Writing to file content_1.xml
  Processing code chunks ...

  'content_1.xml' has been Sweaved

  Removing content.xml

  Post-processing the contents
  Removing content.Rnw
  Removing styles.xml
  Renaming styles_2.xml to styles.xml
  Removing manifest.xml
  Renaming manifest_2.xml to manifest.xml
  Removing extra files

  Packaging file using "C:\Program Files\7-Zip\7z.exe" a "Example_1_in.odt"

7-Zip 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
Scanning

Creating archive Example_1_in.odt

Compressing  Configurations2\accelerator\current.xml
Compressing  content.xml
Compressing  manifest.rdf
Compressing  META-INF\manifest.xml
Compressing  meta.xml
Compressing  mimetype
Compressing  settings.xml
Compressing  styles.xml
Compressing  Thumbnails\thumbnail.png

Everything is Ok
  Copying  Example_1_in.odt
  Resetting wd
  Removing  C:\Users\Kay\AppData\Local\Temp\RtmpghYef5/odfWeave2223195249

  Done

# see the result:
dir()
[1] "Example_1_in.odt"  "Example_1_out.odt"

2 comments :

  1. This was helpful. Thanks so much!!!!

    ReplyDelete
  2. thanks, this solved my problem. very helpful

    ReplyDelete