Skip to content

Commit 4ec2a6c

Browse files
committed
Fixed #169
1 parent eaed5ad commit 4ec2a6c

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* [#181](https://github.com/boxuancui/DataExplorer/issues/181): Added `by` argument to `plot_histogram` and `plot_density` to break down distributions by a discrete or continuous feature.
44

55
## Bug Fixes
6+
* [#169](https://github.com/boxuancui/DataExplorer/issues/169): Charts no longer run off the edge of PDF pages. Report template now uses smaller figure dimensions (6" x 6") for PDF output and keeps larger dimensions (14" x 10") for HTML.
67
* [#172](https://github.com/boxuancui/DataExplorer/issues/172): Fixed `plot_qq(..., by = ...)` error "Faceting variables must have at least one value".
78
* [#185](https://github.com/boxuancui/DataExplorer/issues/185): Fixed warnings from deprecated `aes_string`.
89

R/create_report.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,15 @@ create_report <- function(data,
103103
}
104104
## Get directory of report markdown template
105105
report_dir <- system.file("rmd_template/report.rmd", package = "DataExplorer")
106-
## Render report into html
107-
suppressWarnings(render(
106+
## When output format is PDF, ensure output_file has .pdf extension
107+
is_pdf <- identical(output_format, "pdf_document") ||
108+
"pdf_document" %in% class(output_format) ||
109+
(is.list(output_format) && !is.null(output_format$pandoc$to) && grepl("^latex", output_format$pandoc$to))
110+
if (is_pdf && !grepl("\\.pdf$", output_file, ignore.case = TRUE)) {
111+
output_file <- paste0(sub("\\.[^.]+$", "", output_file), ".pdf")
112+
}
113+
## Render report
114+
report_path <- suppressWarnings(render(
108115
input = report_dir,
109116
output_format = output_format,
110117
output_file = output_file,
@@ -113,7 +120,6 @@ create_report <- function(data,
113120
params = list(data = data, report_config = config, response = y, set_title = report_title),
114121
...
115122
))
116-
## Open report
117-
report_path <- path.expand(file.path(output_dir, output_file))
118-
browseURL(report_path)
123+
## Open report (use path returned by render in case extension was normalized)
124+
browseURL(path.expand(report_path))
119125
}

inst/rmd_template/report.rmd

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ library(data.table)
1414
library(rmarkdown)
1515
library(knitr)
1616
17-
## Set knitr options
17+
## Set knitr options (smaller figures for PDF so charts fit on page; see #169)
18+
fig_dims <- if (knitr::is_latex_output()) {
19+
list(fig.width = 6, fig.height = 6)
20+
} else {
21+
list(fig.width = 14, fig.height = 10)
22+
}
1823
opts_chunk$set(
19-
fig.width = 14,
20-
fig.height = 10,
24+
fig.width = fig_dims$fig.width,
25+
fig.height = fig_dims$fig.height,
2126
echo = FALSE,
2227
results = "asis",
2328
warning = TRUE

0 commit comments

Comments
 (0)