knitr::opts_chunk$set(echo = TRUE) library(ReporteRs) library( magrittr ) options("ReporteRs-fontsize" = 11)
A pot
object (pieces of text or paragraph of text) is made
of one or more chunk of text with different formatting properties.
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!') pot('Hello') + ' ' + pot( 'World!', textItalic() ) pot( 'Cats', textProperties( color = 'orange' ) ) + ' and ' + pot('dogs', textBold( color = '#E74C3C' ) )
The function pot has two arguments:
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
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
Hyperlink can be added to pot objects.
Use argument hyperlink
with function pot
.
Here is an example:
pot( 'Cats', hyperlink = 'http://en.wikipedia.org', textBoldItalic( color = '#428BCA', underline = TRUE ) )
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 MyFTable = FlexTable( data = mtcars[1:5, ], add.rownames = TRUE ) MyFTable[1,1, to = "header"] <- mypot MyFTable
This feature is not available when working with pptx
object (and you can't mix text and images in PowerPoint).
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.
library( ReporteRs ) footnote1 = Footnote( ) footnote1 = addParagraph( footnote1, pot('About this reference', textBold( ) ) ) mydoc = docx( ) mydoc = addParagraph(mydoc, pot('Latius iam disseminata licentia', footnote = footnote1 ) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.