Max,

Thank you for your help. Please see my responses below.


On Tue, Feb 9, 2010 at 8:20 PM, Max Kuhn <mxkuhn@gmail.com> wrote:

> > I am trying to figure out how to control table width and alignment on the
> > page for a table generated by odfTable. Based on reading odfWeave
> > documentation (including formattingOut.odt), here is how I manipulate the
> > styles:
> >
> st = getStyleDefs()
>  # modify the table style
>  tab = getStyles()$table
> st[[tab]]$align = "center"            # seems to have no effect
> st[[tab]]$marginLeft = "2.0 in"     # seems to have no effect
> setStyleDefs(st)
> >
> > My table always ends up fully justified (taking all page width). When I
> > check Table Format in the output .odf, Alignment is always "Automatic".
> When
> > doing Column/Optimal Width on the table, the table shrinks but becomes
> left
> > aligned, not centered.
>
> It's hard to tell without an actual file to test with (and what
> versions of R and odfWeave, and what platform etc)
>

I am working with R 2.10.1 om Windows XP Professional 2002, SP 3. My package
versions are listed below:
> pkgVersions(type = "matrix")
     [,1]                [,2]                 [,3]
[,4]
[1,] "base (2.10.1)"     "grDevices (2.10.1)" "MASS (7.3-4)"      "stats
(2.10.1)"
[2,] "datasets (2.10.1)" "grid (2.10.1)"      "methods (2.10.1)"  "utils
(2.10.1)"
[3,] "graphics (2.10.1)" "lattice (0.17-26)"  "odfWeave (0.7.10)" "XML
(2.6-0)"

Would it help if I send you a small ODT file which concisely shows what I am
trying to do?


> Did you read the example files in the examples directory of the
> package? There are examples of what you are doing there and they seem
> to work (last time I checked at least).
>
> Can you you reproduce those example tables?
>

Yes, I looked into these examples, they are nice, thank you. I am able to
run (odfWeave) 3 out of 4: "examples.odt", "simple.odt" and "testCases.odt",
but they do not make use of the table style "align" or "margin" properties,
so all tables are fully justified per default (except for the case where a
code chuck lives in a small 1x1 table, which effectively restricts the
output width -- in fact, this is a partial alternative to manipulating table
margins).

I cannot run odfWeave on "formatting.odt". The initial error message has to
do with the fact that I do not have the "RTable2" style, which is referenced
in chunk:

   13 : echo term verbatim(label=showTableStyles)

Error:  chunk 13 (label=showTableStyles)
Error in names(x) <- value :
  'names' attribute [1] must be the same length as the vector [0]

However, once I comment out styleDetails("RTable2") from this chunk I get a
different error, here is the full output:

> odfWeave("formatting.odt", "[AN]_formatting_out.odt")
  Copying  formatting.odt
  Setting wd to
C:\DOCUME~1\anaumov\LOCALS~1\Temp\RtmplqVqs5/odfWeave16142147610
  Unzipping ODF file using unzip -o "formatting.odt"
Archive:  formatting.odt
 extracting: mimetype
   creating: Configurations2/statusbar/
  inflating: Configurations2/accelerator/current.xml
   creating: Configurations2/floater/
   creating: Configurations2/popupmenu/
   creating: Configurations2/progressbar/
   creating: Configurations2/menubar/
   creating: Configurations2/toolbar/
   creating: Configurations2/images/Bitmaps/
 extracting: Pictures/1000000000000213000001899B642BA5.png
 extracting: Pictures/10000000000000EA000001757E0E322B.png
 extracting: Pictures/10000000000002110000018638600D3B.png
  inflating: layout-cache
  inflating: content.xml
  inflating: styles.xml
 extracting: meta.xml
  inflating: Thumbnails/thumbnail.png
  inflating: settings.xml
  inflating: META-INF/manifest.xml

  Removing  formatting.odt

  Pre-processing the contents
Error: cc$parentId == parentId is not TRUE
In addition: Warning message:
In function (name, .state)  : found start of code chunk in a code chunk

Surprisingly, even if I remove the comment I still get the same message as
above ("found start of code chunk ...") which is very puzzling. Is
formatting.odt working for you with the latest R and package versions?


> The table style is understood by odfWeave -- here is the output I get
after
> sourcing my style definition file:
>
>> getStyles()$table
> [1] "RTable1"
>> getStyleDefs()[[getStyles()$table]]
> $type
> [1] "Table"
>
> $marginLeft
> [1] "2.0 in"
>
> $marginRight
> [1] "0.05in"
>
> $marginTop
> [1] "0.05in"
>
> $marginBottom
> [1] "0.05in"
>
> $align
> [1] "center"
>
> I am not sure why these style options do not seem to have effect on the
> output. My specific questions are:
>
> (1) How do I get table alignment to work?
>
> (2) Is the only way to control table width via setting the margins in the
> $table style? What am I doing wrong in the above style code?

 At present, yes.
>

Ok, thank you, As I found out by looking at testCases.odt, another way which
may work for simple tables is to embed a chuck into a 1x1 table with
specified dimensions, even though this approach is not flexible (no way to
control table dimensions at run time).


> > (3) What about column width -- is it possible to automatically size
> columns
> > to fit the content, like selecting Column/Optimal Width but
> programmatically
> > via odfWeave?
>
> It is on my (neglected) list of things to do. We could provide an
> interface for users to specify the columns widths manually. I've
> experimented with figuring it out automatically and it is subject to
> the font specifications (obviously) and tricky.
>

That would be very nice. As well, automatic column sizing would be a good
thing to have, especially for data frames which have a mix of numeric and
character/factor variables and/or variable names of different lengths. I
have done much coding in R, but I am not familiar with R internals, neither
am I good at C... Could I be of help to you in working on this as time
permits?

Thanks,

Aleksey


>
> Max
>

	[[alternative HTML version deleted]]

