ReporteRs (version 0.5.8)

[<-.FlexTable: alter FlexTable content and format

Description

add text or format a FlexTable object

Usage

# S3 method for FlexTable
[ (x, i, j, text.properties, newpar = F, byrow = FALSE, to = "body") <- value

Arguments

x

the FlexTable object

i

vector (integer index, row.names values or boolean vector) for rows selection.

j

vector (integer index, col.names values or boolean vector) for columns selection. or an object of class textProperties.

text.properties

formatting properties (an object of class textProperties).

newpar

logical value specifying wether or not the content should be added as a new paragraph

byrow

logical. If FALSE (the default) content is added by columns , otherwise content is added by rows.

to

specify on which part of the FlexTable to apply the value, must be one of the following values "body" (default) or "header" or "footer"

value

see details.

Details

To modify content formatting properties, value should be an object of class cellProperties or an object of class parProperties or an object of class textProperties.

To add content, there are two options:

* First option: value should be a data.frame or a matrix or a vector with as many elements as defined by the selection. text.properties can be used to specify how to format added values.

* Second option: value is a pot object, its value will be added in all cells defined by the selection.

Use ft_object[1:4, 2:3] <- ... to perform the operation on the body subset of of the FlexTable.

Use ft_object[1, 2, to = "header"] <- ... to perform the operation on the header subset of the FlexTable.

Use ft_object[1, 2, , to = "footer"] <- ... to perform the operation on the footer subset of the FlexTable.

Use ft_object[] <- ... to perform the operation on the whole part (body, header or footer) of the FlexTable.

See Also

addHeaderRow, addFooterRow , FlexTable, setFlexTableBorders , spanFlexTableRows, spanFlexTableColumns , setRowsColors, setColumnsColors, setZebraStyle , addFlexTable, addFlexTable.docx , addFlexTable.pptx, addFlexTable.html

Examples

Run this code
# NOT RUN {
#START_TAG_TEST
# Create a FlexTable object with first 10 lines of data.frame mtcars
# add row.names as first column
MyFTable = FlexTable( data = mtcars[1:10, ]
  , add.rownames=TRUE
)
# modify the text formatting properties for the row.names column
MyFTable[ , 1] = textProperties( font.style="italic", font.size = 9)
# align text to right for the row.names column
MyFTable[ , 1] = parProperties( text.align = "right" )

# change cell formatting properties for various columns
MyFTable[ c(3,6:9), c( "mpg", "disp"
  , "hp", "drat", "wt", "qsec" ) ] = cellProperties( background.color="#CCCCCC")
# add text to elements of the column cyl
MyFTable[, "cyl", text.properties = textProperties( 
  vertical.align="superscript", font.size = 9) ] = " miles/gallon"



data( iris )
iris = head( iris[, c(5, 1:4)] )

default_text = textProperties( font.size = 11 )
note_text = chprop(default_text, vertical.align = "superscript", color = "blue")

iris_ft = FlexTable( data = iris, header.columns = FALSE )
iris_ft = addHeaderRow( iris_ft, value = c("", "Measures" ), colspan = c( 4, 1 ) )
iris_ft = addHeaderRow( iris_ft, value = gsub( "\\.", " ", names( iris ) ) )
iris_ft[2, 2, newpar = TRUE ] = "Hi there"
iris_ft[2, 1, to="header"] = pot("* this is a note", note_text )


iris_ft = spanFlexTableRows( iris_ft, j = "Species", runs = as.character( iris$Species ) )
iris_ft = setFlexTableBorders( iris_ft, 
  inner.vertical = borderProperties( style = "none" ), 
  inner.horizontal = borderProperties( width = 1 ), 
  outer.vertical = borderProperties( width = 0 ), 
  outer.horizontal = borderProperties( width = 2 ), 
  footer = TRUE
)
#STOP_TAG_TEST
# }

Run the code above in your browser using DataCamp Workspace