Emmanuel Charpentier
2009-Jun-30 22:08 UTC
[R] odfWeave : problems with odfInsertPlot() and odfFigureCaption()
Dear Max, dear list, I have trouble using odfInsertPlot to insert plots outside fig=TRUE chunks. My goal is to dump a bunch of (relatively uninteresting, but required) graphs from within a loop, possibly interspeded with some tables. This is not possible within a normal fig=TRUE chunk. odfInsertPlot() is able to insert a previously saved plot. When used in a fig=TRUE, results=hide chunk, it produces just a blank frame (with a caption if caption=odfFigureCaption() is used). Used in a fig=TRUE, results=xml chunk, it produces an error at file rte-assembly (see end of post). However, when wrapped in a cat(), the same code produces 1) the figure (without caption), then a blank frame with the caption, or just the figure (without caption) if the caption=() argument is absent. The same cat(odfInsertPlot()) construct can be used in a results=xml chunk (no fig=TRUE) ; however, I found no way to insert the caption. Therefore : I can programmatically create graphs and insert them via results=xml chunks, but I can't caption them. Do someone has a workaround (except reprogramming odfFigureCaption() with a new argument taking the output of odfInsertPlot()) ? Sincerely, Emmanuel Charpentier Annex : log of compilation with fig=true, results=xml.> odfWeave("Test1Src.odt", "Test1.odt")Copying Test1Src.odt Setting wd to /tmp/RtmpenMTgz/odfWeave3023572231 Unzipping ODF file using unzip -o Test1Src.odt Archive: Test1Src.odt extracting: mimetype inflating: content.xml inflating: layout-cache inflating: styles.xml extracting: meta.xml inflating: Thumbnails/thumbnail.png inflating: Configurations2/accelerator/current.xml creating: Configurations2/progressbar/ creating: Configurations2/floater/ creating: Configurations2/popupmenu/ creating: Configurations2/menubar/ creating: Configurations2/toolbar/ creating: Configurations2/images/Bitmaps/ creating: Configurations2/statusbar/ inflating: settings.xml inflating: META-INF/manifest.xml Removing Test1Src.odt Creating a Pictures directory Pre-processing the contents Sweaving content.Rnw Writing to file content_1.xml Processing code chunks ... 1 : term hide(label=Prol?gom?nesStandard) 2 : term xml(label=EssaiGraphe1) 3 : echo term verbatim(label=TestChunk) 4 : term xml(label=SecondChunk) 'content_1.xml' has been Sweaved Removing content.xml Post-processing the contents error parsing attribute name attributes construct error xmlParseStartTag: problem parsing attributes Couldn't find end of Start Tag draw:frame line 6 error parsing attribute name attributes construct error xmlParseStartTag: problem parsing attributes Couldn't find end of Start Tag draw:image line 6 Opening and ending tag mismatch: text:p line 6 and draw:frame Opening and ending tag mismatch: office:text line 2 and text:p Opening and ending tag mismatch: office:body line 2 and office:text Opening and ending tag mismatch: office:document-content line 2 and office:body Extra content at the end of the document Erreur : 1: error parsing attribute name 2: attributes construct error 3: xmlParseStartTag: problem parsing attributes 4: Couldn't find end of Start Tag draw:frame line 6 5: error parsing attribute name 6: attributes construct error 7: xmlParseStartTag: problem parsing attributes 8: Couldn't find end of Start Tag draw:image line 6 9: Opening and ending tag mismatch: text:p line 6 and draw:frame 10: Opening and ending tag mismatch: office:text line 2 and text:p 11: Opening and ending tag mismatch: office:body line 2 and office:text 12: Opening and ending tag mismatch: office:document-content line 2 and office:body 13: Extra content at the end of the document>
Max Kuhn
2009-Jul-01 01:36 UTC
[R] odfWeave : problems with odfInsertPlot() and odfFigureCaption()
Well, on this one, I might bring my record down to commercial software bug fix time lines...> I have trouble using odfInsertPlot to insert plots outside fig=TRUE > chunks. > > My goal is to dump a bunch of (relatively uninteresting, but required) > graphs from within a loop, possibly interspeded with some tables. This > is not possible within a normal fig=TRUE chunk. > > odfInsertPlot() is able to insert a previously saved plot. When used in > a fig=TRUE, results=hide chunk, it produces just a blank frame (with a > caption if caption=odfFigureCaption() is used). > > Used in a fig=TRUE, results=xml chunk, it produces an error at file > rte-assembly (see end of post). However, when wrapped in a cat(), the > same code produces 1) the figure (without caption), then a blank frame > with the caption, or just the figure (without caption) if the caption=() > argument is absent. > > The same cat(odfInsertPlot()) construct can be used in a results=xml > chunk (no fig=TRUE) ; however, I found no way to insert the caption. > > Therefore : I can programmatically create graphs and insert them via > results=xml chunks, but I can't caption them.We had to do some interesting things to get figure captions working with odfWeave. You would think that the figure caption function just write out some xml and are done (like the insert plot code and the table caption code). Unfortunately, it doesn't. It writes the caption to a global variable (I know, I know) and other code actually writes the caption. We had good reason to do this, mostly related to the complexity associated with the context of the code chunk (e.g. was it inside a table, at paragraph, etc). I've been thinking about this one for a while since the current implementation doesn't allow you to pass the figure caption to other functions (it writes a global variable and returns NULL). I haven't come up with a good solution yet. <aside> I've not been as prompt with odfWeave changes in comparison to other packages (many of you have figured this out). This is mostly due to the necessary complexity of the code. In a lot of ways, I think that we let the feature set be too rich and should have put some constrains on the availability of code chunks (e.g. only in paragraphs). I want to add more features (like the one that you are requesting), but seemingly small changes end up being a considerable amount of work (and I don't time). I've been thinking about simplifying the code (or writing rtfWeave) to achieve the same goals without such a complex system. The ODF format is a double-edged sword. It allows you to do many more things than something like RTF, but makes it a lot more difficult to program for. Take tables as an example. The last time I looked at the RTF specification, this was a simple markup structure. In ODF, the table structure is somewhat simple, but the approach to formatting the table is complex and not necessarily well documented. For example, some table style elements go into styles.xml whereas others go into contest.xml (this might be implementation dependent) So, I could more easily expand the functionality of odfWeave by imposing some constraints about where the code chunks reside. The earlier versions of odfWeave did not even parse the xml; we got a lot done via regular expressions and gsub. However, we went to a xml parsing approach when we found out that the context of the code chunk matters. Feedback is welcome: do people actually use code chunks in places other than paragraphs? </aside> So, back to your question, the relevant code for captions is in odfWeave:::withCaptionXML (odfInsertPlot uses this to write the xml). You can try that and I might be able to look at it in the next few days. Thanks, Max