XML Processing Functions {odfWeave} | R Documentation |
These function takes a character vector of XML for the Open Document Format and process it it various ways.
odfTranslate
converts some XML modified characters (such as
>
) to R code (>
). This function also tries to mistake proof the code by anticipating characters that might be in UTF-8 encoding to R compliant characters (e.g. OpenOffice may convert some characters. For example, " will become a UTF-8 character, which R will choke on).
stripXmlTag
removes any text between "<" and ">" and optionally remove leading or trailing whitespace.
processInLine
uses odfTranslate
and stripXmlTag
to process in-line Sweave
statements. Similarly, xml2R
does the same thing for code chunks.
odfTranslate(x, toR = TRUE) stripXmlTag(x, leadWhite = FALSE, endWhite = FALSE) processInLine(x, matches) xml2R(x)
x |
a character vector |
toR |
a logical. If TRUE , the text is translated from XML to R. The opposite is done if FALSE . |
leadWhite |
a logical for removing leading white space |
endWhite |
a logical for removing tailing white space |
matches |
an integer vector with the character positions of any Sweave tags. matches must contain attributes match.length and match.type which are the length of the tag and the type (e.g. "sepxr"), respectively |
a character vector
Max Kuhn and Nathan Coulter
x <- " <text:p text:style-name=\"P3\"><text:s text:c=\"3\"/>lm(y~x)</text:p>" y <- "\Sexpr{paste(letters[1:5], <text:s text:c=\"2\"/>collapse = ",")}" z <- " <text:span text:style-name=\"T1\">\Sexpr{x > 2}</text:span>" stripXmlTag(x) odfTranslate(y) xml2R(y) #processInLine(z)