[R] odfWeave problem

Sarah Goslee sarah.goslee at gmail.com
Fri Dec 22 15:52:55 CET 2006


Sorry, I zipped you off a reply without actually having OpenOffice
available - never wise.

First, both "right" and "end" work for me as alignment specifications,
though OpenOffice itself seems to use "end".

Here's the R code I'm using to define the styles:


	# Now to specify the styles themselves
	# The default list has 10 styles in it right now.
	existingStyles <- getStyleDefs()

	# Use one of the cell styles as a template for the new cell style
	# The style definition contains information on background
	# color, alignment, and borders.


	# Style 3 is a bit different. Here I want to change the text color,
	# which is specified in a different style definition.
	newStyle3 <- existingStyles$ArialCentered
	newStyle3$fontColor <- "#0000cc"
   newStyle3$textAlign <- "right"


	# Finally, the new styles need to be set.
	existingStyles <- c(existingStyles, newStyle1=list(newStyle1),
newStyle2=list(newStyle2), newStyle3=list(newStyle3))
	setStyleDefs(existingStyles)

And here's the code block from the ODF document:


<<Table1,echo=FALSE,results=xml>>=
	# here's the same example data as in table 1
	x <- data.frame(Var1=1:3, Var2=4:6, Var3=7:9, row.names=c("A", "B", "C"))

	# Here's a matrix specifying the desired styles for each cell in the table
	# This could be p-values for the correlations in x, for example. For
	# this example, I'm just making it up. There are three possible styles,
	# as well as the default style.
	# The style matrix must have an additional column for the row names.
	y <- matrix(c(0, 0, 0, 1,0,0,3,0,1,2,0,2), byrow=FALSE, nrow=3, ncol=4)
	y <- data.frame(y)
	colnames(y) <- c("rownames", "Var1", "Var2", "Var3")


	# Now, to specify when to use these new styles.
	# tableStyles() will provide the default styles for each
	# element of x
	# note that I'm creating the styles for x based on y,
	# which already has the extra column for row names.
	x.styles <- tableStyles(y, header=colnames(y))

	# every element of x has two associated styles
	# for the cells, text style is in text and cell style is in cells
	# for headers, it is in header and headerCell

	# newStyle3 is a text style.
	x.styles$text[y == 3] <- "newStyle3"


	odfTable(x, useRowNames = TRUE, styles = x.styles)
@

I hope this example is more helpful than my previous email!

If you are interested, I have a longer, heavily-commented, example
of figure and table styles for odfWeave that I'm planning to put
online shortly. I'd be happy to send you a copy.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list