Skip to content
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

plot_crop fails silently #2381

Open
3 tasks done
JackCaster opened this issue Nov 11, 2024 · 1 comment
Open
3 tasks done

plot_crop fails silently #2381

JackCaster opened this issue Nov 11, 2024 · 1 comment

Comments

@JackCaster
Copy link

I am using knitr via Quarto. One issue that I had was that the pdf plots had too much margin, but I solved it with the knitr::hook_pdfcrop. The thing is that it took me a while to get pfdcrop to work. The problem was that:

Until I fixed the problems above with some trials and errors, knitr::plot_crop was failing silently, returning the path of the image to crop, but not actually cropping.

Would it be a good idea to change this

knitr/R/plot.R

Line 345 in 9eb1074

if (is_pdf && !has_utility('pdfcrop')) return(x2)

into something that raises a warning if the utility is not found?


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). 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('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@cderv
Copy link
Collaborator

cderv commented Nov 12, 2024

It seems it should warn by default as warn = TRUE is the default

knitr/R/utils.R

Line 812 in 9eb1074

if (name == 'pdfcrop') yes = has_crop_tools() else {

knitr/R/utils.R

Lines 821 to 838 in 9eb1074

has_crop_tools = function(warn = TRUE) {
if (Sys.which('pdfcrop') == '') {
if (warn) warning("'pdfcrop' is required but not found")
return(FALSE)
}
if (is_windows() && Sys.which('tlmgr') != '') {
# assuming users know what this env var means (rstudio/tinytex#391)
if (Sys.getenv('TEXLIVE_WINDOWS_EXTERNAL_GS') != '') return(TRUE)
year = tinytex::tlmgr_version('list')$texlive
if (year < 2023 && warn) warning(
'TeX Live version too low. Please consider upgrading, e.g., via tinytex::reinstall_tinytex().'
)
return(year >= 2023)
}
gs = tools::find_gs_cmd() != ''
if (warn && !gs) warning("'ghostscript' is required but not found")
gs
}

Did you get no warning at all ?

I tried tinytex::tlmgr_remove("pdfcrop") to uninstall pdfcrop and then tried

> knitr:::has_utility("pdfcrop")
[1] FALSE
Message d'avis :
Dans has_crop_tools() : 'pdfcrop' is required but not found

and I got the warning.

So maybe this is something else in another context ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants