Writes a result table, a figure or an interactive graphic to a file whose format follows its extension, for a manuscript, a report or a presentation.
Usage
jp_save(
x,
file,
title = NULL,
note = NULL,
digits = 3,
width = 7.5,
height = 5,
dpi = 300,
label = NULL,
...
)Arguments
- x
A data frame, a ggplot, an htmlwidget or a
joinpointfit.- file
Output file; the extension sets the format.
- title
Optional caption of the table or figure.
- note
Optional note printed under the table or figure.
- digits
Decimals of the numeric columns of a table (character columns, such as those of
jp_table(), are written as they are). In.csv,.tsvand.txtfiles numbers stay numeric (p values rounded todigitssignificant digits); other formats show p values with three decimals, and below 0.001 as "< 0.001". Line breaks inside cells of Markdown and document tables become spaces.- width, height, dpi
Size of a figure in inches and its resolution.
- label
Optional LaTeX label (
.texoutput).- ...
Further arguments to
jp_report()whenxis a fit.
Details
Tables (data frames such as the results of
jp_table(),apc()ormodel_selection()$criteria):.csv,.tsv,.txt,.md(Markdown pipe table),.tex(LaTeXtablewith booktabs rules; load\usepackage{booktabs}),.html,.docx(Word table),.odt,.rtf,.pptxand.pdf.Figures (ggplot objects such as autoplot() or
plot_apc()): the image formats ofggplot2::ggsave()(.png,.pdf,.svg,.jpeg,.tiff,.eps, ...),.tex(a LaTeXfigurethat includes a PDF of the figure written beside it), and.html,.docx,.odt,.rtf,.pptxand.mddocuments holding the figure.Interactive graphics (
jp_interactive()):.html, a standalone web page (without Pandoc, a page with its scripts in the folder<name>_filesbeside it).A
joinpointfit: a complete report, seejp_report().
Word, OpenDocument, PowerPoint, RTF, HTML and PDF documents are made with
Pandoc, which comes with RStudio and Quarto (or see
https://pandoc.org), through the rmarkdown package; PDF documents also
need LaTeX (for example tinytex::install_tinytex()).
Examples
tb <- subset(us_mortality, cause == "Tuberculosis")
fit <- joinpoint(tb, year, rate, kmax = 2, ci_method = "parametric")
dir <- file.path(tempdir(), "joinpoint-save")
dir.create(dir)
jp_save(jp_table(fit), file.path(dir, "trends.tex"),
title = "Trends in tuberculosis mortality")
jp_save(jp_table(fit), file.path(dir, "trends.md"))
jp_save(autoplot(fit), file.path(dir, "trend.png"), width = 6, height = 4)
if (requireNamespace("rmarkdown", quietly = TRUE) &&
rmarkdown::pandoc_available()) {
jp_save(jp_table(fit), file.path(dir, "trends.docx"))
}
list.files(dir)
#> [1] "trend.png" "trends.docx" "trends.md" "trends.tex"
unlink(dir, recursive = TRUE)