[R] odfWeave : problems with odfInsertPlot() and odfFigureCaption()
Emmanuel Charpentier
charpent at bacbuc.dyndns.org
Wed Jul 1 09:07:31 CEST 2009
Dear Max,
Le mardi 30 juin 2009 à 21:36 -0400, Max Kuhn a écrit :
> Well, on this one, I might bring my record down to commercial software
> bug fix time lines...
Having actually looked at the code before wailing, I had such a hunch...
[ Snip ... ]
> 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.
ISTR from my Lisp/Scheme days that a good heuristic in this kind of case
is to try to build a closure and return that to a wrapper.
Unfortunately, R doesn't have anything as simple to use as let/let*, and
you have to play fast and loose with environments...
> <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 didn't even think of this. A priori, that's hard to do (whereas
(\La)Texw will need "\par" or *two* newlines to end a paragraph and
start another, oowriter will take one newline as an end of paragraph and
will emit the corresponding XML.
Come to think of it, you might try to insert a chunk in a table case, or
in a footnote...
And I don't know about other ODF tools...
> 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.
What about something along the line of :
foo<-odfTable(something)
bar<-odfInsertPlot(somethingelse)
odfCaptionize(foo,"Something")
odfCaptionize(bar("Something else")
?
> 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.
Indeed...
> 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>
I didn't even think of it. But now that you tell it, you got me a nice
idea for a workaround ... :-)
> 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.
I did look that. Tjhe problem is that your code has dire warnings not to
call it with a caption more than once in a figure=TRUE (sic..) chunk.
> Thanks,
*I* thank *you, Max,
Emmanuel Charpentier
More information about the R-help
mailing list