ReporteRs (version 0.4)

addTOC.docx: Insert a table of contents into a docx object

Description

Insert a table of contents into a "docx" object.

Usage

# S3 method for docx
addTOC (doc, stylename, ...)

Arguments

doc

Object of class "docx" where table of content has to be added

stylename

optional. Stylename in the document that will be used to build entries of the TOC.

...

further arguments, not used.

Value

an object of class "docx".

Details

If stylename is not used, a classical table of content will be produced. If stylename is used, a custom table of contents will be produced, pointing to entries that have been formated with stylename. For example, this can be used to produce a toc with only plots.

See Also

docx, addTitle.docx , styles.docx, addParagraph.docx

Examples

Run this code
# NOT RUN {
#START_TAG_TEST
require( ggplot2 )

### example 1
# Create a new document
doc = docx( title = "title" )
#leave the first page blank and add a page break
doc = addPageBreak(doc)
# add a TOC (to be refresh when document is opened)
# and add a page break
doc <- addTOC(doc)
doc = addPageBreak(doc)

# add titles that will be entries in the TOC
doc = addTitle( doc, "My first title", level = 1 )
doc = addTitle( doc, "My second title", level = 1 )

# Write the object in file "addTOC_example1.docx"
writeDoc( doc, "addTOC_example1.docx" )


### example 2
# Create a new document
doc = docx( title = "title" )
#leave the first page blank and add a page break
doc = addPageBreak(doc)#'

doc = addTitle( doc, "Plots", level = 1 )
doc = addPlot( doc
		, fun = plot
		, x = rnorm( 100 )
		, y = rnorm (100 )
		, main = "base plot main title"
	)
doc = addParagraph( doc, value="graph example 1", stylename = "rPlotLegend" )

myplot = qplot(Sepal.Length, Petal.Length, data = iris, color = Species
		, size = Petal.Width, alpha = I(0.7))
doc = addPlot( doc = doc
		, fun = print
		, x = myplot #this argument MUST be named, print is expecting argument 'x'
	)
doc = addParagraph( doc, value="graph example 2", stylename = "rPlotLegend" )

# Because we used "rPlotLegend" as legend in plot
# , addTOC will use this stylename to define
# entries in the generated TOC
doc <- addTOC(doc, stylename = "rPlotLegend")

# Write the object in file "addTOC_example2.docx"
writeDoc( doc, "addTOC_example2.docx" )
#STOP_TAG_TEST
# }

Run the code above in your browser using DataCamp Workspace