addParagraph

0th

Percentile

Add a paragraph into a document object

Add a paragraph into a document object

Usage
addParagraph(doc, value, ...)
"addParagraph"(doc, value, stylename, bookmark, par.properties = parProperties(), restart.numbering = FALSE, ...)
"addParagraph"(doc, value, par.properties = parProperties(), restart.numbering = FALSE, ...)
"addParagraph"(doc, value, offx, offy, width, height, par.properties, append = FALSE, restart.numbering = FALSE, ...)
Arguments
doc
document object
value
text to add to the document as paragraphs: an object of class pot or set_of_paragraphs or a character vector.
...
further arguments passed to other methods
stylename
value of the named style to apply to paragraphs in the docx document. Expected value is an existing stylename of the template document used to create the docx object. see styles.docx.
bookmark
a character value ; id of the Word bookmark to replace by the table. optional. See bookmark.
par.properties
parProperties to apply to paragraphs, only used if stylename if missing.
restart.numbering
boolean value. If TRUE, next numbered list counter will be set to 1.
offx
optional, x position of the shape (top left position of the bounding box) in inches. See details.
offy
optional, y position of the shape (top left position of the bounding box) in inches. See details.
width
optional, width of the shape in inches. See details.
height
optional, height of the shape in inches. See details.
append
boolean default to FALSE. If TRUE, paragraphs will be appened in the current shape instead of beeing sent into a new shape. Paragraphs can only be appended on shape containing paragraphs (i.e. you can not add paragraphs after a FlexTable). Applies to only pptx objects.
Details

a paragraph is a set of text that ends with an end of line. Read pot to see how to get different font formats. If an end of line is required, a new paragraph is required.
When document is a pptx object, two positioning methods are available.
If arguments offx, offy, width, height are missing, position and dimensions will be defined by the width and height of the next available shape of the slide. This dimensions can be defined in the layout of the PowerPoint template used to create the pptx object.
If arguments offx, offy, width, height are provided, they become position and dimensions of the new shape.
Also, when document is a pptx object, shading and border settings of argument par.properties will have no effect.

Value

a document object

See Also

docx, pptx, bsdoc, pot, textProperties, parProperties

Aliases
  • addParagraph
  • addParagraph.bsdoc
  • addParagraph.docx
  • addParagraph.pptx
Examples

# docx example ---------
doc.filename = "ex_paragraph.docx"
doc <- docx()
styles(doc)

doc = addTitle( doc, "Title example 1", level = 1 )

# Add "Hello World" into the document doc
doc = addParagraph(doc, "Hello Word", stylename = "Normal" )

doc = addTitle( doc, "Title example 2", level = 1 )

# define some text
sometext = c( "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", 
"In sit amet ipsum tellus. Vivamus dignissim arcu sit amet faucibus auctor.", 
"Quisque dictum tristique ligula.")

# add sometext with stylename BulletList
doc = addParagraph( doc, value = sometext, stylename="BulletList" )

doc = addTitle( doc, "Title example 3", level = 1 )

# "My tailor is rich" with formatting on some words
pot1 = pot("My tailor", textProperties(color = "red" ) 
  ) + " is " + pot("rich", textProperties(shading.color = "red", 
  font.weight = "bold" ) )

# "Cats and dogs" with formatting on some words
pot2 = pot("Cats", textProperties(color = "red" ) ) + 
  " and " + 
  pot("dogs", textProperties( color = "blue" ), 
    hyperlink = "http://www.wikipedia.org/" )

# create a set of paragraphs made of pot1 and pot2
my.pars = set_of_paragraphs( pot1, pot2 )

# Add my.pars into the document doc
doc = addParagraph(doc, my.pars, stylename = "Normal" )

doc = addTitle( doc, "Title example 4", level = 1 )
# define some text
text1 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
text2 = "In sit amet ipsum tellus. Vivamus arcu sit amet faucibus auctor."
text3 = "Quisque dictum tristique ligula."

# define parProperties with list properties
ordered.list.level1 = parProperties(list.style = "ordered", 
	level = 1 )
ordered.list.level2 = parProperties(list.style = "ordered", 
	level = 2 )

# define parProperties with list properties
unordered.list.level1 = parProperties(list.style = "unordered", 
	level = 1 )
unordered.list.level2 = parProperties(list.style = "unordered", 
	level = 2 )

# add ordered list items 
doc = addParagraph( doc, value = text1, 
	par.properties = ordered.list.level1 )
doc = addParagraph( doc, value = text2, 
	par.properties = ordered.list.level2 )

# add ordered list items without restart renumbering
doc = addParagraph( doc, value = c( text1, text2, text3), 
	par.properties = ordered.list.level1 )

# add ordered list items and restart renumbering
doc = addParagraph( doc, value = c( text1, text2, text3), 
restart.numbering = TRUE, par.properties = ordered.list.level1 )

# add unordered list items
doc = addParagraph( doc, value = text1, 
	par.properties = unordered.list.level1 )
doc = addParagraph( doc, value = text2, 
	par.properties = unordered.list.level2 )


writeDoc( doc, file = doc.filename )

# bsdoc example ---------
doc.filename = "ex_paragraph/example.html"

options( "ReporteRs-fontsize" = 11 )
doc = bsdoc( )

doc = addTitle( doc, "Title example 1", level = 1 )

# Add "Hello World" into the document doc
doc = addParagraph(doc, "Hello Word" )

doc = addTitle( doc, "Title example 2", level = 1 )

# "My tailor is rich" with formatting on some words
pot1 = pot("My tailor", textProperties(color = "red" ) 
  ) + " is " + pot("rich", textProperties(shading.color = "red", 
  font.weight = "bold" ) )

# "Cats and dogs" with formatting on some words
pot2 = pot("Cats", textProperties(color = "red" ) ) + 
  " and " + 
  pot("dogs", textProperties( color = "blue" ), 
    hyperlink = "http://www.wikipedia.org/" )

# create a set of paragraphs made of pot1 and pot2
my.pars = set_of_paragraphs( pot1, pot2 )

# Add my.pars into the document doc
doc = addParagraph(doc, my.pars )

doc = addTitle( doc, "Title example 3", level = 1 )
# define some text
text1 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
text2 = "In sit amet ipsum tellus. Vivamus arcu sit amet faucibus auctor."
text3 = "Quisque dictum tristique ligula."

# define parProperties with list properties
ordered.list.level1 = parProperties(list.style = "ordered", 
	level = 1 )
ordered.list.level2 = parProperties(list.style = "ordered", 
	level = 2 )

# define parProperties with list properties
unordered.list.level1 = parProperties(list.style = "unordered", 
	level = 1 )
unordered.list.level2 = parProperties(list.style = "unordered", 
	level = 2 )

# add ordered list items 
doc = addParagraph( doc, value = text1, 
	par.properties = ordered.list.level1 )
doc = addParagraph( doc, value = text2, 
	par.properties = ordered.list.level2 )

# add ordered list items without restart renumbering
doc = addParagraph( doc, value = c( text1, text2, text3), 
	par.properties = ordered.list.level1 )

# add ordered list items and restart renumbering
doc = addParagraph( doc, value = c( text1, text2, text3), 
restart.numbering = TRUE, par.properties = ordered.list.level1 )

# add unordered list items
doc = addParagraph( doc, value = text1, 
	par.properties = unordered.list.level1 )
doc = addParagraph( doc, value = text2, 
	par.properties = unordered.list.level2 )


writeDoc( doc, file = doc.filename )

# pptx example -------
doc.filename = "ex_paragraph.pptx"

options( "ReporteRs-fontsize" = 24 )
doc = pptx( title = "title" )

# add a slide with layout "Title and Content"
doc = addSlide( doc, slide.layout = "Title and Content" )

doc = addTitle( doc, "Title example 1" )

# Add "Hello World" into the document doc
doc = addParagraph(doc, "Hello Word" )

# add a slide with layout "Title and Content"
doc = addSlide( doc, slide.layout = "Title and Content" )

doc = addTitle( doc, "Title example 2" )

# "My tailor is rich" with formatting on some words
pot1 = pot("My tailor", textProperties(color = "red" ) 
  ) + " is " + pot("rich", textProperties(shading.color = "red", 
  font.weight = "bold" ) )

# "Cats and dogs" with formatting on some words
pot2 = pot("Cats", textProperties(color = "red" ) ) + 
  " and " + 
  pot("dogs", textProperties( color = "blue" ), 
    hyperlink = "http://www.wikipedia.org/" )

# create a set of paragraphs made of pot1 and pot2
my.pars = set_of_paragraphs( pot1, pot2 )

# Add my.pars into the document doc
doc = addParagraph(doc, my.pars )

# Add my.pars into the document doc
doc = addParagraph(doc, my.pars, offx = 3, offy = 3, 
  width = 2, height = 0.5,
  par.properties=parProperties(text.align="center", padding=0) )

# add a slide with layout "Title and Content"
doc = addSlide( doc, slide.layout = "Title and Content" )

doc = addTitle( doc, "Title example 3" )

# "My tailor is rich" with formatting on some words
pot1 = pot("My tailor", textProperties(color = "red" ) 
  ) + " is " + pot("rich", textProperties(shading.color = "red", 
  font.weight = "bold" ) )

# "Cats and dogs" with formatting on some words
pot2 = pot("Cats", textProperties(color = "red" ) ) + 
  " and " + 
  pot("dogs", textProperties( color = "blue" ), 
    hyperlink = "http://www.wikipedia.org/" )

# create a set of paragraphs made of pot1 and pot2
my.pars = set_of_paragraphs( pot1, pot2 )

# Add my.pars into the document doc
doc = addParagraph(doc, my.pars, 
  par.properties=parProperties(text.align="center", padding=24) )

# add a slide with layout "Title and Content"
doc = addSlide( doc, slide.layout = "Title and Content" )

doc = addTitle( doc, "Title example 1" )
# define some text
text1 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
text2 = "In sit amet ipsum tellus. Vivamus arcu sit faucibus auctor."
text3 = "Quisque dictum tristique ligula."

# define parProperties with list properties
ordered.list.level1 = parProperties(list.style = "ordered", 
	level = 1 )
ordered.list.level2 = parProperties(list.style = "ordered", 
	level = 2 )

# define parProperties with list properties
unordered.list.level1 = parProperties(list.style = "unordered", 
	level = 1 )
unordered.list.level2 = parProperties(list.style = "unordered", 
	level = 2 )

# add ordered list items 
doc = addParagraph( doc, value = text1, 
	par.properties = ordered.list.level1 )
doc = addParagraph( doc, value = text2, append = TRUE, 
	par.properties = ordered.list.level2 )

doc = addParagraph(doc, "This paragraph has no list attribute", 
	append = TRUE )

# add ordered list items without restart renumbering
doc = addParagraph( doc, value = c( text1, text2, text3), 
	append = TRUE, par.properties = ordered.list.level1 )

# add ordered list items and restart renumbering
doc = addParagraph( doc, value = c( text1, text2, text3), 
	append = TRUE, restart.numbering = TRUE, 
	par.properties = ordered.list.level1 )

# add unordered list items
doc = addParagraph( doc, value = text1, 
		append = TRUE, 
		par.properties = unordered.list.level1 )
doc = addParagraph( doc, value = text2, 
		append = TRUE, 
		par.properties = unordered.list.level2 )


writeDoc( doc, file = doc.filename )
Documentation reproduced from package ReporteRs, version 0.8.6, License: GPL-3

Community examples

Looks like there are no examples yet.