A pot object (pieces of text or paragraph of text) is made of one or more chunk of text with different formatting properties.

Overview

ReporteRs provide a class of object to enable text formatting: pot objects.

pot objects are created with function pot. These objects can be concatenated: an object can be added with another pot object or with a single text value (a character vector of length 1).

A pot object is a set of text chunks, each chunk is associated with its own font properties. A Footnote and an hyperlink can be associated to a pot object.

When \\n is used, a soft return is used.

These objects are to be used when adding paragraphs into a document or when working with FlexTable.

pot('Hello World!')

Hello World!

pot('Hello') + ' ' + pot( 'World!', textItalic() )

Hello World!

pot( 'Cats', textProperties( color = 'orange' ) ) + ' and ' + 
  pot('dogs', textBold( color = '#E74C3C' ) )

Cats and dogs

Usage

The function pot has two arguments:

  • value: a text value or a value that has a format method returning character value.
  • format (optional): formating properties (an textProperties` object).

The following code show usage of these parameters:

my_text_prop <- textProperties(color='#1163A5',
  font.size = 20, font.weight = 'bold', font.family = 'Courier New' )

my_text <- pot( value = 'My tailor', format = my_text_prop ) +
  ' is rich. ' +
  pot( value = 'Cats', format = chprop( my_text_prop, color = '#F0A91B') ) +
  ' and ' +
  pot( value = 'dogs', format = chprop( my_text_prop, color = '#D63C3A') )
my_text

My tailor is rich. Cats and dogs

Examples

add paragraphs

mydoc = docx( )
mydoc = addParagraph( mydoc, value = my_text )

It produces this document.

add into FlexTable

MyFTable = FlexTable( data = mtcars[1:5, ], add.rownames = TRUE )
MyFTable = addFooterRow( MyFTable, value = '',colspan = ncol(mtcars) + 1)
MyFTable[1,1, to = 'footer'] = my_text

MyFTable

mpg

cyl

disp

hp

drat

wt

qsec

vs

am

gear

carb

Mazda RX4

21.0

6

160

110

3.90

2.620

16.46

0

1

4

4

Mazda RX4 Wag

21.0

6

160

110

3.90

2.875

17.02

0

1

4

4

Datsun 710

22.8

4

108

93

3.85

2.320

18.61

1

1

4

1

Hornet 4 Drive

21.4

6

258

110

3.08

3.215

19.44

1

0

3

1

Hornet Sportabout

18.7

8

360

175

3.15

3.440

17.02

0

0

3

2

My tailor is rich. Cats and dogs

pot_img

pot_img have been implemented to let you arrange text (pot) and images(pot_img) into a paragraph.

img.file <- file.path( Sys.getenv("R_HOME"), "doc", "html", "logo.jpg" )

mypot <- "This paragraph mix an image and text into a paragraph: " + pot_img(filename = img.file, width = .3, height = .3) + pot( '4Cats', textBoldItalic( color = '#428BCA', underline = TRUE ) )
mypot

This paragraph mix an image and text into a paragraph: 4Cats

MyFTable = FlexTable( data = mtcars[1:5, ], add.rownames = TRUE )
MyFTable[1,1, to = "header"] <- mypot
MyFTable

This paragraph mix an image and text into a paragraph: 4Cats

mpg

cyl

disp

hp

drat

wt

qsec

vs

am

gear

carb

Mazda RX4

21.0

6

160

110

3.90

2.620

16.46

0

1

4

4

Mazda RX4 Wag

21.0

6

160

110

3.90

2.875

17.02

0

1

4

4

Datsun 710

22.8

4

108

93

3.85

2.320

18.61

1

1

4

1

Hornet 4 Drive

21.4

6

258

110

3.08

3.215

19.44

1

0

3

1

Hornet Sportabout

18.7

8

360

175

3.15

3.440

17.02

0

0

3

2

This feature is not available when working with pptx object (and you can’t mix text and images in PowerPoint).

Footnotes

Footnotes can be added to pot objects.

Use objects of class Footnote to create a Footnote. Function pot has an argument footnote to specify which Footnote to use. If missing, no footnote will be added.

Footnote are not supported within PowerPoint documents.

Word example

library( ReporteRs )

footnote1 = Footnote( )
footnote1 = addParagraph( footnote1, pot('About this reference', textBold( ) ) )

mydoc = docx( )
mydoc = addParagraph(mydoc, pot('Latius iam disseminata licentia', footnote = footnote1 ) )