Paul Miller
2013-Apr-11 20:40 UTC
[R] odfWeave: Some questions about potential formatting options
Hello All, Learning to use the odfWeave package. I really like the package. It has good documentation, makes some very nice looking tables, and seems to have lots of options for customizing output. There are a few things I'd like to do that don't seem to be covered in the documentation though. So I'm not sure if they're possible or not. Here's a list of some things I'd like to be able to do: 1. Make titles generated by odfTableCaption/odfFigureCaption bold 2. Add footnotes to tables (using something other than odfCat) 3. Control the width of columns 4. Control the alignment of columns (first column left and centered otherwise) Is it possible to do any or all of these things using odfWeave? Thanks, Paul
Milan Bouchet-Valat
2013-Apr-12 09:10 UTC
[R] odfWeave: Some questions about potential formatting options
Le jeudi 11 avril 2013 ? 13:40 -0700, Paul Miller a ?crit : Hello All,> > Learning to use the odfWeave package. I really like the package. It has good documentation, makes some very nice looking tables, and seems to have lots of options for customizing output. > > There are a few things I'd like to do that don't seem to be covered in the documentation though. So I'm not sure if they're possible or not. > > Here's a list of some things I'd like to be able to do: > > 1. Make titles generated by odfTableCaption/odfFigureCaption bold > > 2. Add footnotes to tables (using something other than odfCat) > > 3. Control the width of columns > > 4. Control the alignment of columns (first column left and centered otherwise) > > Is it possible to do any or all of these things using odfWeave? > For points 1 and 4, you have to use a style, and edit the style via LibreOffice to make the text bold or change its alignement. See tableStyles() for the latter.For point 3 (column widths), I needed to make small changes to odfWeave to support that part of the ODF spec. I've sent them to Max Kuhn for review, but so far he probably could not find the time to study them. If you are interested, you can grab the modified version of the package from here : http://nalimilan.perso.neuf.fr/transfert/odfWeave.tar.gz Then you can set the width like that: currentDefs <- getStyleDefs() currentDefs$firstColumn$type <- "Table Column" currentDefs$firstColumn$columnWidth <- "5 cm" currentDefs$secondColumn$type <- "Table Column" currentDefs$secondColumn$columnWidth <- "3 cm" setStyleDefs(currentDefs) Then you can use these styles this way: odfTable(df, styles=style, ???????? colStyles=c("firstColumn", "secondColumn")) For point 2, I'm not sure what you mean. Do you want to include a legend below the table, or do you want to use real footnotes? Regards
Paul Miller
2013-Apr-16 17:15 UTC
[R] odfWeave: Some questions about potential formatting options
Hi Milan and Max, Thanks to each of you for your reply to my post. Thus far, I've managed to find answers to some of the questions I asked initially. I am now able to control the justification of the leftmost column in my tables, as well as to add borders to the top and bottom. I also downloaded Milan's revised version of odfWeave at the link below, and found that it does a nice job of controlling column widths. http://nalimilan.perso.neuf.fr/transfert/odfWeave.tar.gz There are some other things I'm still struggling with though. 1. Is it possible to get odfTableCaption and odfFigureCaption to make the titles they produce bold? I understand it might be possible to accomplish this by changing something in the styles but am not sure what. If someone can give me a hint, I can likely do the rest. 2. Is there any way to get odfFigureCaption to put titles at the top of the figure instead of the bottom? I've noticed that odfTableCaption is able to do this but apparently not odfFigureCaption. 3. Is it possible to add special characters to the output? Below is a sample Kaplan-Meier analysis. There's a footnote in there that reads "Note: X2(1) = xx.xx, p = .xxxx". Is there any way to make the X a lowercase Chi and to superscript the 2? I did quite a bit of digging on this topic. It sounds like it might be difficult, especially if one is using Windows as I am. Thanks, Paul ################## #### Get data #### ################## #### Load packages #### require(survival) require(MASS) #### Sample analysis #### attach(gehan) gehan.surv <- survfit(Surv(time, cens) ~ treat, data= gehan, conf.type = "log-log") print(gehan.surv) survTable <- summary(gehan.surv)$table survTable <- data.frame(Treatment = rownames(survTable), survTable, row.names=NULL) survTable <- subset(survTable, select = -c(records, n.max)) ################## #### odfWeave #### ################## #### Load odfWeave #### require(odfWeave) #### Modify StyleDefs #### currentDefs <- getStyleDefs() currentDefs$firstColumn$type <- "Table Column" currentDefs$firstColumn$columnWidth <- "5 cm" currentDefs$secondColumn$type <- "Table Column" currentDefs$secondColumn$columnWidth <- "3 cm" currentDefs$ArialCenteredBold$fontSize <- "10pt" currentDefs$ArialNormal$fontSize <- "10pt" currentDefs$ArialCentered$fontSize <- "10pt" currentDefs$ArialHighlight$fontSize <- "10pt" currentDefs$ArialLeftBold <- currentDefs$ArialCenteredBold currentDefs$ArialLeftBold$textAlign <- "left" currentDefs$cgroupBorder <- currentDefs$lowerBorder currentDefs$cgroupBorder$topBorder <- "0.0007in solid #000000" setStyleDefs(currentDefs) #### Modify ImageDefs #### imageDefs <- getImageDefs() imageDefs$dispWidth <- 5.5 imageDefs$dispHeight<- 5.5 setImageDefs(imageDefs) #### Modify Styles #### currentStyles <- getStyles() currentStyles$figureFrame <- "frameWithBorders" setStyles(currentStyles) #### Set odt table styles #### tableStyles <- tableStyles(survTable, useRowNames = FALSE, header = "") tableStyles$headerCell[1,] <- "cgroupBorder" tableStyles$header[,1] <- "ArialLeftBold" tableStyles$text[,1] <- "ArialNormal" tableStyles$cell[2,] <- "lowerBorder" #### Weave odt source file #### fp <- "N:/Studies/HCRPC1211/Report/odfWeaveTest/" inFile <- paste(fp, "testWeaveIn.odt", sep="") outFile <- paste(fp, "testWeaveOut.odt", sep="") odfWeave(inFile, outFile) ###################################### #### Contents of .odt source file #### ###################################### Here is a sample Kaplan-Meier table. <<testKMTable, echo=FALSE, results = xml>>odfTableCaption(?A Sample Kaplan-Meier Analysis Table?) odfTable(survTable, useRowNames = FALSE, digits = 3, colnames = c("Treatment", "Number", "Events", "Median", "95% LCL", "95% UCL"), colStyles = c("firstColumn", "secondColumn", "secondColumn", "secondColumn", "secondColumn", "secondColumn"), styles = tableStyles) odfCat(?Note: X2(1) = xx.xx, p = .xxxx?) @ Here is a sample Kaplan-Meier graph. <<testKMFig, echo=FALSE, fig = TRUE>>odfFigureCaption("A Sample Kaplan-Meier Analysis Graph", label = "Figure") plot(gehan.surv, xlab = "Time", ylab= "Survivorship") @
Paul Miller
2013-Apr-22 16:27 UTC
[R] odfWeave: Some questions about potential formatting options
Hi Milan and Max, ? Thanks for your most recent replies.?I wasn't able to sucessfully implement any of your proposed solutions, but am not overly worried about it. For example, I found that I could not get the Greek letter chi into my table footnotes via odfCat using unicode or escape codes (I think because I'm using Windows). I can easily work around this though. The actual tables themselves are the most important thing and I'm really pleased with what I've gotten using odfWeave. Thanks again. Paul --- On Wed, 4/17/13, Milan Bouchet-Valat <nalimilan at club.fr> wrote: From: Milan Bouchet-Valat <nalimilan at club.fr> Subject: Re: [R] odfWeave: Some questions about potential formatting options To: "Paul Miller" <pjmiller_57 at yahoo.com> Cc: "Max Kuhn" <mxkuhn at gmail.com>, r-help at r-project.org Received: Wednesday, April 17, 2013, 11:17 AM Le mardi 16 avril 2013 ? 10:15 -0700, Paul Miller a ?crit :> Hi Milan and Max, > > Thanks to each of you for your reply to my post. Thus far, I've > managed to find answers to some of the questions I asked initially. > > I am now able to control the justification of the leftmost column in > my tables, as well as to add borders to the top and bottom. I also > downloaded Milan's revised version of odfWeave at the link below, and > found that it does a nice job of controlling column widths. > > http://nalimilan.perso.neuf.fr/transfert/odfWeave.tar.gz > > There are some other things I'm still struggling with though. > > 1. Is it possible to get odfTableCaption and odfFigureCaption to make > the titles they produce bold? I understand it might be possible to > accomplish this by changing something in the styles but am not sure > what. If someone can give me a hint, I can likely do the rest.Just right-click on a caption and choose "Edit paragraph style..." (in the template document). Or edit the styles called Table and Illustration.> 2. Is there any way to get odfFigureCaption to put titles at the top > of the figure instead of the bottom? I've noticed that odfTableCaption > is able to do this but apparently not odfFigureCaption.No idea.> 3. Is it possible to add special characters to the output? Below is a > sample Kaplan-Meier analysis. There's a footnote in there that reads > "Note: X2(1) = xx.xx, p = .xxxx". Is there any way to make the X a > lowercase Chi and to superscript the 2? I did quite a bit of digging > on this topic. It sounds like it might be difficult, especially if one > is using Windows as I am.For the Chi you can copy the Unicode character ? from e.g. LibreOffice and use it in the string passed to odfCat() and friends. If that does not work on Windows, you can also use the escape code \u03C7. For the ?, you can either use the Unicode character (code \u00B2), or try to insert ODF markup to put a 2 as an exponent (I did not test second option). Regards> Thanks, > > Paul > > ################## > #### Get data #### > ################## > > #### Load packages #### > > require(survival) > require(MASS) > > #### Sample analysis #### > > attach(gehan) > gehan.surv <- survfit(Surv(time, cens) ~ treat, data= gehan, conf.type = "log-log") > print(gehan.surv) > > survTable <- summary(gehan.surv)$table > survTable <- data.frame(Treatment = rownames(survTable), survTable, row.names=NULL) > survTable <- subset(survTable, select = -c(records, n.max)) > > ################## > #### odfWeave #### > ################## > > #### Load odfWeave #### > > require(odfWeave) > > #### Modify StyleDefs #### > > currentDefs <- getStyleDefs() > > currentDefs$firstColumn$type <- "Table Column" > currentDefs$firstColumn$columnWidth <- "5 cm" > currentDefs$secondColumn$type <- "Table Column" > currentDefs$secondColumn$columnWidth <- "3 cm" > > currentDefs$ArialCenteredBold$fontSize <- "10pt" > currentDefs$ArialNormal$fontSize <- "10pt" > currentDefs$ArialCentered$fontSize <- "10pt" > currentDefs$ArialHighlight$fontSize <- "10pt" > > currentDefs$ArialLeftBold <- currentDefs$ArialCenteredBold > currentDefs$ArialLeftBold$textAlign <- "left" > > currentDefs$cgroupBorder <- currentDefs$lowerBorder > currentDefs$cgroupBorder$topBorder <- "0.0007in solid #000000" > > setStyleDefs(currentDefs) > > #### Modify ImageDefs #### > > imageDefs <- getImageDefs() > imageDefs$dispWidth <- 5.5 > imageDefs$dispHeight<- 5.5 > setImageDefs(imageDefs) > > #### Modify Styles #### > > currentStyles <- getStyles() > currentStyles$figureFrame <- "frameWithBorders" > setStyles(currentStyles) > > #### Set odt table styles #### > > tableStyles <- tableStyles(survTable, useRowNames = FALSE, header = "") > tableStyles$headerCell[1,] <- "cgroupBorder" > tableStyles$header[,1] <- "ArialLeftBold" > tableStyles$text[,1] <- "ArialNormal" > tableStyles$cell[2,] <- "lowerBorder" > > #### Weave odt source file #### > > fp <- "N:/Studies/HCRPC1211/Report/odfWeaveTest/" > inFile <- paste(fp, "testWeaveIn.odt", sep="") > outFile <- paste(fp, "testWeaveOut.odt", sep="") > odfWeave(inFile, outFile) > > ###################################### > #### Contents of .odt source file #### > ###################################### > > Here is a sample Kaplan-Meier table. > > <<testKMTable, echo=FALSE, results = xml>>> odfTableCaption(?A Sample Kaplan-Meier Analysis Table?) > odfTable(survTable, useRowNames = FALSE, digits = 3, > colnames = c("Treatment", "Number", "Events", "Median", "95% LCL", "95% UCL"), > colStyles = c("firstColumn", "secondColumn", "secondColumn", > "secondColumn", "secondColumn", "secondColumn"), > styles = tableStyles) > odfCat(?Note: X2(1) = xx.xx, p = .xxxx?) > @ > > Here is a sample Kaplan-Meier graph. > > <<testKMFig, echo=FALSE, fig = TRUE>>> odfFigureCaption("A Sample Kaplan-Meier Analysis Graph", label = "Figure") > plot(gehan.surv, xlab = "Time", ylab= "Survivorship") > @ >