-
-
Notifications
You must be signed in to change notification settings - Fork 977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No warning when Ghostsript cannot be find and fig_crop = TRUE #2016
Comments
Thanks for the report. If I understand correctly, you would have expected a warning when Am I understanding it ok ? We could definitely makes the warning more coherent. |
Yeah, absolutely. Just to be a bit more verbose. So the user does not have to be surprised why his or her figures are not cropped even if they opt for so. That is the point. |
Thanks for the report @netique ! |
Ehrm, considering fig_crop is enabled by default, shouldn't the warn be thrown "on failed actual use" rather than "hypothetical initialization"? |
@mirh I agree. @cderv We could probably try this: diff --git a/R/output_format.R b/R/output_format.R
index db90df08..c7eb0a73 100644
--- a/R/output_format.R
+++ b/R/output_format.R
@@ -262,7 +262,7 @@ knitr_options_pdf <- function(fig_width,
knit_hooks <- NULL
# apply cropping if requested and we have pdfcrop and ghostscript
- crop <- fig_crop && has_crop_tools()
+ crop <- fig_crop && has_crop_tools(!missing(fig_crop))
if (crop) {
knit_hooks = list(crop = knitr::hook_pdfcrop)
opts_chunk$crop = TRUE
diff --git a/R/util.R b/R/util.R
index e900168e..d2ade523 100644
--- a/R/util.R
+++ b/R/util.R
@@ -312,7 +312,7 @@ find_program <- function(program) {
}
}
-has_crop_tools <- function() {
+has_crop_tools <- function(warn = TRUE) {
tools <- c(
pdfcrop = unname(find_program("pdfcrop")),
ghostcript = unname(tools::find_gs_cmd())
@@ -320,7 +320,7 @@ has_crop_tools <- function() {
missing <- tools[tools == ""]
if (length(missing) == 0) return(TRUE)
x <- paste0(names(missing), collapse = ", ")
- warning(
+ if (warn) warning(
sprintf("\nTool(s) not installed or not in PATH: %s", x),
"\n-> As a result, figure cropping will be disabled."
) In general, I don't really like testing |
yes I think I wonder if this is really too late to change:
Before, if users did not have the crop tools then Am I missing something ? |
I also don't think changing a default should be a taboo, at least if it's pointed out in big enough letters in the release notes But I'm wondering: why should the default option depend automatically on the tools installed more or less explicitly in one's environment? |
I am really interested to hear about all that. Feel free to open a new issue to share all your feedback - I thinkit would help us do better in the future. |
Since I was using my own thesisdown template, I'm not really sure how much generalizable it could be. At the end of the day not even something *that* huge to fix, if you measure it in "lines of code", but of course you have to understand what is going actually on first and foremost. EDIT: sigh, after actually comparing pixel-by-pixel the pages I also found out of jgm/pandoc#7347 and jgm/pandoc#7393. So TL;DR this was really a big deal to upgrade (and even then, I still have tables slightly wider since the tabcolsep switch). |
FYI |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary. |
I write a custom format and I've noticed there is a
fig_crop
argument inknitr_options_pdf
, which sounds pretty neat. After inspection of the generated output of the function, there was no mention about any cropping, so I went to the definition and spotted that a user is not informed by any means thatpdfcrop
orghostscript
is missing, and crop is silently not applied:rmarkdown/R/output_format.R
Lines 264 to 269 in 268c6eb
Note that
knitr
also does those checks (e.g.knitr:::has_utility("ghostsript")
) wheneverknitr:::pdf_crop()
is called and issues proper warnings as expected. Note further that even if user installs everything needed, Ghostscript does not register its directories to PATH (at least on Windows) and this can lead to another confusion.By filing an issue to this repo, I promise that
xfun::session_info('rmarkdown')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('rstudio/rmarkdown')
.I understand that my issue may be closed if I don't fulfill my promises.
The text was updated successfully, but these errors were encountered: