odfTable: Create an Open Document Format table

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Create an Open Document Format table from a data frame, matrix or vector

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
odfTable(x, ...)

## S3 method for class 'numeric'
odfTable(x, 
         horizontal = length(x) < 5, 
         colnames = names(x), 
         digits = max(3, getOption("digits") - 3), 
         name = paste("Table", floor(runif(1) * 1000), sep = ""), 
         styles = NULL,
         ...)
  
## S3 method for class 'character'
odfTable(x, 
         horizontal = length(x) < 5, 
         colnames = names(x), 
         name = paste("Table", floor(runif(1) * 1000), sep = ""), 
         styles = NULL, 
         ...)
     
## S3 method for class 'data.frame'
odfTable(x, 
         colnames = NULL, 
         useRowNames = TRUE, 
         digits = max(3, getOption("digits") - 3), 
         name = paste("Table", floor(runif(1) * 1000), sep = ""), 
         styles = NULL, 
         cgroup = NULL, 
         rgroup = NULL, 
         ...)
   
## S3 method for class 'matrix'
odfTable(x, 
         colnames = NULL, 
         useRowNames = TRUE, 
         digits = max(3, getOption("digits") - 3),
         name = paste("Table", floor(runif(1) * 1000), sep = ""), 
         styles = NULL, 
         cgroup = NULL, 
         rgroup = NULL, 
         ...)

Arguments

x

A vector, matrix or data frame.

horizontal

A logical: should the vector be shown as a 1xn table or nx1? This is ignored for other data structures.

colnames

A vector of column names that can be used. Note that if the row names are used in the table, this should contain an extra element for that column.

useRowNames

A logical: should the row names be printed in the final table.

digits

Number of significant digits passed to format.

name

A name for the table. ODF requires a name for each object, so a random name will be used if unspecified.

styles

An optional list of style names for each table element (cells, headers etc). See tableStyles

cgroup

A data frame with two, three, or four columns. The first column should be a character vector specifying column group header names. The resulting row will come before the header names specified via the colnames argument. The second column should be a numeric vector specifying the column span for the corresponding element of the first column. The sum of the second column must be equal to the number of columns in x, plus one, if useRowNames is true and x actually has row names. If there is a third column, it should contain the names of paragraph styles to use. If there is a fourth column, it should contain the names of cell styles. In the absence of these columns, the cgroupText and cgroupCell elements of the styles argument will be used.

rgroup

A data frame with two, three, or four columns. The first column should be a character vector specifying row group header names. The second column should be a numeric vector specifying the row span for the corresponding element of the first column. The sum of the second column must be equal to the number of rows in x. If there is a third column, it should contain the names of paragraph styles to use. If there is a fourth column, it should contain the names of cell styles. In the absence of these columns, the rgroupText and rgroupCell elements of the styles argument will be used.

...

Optional arguments that can be passed to format.

Details

The data structures are converted to character matrices using format. The justify and trim arguments to format are usually overridden by the table style options, so those arguments are automatically set to justify = "none" and trim = TRUE. However, if values of these arguments are passed using the three dots, format will use them (but they probably won't do anything).

When using odfTable in a code chunk, the chunk's results argument should be set to xml.

The document formatting.odt in the package's examples directory illustrates the process of changing the appearance of the table.

Value

a list of character string that contain XML markup

Author(s)

Max Kuhn, with contributions from Zekai Otles

See Also

tableStyles

Examples

1
odfTable(iris[1:5,])

Example output

Loading required package: lattice
Loading required package: XML

<table:table table:name="Table804"  table:style-name="RTable1" >
  <table:table-column table:number-columns-repeated="6"/>
   <table:table-header-rows>

    <table:table-row>

    <table:table-cell  table:style-name="lowerBorder" office:value-type="string">
      <text:p  text:style-name="ArialCenteredBold" ></text:p>
    </table:table-cell>
    <table:table-cell  table:style-name="lowerBorder" office:value-type="string">
      <text:p  text:style-name="ArialCenteredBold" >Sepal.Length</text:p>
    </table:table-cell>
    <table:table-cell  table:style-name="lowerBorder" office:value-type="string">
      <text:p  text:style-name="ArialCenteredBold" >Sepal.Width</text:p>
    </table:table-cell>
    <table:table-cell  table:style-name="lowerBorder" office:value-type="string">
      <text:p  text:style-name="ArialCenteredBold" >Petal.Length</text:p>
    </table:table-cell>
    <table:table-cell  table:style-name="lowerBorder" office:value-type="string">
      <text:p  text:style-name="ArialCenteredBold" >Petal.Width</text:p>
    </table:table-cell>
    <table:table-cell  table:style-name="lowerBorder" office:value-type="string">
      <text:p  text:style-name="ArialCenteredBold" >Species</text:p>
    </table:table-cell>
    </table:table-row>
   </table:table-header-rows>
<table:table-row>
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >1</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >5.1</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >3.5</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >1.4</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >0.2</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >setosa</text:p>
  </table:table-cell>

</table:table-row>
 <table:table-row>
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >2</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >4.9</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >3.0</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >1.4</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >0.2</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >setosa</text:p>
  </table:table-cell>

</table:table-row>
 <table:table-row>
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >3</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >4.7</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >3.2</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >1.3</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >0.2</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >setosa</text:p>
  </table:table-cell>

</table:table-row>
 <table:table-row>
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >4</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >4.6</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >3.1</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >1.5</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >0.2</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >setosa</text:p>
  </table:table-cell>

</table:table-row>
 <table:table-row>
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >5</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >5.0</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >3.6</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >1.4</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >0.2</text:p>
  </table:table-cell>

 
 <table:table-cell office:value-type="string"   table:style-name="noBorder"  >
       <text:p text:style-name="ArialCentered" >setosa</text:p>
  </table:table-cell>

</table:table-row>

</table:table>

odfWeave documentation built on May 30, 2017, 7:23 a.m.