Update the content of a report section in a
camReport object, or list the report sections
currently
attached to the object.
Usage
updateReportSection(
x,
section,
text,
title,
code,
code_name,
code_setting,
packages,
append_text,
append_code
)
listReportSections(x)Arguments
- x
- section
A single character string giving the name or title of the report section to update.
- text
An optional character value used to update the text body of the report section. The default is
NULL, which leaves the text unchanged.- title
An optional character value giving a new title for the report section. The default is
NULL, which leaves the title unchanged.- code
Optional R code used to update or add a code chunk. The code can be supplied inside braces.
- code_name
An optional character string naming the R code chunk. The default is
NULL.- code_setting
Optional R Markdown chunk options for the code chunk. The default is
NULL.- packages
An optional character vector giving the R packages required by the code chunk. The default is
NULL.- append_text
A logical value (default
FALSE). IfTRUE, the new text is appended to the existing section text; otherwise, the existing text is replaced.- append_code
A logical value (default
FALSE). IfTRUE, the new code is appended to the existing code chunk; otherwise, the existing code is replaced.
Value
updateReportSection() returns the updated camReport object
invisibly. listReportSections() returns a data frame describing the
report sections attached to the object.
Details
Report sections can be identified using either their name or title.
listReportSections() lists the sections attached to a camReport object
and
can be used to find the exact section names before updating them.
updateReportSection() is useful for adapting the default report content to
project-specific needs, including changing section titles, replacing or
appending text, and adding or updating R code chunks.
See also
camData(), report(), reportSection(), info()
Other report sections:
reportSection,character-method,
section_names(),
testSection,.textSection-method
Examples
# \donttest{
source_dataset <- system.file(
"external",
"dataset",
package = "camtrapReport"
)
example_dataset <- tempfile("camtrapReport-example-")
dir.create(example_dataset)
invisible(file.copy(
list.files(source_dataset, full.names = TRUE),
example_dataset,
recursive = TRUE
))
cm <- camData(example_dataset)
#> The camReport object is being created...
#> Dataset size: 6.6 MB.
#> File size looks modest, but full object creation may still take several minutes depending on the number of records.
#> Setup is done!
#> Data loaded successfully in 25 sec.
#> camReport object is ready for GMU8 LEUVEN.
# List sections currently attached to the report
section_catalog <- listReportSections(cm)
head(section_catalog)
#> name title parent
#> 1 introduction Introduction .root
#> 2 methods Methods .root
#> 3 study_area Study Area methods
#> 4 sampling Sampling methods
#> 5 location Camera Locations {.tabset} methods
#> 6 effort Sampling Efforts methods
#> path
#> 1 introduction / introduction
#> 2 methods / methods / methods
#> 3 methods / study_area / study_area
#> 4 methods / sampling / sampling
#> 5 methods / location / location
#> 6 methods / effort / effort
# Update the introduction
cm <- updateReportSection(
cm,
section = "introduction",
title = "Project introduction",
text = paste(
"This report summarises camera-trap monitoring",
"data for the example study site."
)
)
# Confirm the updated section title
updated_catalog <- listReportSections(cm)
updated_catalog[
updated_catalog$name == "introduction",
c("name", "title"),
drop = FALSE
]
#> name title
#> 1 introduction Project introduction
unlink(example_dataset, recursive = TRUE, force = TRUE)
# }