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

Install pdfcrop not working on Ubuntu 22 #435

Closed
dmkaplan2000 opened this issue Feb 9, 2024 · 11 comments
Closed

Install pdfcrop not working on Ubuntu 22 #435

dmkaplan2000 opened this issue Feb 9, 2024 · 11 comments

Comments

@dmkaplan2000
Copy link

I am trying to install pdfcrop using tinytex 0.37 in R 4.3.2 on Ubuntu 22.04.3 LTS. I get the following when I run tinytex::tlmgr_install("pdfcrop"):

tlmgr update --all --self
tlmgr install pdfcrop
tlmgr: package repository https://mirrors.rit.edu/CTAN/systems/texlive/tlnet/ (verified)
tlmgr install: package already present: pdfcrop
mkdir(/home/runner/) failed for tree /home/runner/bin: Permission denied
tlmgr: An error has occurred. See above messages. Exiting.
TLUtils::add_remove_symlinks: add of symlinks had 1 error(s), see messages above.

It seems it is trying to create a directory called /home/runner. If I create that directory myself outside of R and then rerun tinytex::tlmgr_install("pdfcrop"), I get:

tlmgr update --all --self
tlmgr install pdfcrop
tlmgr: package repository https://mirrors.rit.edu/CTAN/systems/texlive/tlnet/ (verified)
tlmgr install: package already present: pdfcrop
> Sys.which('pdfcrop')
pdfcrop 
     "" 
> knitr:::has_utility("pdfcrop")
[1] FALSE

Looking in /home/runner/bin I see that pdfcrop is indeed present, but this directory does not seem to be on the path, so has_utility cannot find it.

Cryptically, if has_utility fails to find pdfcrop, then knitr::plot_crop just returns the input filename with no message, which had me stumped for a bit.


By filing an issue to this repo, I promise that

  • [ X] I have fully read the issue guide at https://yihui.org/issue/.
  • [ X] 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('tinytex'). 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/tinytex').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • [ X] 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.

@yihui
Copy link
Member

yihui commented Feb 9, 2024

It seems there are at least two issues here. First, I wonder if /home/runner is really your HOME directory. It's the home directory of Github Action runners, but should be unlikely to be yours. If your home directory is not /home/runner but tlmgr is trying to use this directory, there must be something wrong in your TinyTeX installation (how did you install it?). Also check the output of tlmgr option sys_bin.

Second, when TinyTeX and pdfcrop are installed but $HOME/bin is not in your PATH variable, knitr should be able to find it. I just fixed this issue in knitr. You can install the development version via

remotes::install_github('yihui/knitr')

Thanks!

@dmkaplan2000
Copy link
Author

I have no idea where /home/runner is coming from. It is certainly not my home directory and I have never heard mention of or created a directory with that name. Also, $HOME/bin is on my path. What was missing for some reason was the link to $HOME/.TinyTeX/bin/x86_64-linux/pdfcrop in $HOME/bin. I added that by hand and then restarted RStudio and now it can find pdfcrop, but something clearly went very wrong at some point. Perhaps RStudio uses /home/runner as a temporary place to run things??? A mystery. In any case, with the manually created symlink, pdfcrop now works so I guess the problem is solved...

@dmkaplan2000
Copy link
Author

dmkaplan2000 commented Feb 9, 2024

Ahh, I now see the sense of your comment - I was indeed running rstudio from a directory cloned from github. Perhaps that somehow messed things up. But I don't knowingly use Github Action runners. And I installed tinytex using the standard tinytex::install_tinytex(). If the problem creeps up again I will just reinstall from outside of the git repo.

@yihui
Copy link
Member

yihui commented Feb 9, 2024

I feel there might be something wrong on our side, but it should be very unlikely. If you installed TinyTeX via tinytex::install_tinytex(), it should adjust the sys_bin option of TeX Live to your actual HOME directory:

tlmgr(c('option', 'sys_bin', bin_dir))

The /home/runner directory is from the Github Action runner that we use to build TinyTeX. It's hardcoded in TinyTeX, but as I said, when you install it, the installation script should adjust this hardcoded path to your own ~/bin. You can check the output of

tlmgr option sys_bin
tlmgr option sys_bin ~/bin
tlmgr option sys_bin

@dmkaplan2000
Copy link
Author

dmkaplan2000 commented Feb 9, 2024

$ tlmgr option sys_bin
Destination for symlinks for binaries (sys_bin): /home/runner/bin
$ tlmgr option sys_bin ~/bin
tlmgr: setting option sys_bin to /home/dmk/bin.
tlmgr: updating /home/dmk/.TinyTeX/tlpkg/texlive.tlpdb
$ tlmgr option sys_bin
Destination for symlinks for binaries (sys_bin): /home/dmk/bin

Does this permanently fix the issue?

@yihui
Copy link
Member

yihui commented Feb 9, 2024

When you (re)install TinyTeX next time, the option may be restored.

In your case, I don't understand why the command tlmgr option didn't work at

tlmgr(c('option', 'sys_bin', bin_dir))

tinytex:::os_index must be 2 in your system, right?

@dmkaplan2000
Copy link
Author

Yes, tinytex:::os_index is 2 on my system. I haven't reinstalled TinyTeX, but I could do that if you wanted me to test.

@yihui
Copy link
Member

yihui commented Feb 14, 2024

Yes, it will be nice if you could test reinstalling TinyTeX. Or simply test this:

tinytex::tlmgr(c('option', 'sys_bin', '~/bin'))

# check if it worked
tinytex::tlmgr(c('option', 'sys_bin'))

tinytex::tlmgr_path()

@dmkaplan2000
Copy link
Author

I tried the code you sent (before reinstalling) and it gave:

> tinytex::tlmgr(c('option', 'sys_bin', '~/bin'))
tlmgr option sys_bin ~/bin
tlmgr: setting option sys_bin to /home/dmk/bin.
tlmgr: updating /home/dmk/.TinyTeX/tlpkg/texlive.tlpdb
> 
> # check if it worked
> tinytex::tlmgr(c('option', 'sys_bin'))
tlmgr option sys_bin
Destination for symlinks for binaries (sys_bin): /home/dmk/bin
> 
> tinytex::tlmgr_path()
> 

@dmkaplan2000
Copy link
Author

I also tried uninstall and then install and it seems to be working:

> tinytex::uninstall_tinytex()
tlmgr: no auxiliary texmf trees defined, so nothing removed
tlmgr: action conf returned an error; continuing.
tlmgr: An error has occurred. See above messages. Exiting.
> tinytex::install_tinytex()
trying URL 'https://yihui.org/tinytex/TinyTeX-1.tar.gz'
Content type 'application/octet-stream' length 92431591 bytes (88.1 MB)
==================================================
downloaded 88.1 MB

tlmgr option sys_bin ~/bin
tlmgr: setting option sys_bin to /home/dmk/bin.
tlmgr: updating /home/dmk/.TinyTeX/tlpkg/texlive.tlpdb
Warning message:
In do_once((if (is_R_CMD_check()) stop else warning)("The function xfun::isFALSE() will be deprecated in the future. Please ",  :
  The function xfun::isFALSE() will be deprecated in the future. Please consider using base::isFALSE(x) or identical(x, FALSE) instead.
> tinytex::tlmgr(c('option', 'sys_bin'))
tlmgr option sys_bin
Destination for symlinks for binaries (sys_bin): /home/dmk/bin
> tinytex::tlmgr_path()
> 
> tinytex::tlmgr_install("pdfcrop")
tlmgr install pdfcrop
tlmgr: package repository https://mirror.ctan.org/systems/texlive/tlnet (verified)
[1/2, ??:??/??:??] install: pdfcrop.x86_64-linux [1k]
[2/2, 00:01/00:31] install: pdfcrop [11k]
running mktexlsr ...
done running mktexlsr.
tlmgr: package log updated: /home/dmk/.TinyTeX/texmf-var/web2c/tlmgr.log
tlmgr: command log updated: /home/dmk/.TinyTeX/texmf-var/web2c/tlmgr-commands.log

It is a mystery why it didn't work before...

@yihui
Copy link
Member

yihui commented Feb 16, 2024

Indeed it is a mystery...

clrpackages pushed a commit to clearlinux-pkgs/R-knitr that referenced this issue Apr 9, 2024
Kyle F Butts (2):
      Add support for `# %%` for chunk demarcation in `knitr::spin` (#2307)
      make spin() recognize `#|` comments as code chunks (#2320)

Lee Mendelowitz (1):
      Fix the error when kable()'s caption value is of length > 1 (#2312)

Max Schmit (1):
      add ALTER as sql statment, that is not returning anything (#2330)

Yihui Xie (53):
      start the next version
      fix #2304: shouldn't have used `return(meta)` since `meta` is not the `citation()` but `packageDescription()`
      fix rstudio/rmarkdown#2526 by reverting bebf117 since the `cairo_pdf` device has been explicitly supported in chunk_device(); now all possible `pdf()` arguments are supported, including `family`
      Disallow unbalanced chunk delimiters (#2306)
      close #1679: obtain the caption from the chunk option `tab.cap` for `kable()`
      also try the chunk option tbl.cap when tab.cap is NULL (quarto-dev/quarto-cli#7555)
      tweak R Markdown v1 vignettes
      move mailing list link and use https in ref card
      move css and js to jsdelivr for html_vignette
      use jsdelivr for the Rhtml template
      rewrite the docco classic style using JS instead of R
      standardize the docco linear format
      new version of funmediation is on CRAN now
      support the ... argument in chunk hooks
      optimize PNG images in package vignettes via optipng and pngquant if they are installed
      use R Markdown v1 for the knitr-intro vignette, too
      delete some files that are no longer needed in inst/examples and also ignore some files
      fix #2308: don't trim trailing spaces escaped by `\`
      support in-body chunk options for ojs and mermaid (quarto-dev/quarto-cli#7799)
      amend 3dcfac4780accc3791855b298a556297f62dc73d to fix quarto-dev/quarto-cli#5994: add YAML options to code for dot/mermaid/ojs chunks so that the full chunk content can be returned to Quarto
      add trailing slashes to URLs
      use the `assert(fact, {})` syntax for all tests
      revert c9473ad: map the chunk option `tbl-cap` to `tab.cap`
      leave tbl.cap alone; don't convert it to tab.cap, since Quarto has its own special handling of `tbl-cap`
      Create FUNDING.yml
      use xfun::decimal_dot() to ensure dot as the decimal separator
      fix rstudio/rmarkdown#2525: ensure the dot is used as the decimal separator even when options(OutDec) is not `.` or `LC_NUMERIC` is inappropriate
      factor out code to xfun::csv_options() and xfun::divide_chunk()
      get_option_comment() has been moved to xfun
      roxygenize
      bump xfun version
      xfun 0.42 is on CRAN now
      revert 87d094a6c593c31a3667821865e91b4a530018ec per request from CRAN maintainers, since _R_CHECK_VIGNETTES_SKIP_RUN_MAYBE_=true has been made the default
      fix rstudio/tinytex#435: adjust PATH temporarily for pdf_crop() to be able to find the command `pdfcrop` from TinyTeX
      RStudio IDE still calls parse_params(): https://github.com/rstudio/rstudio/blob/9a6196233d8eae5aa365b73eaafba04f7714190c/src/cpp/session/modules/SessionRmdNotebook.R#L666
      a follow-up on #2331: use xfun::fenced_block() from yihui/xfun@22a97ce
      xfun 0.43 is on CRAN now
      not sure what's wrong with pak
      `knitr::imgur_upload()` is now simply a wrapper function of `xfun::upload_imgur()` (#2325)
      too many ways to do the same thing... drop support for `#-` in spin()
      make spin() work again with input that can't be parsed as R code
      use xfun::check_old_package()
      markdown no longer sets this option internally, so no need to empty it now
      better detection of Rmd v2 input in knit2html(), so it no longer warns against documents that use markdown:: or litedown:: output formats
      make regex a little stricter so it won't match rmarkdown::
      the loo issue has been fixed (#2306)
      roxygen2 requires _PACKAGE now
      rename class names 'block' to 'knitr_block', and 'inline' to 'knitr_inline' since I need to export the print() methods and the names 'block' and 'inline' are too general
      preserve trailing \n in source code by doubling it, because later we will remove trailing \n in fenced_block()
      a temporary workaround for davidgohel/flextable#621
      StructFDR has been updated on CRAN but unfortunately the maintainer didn't seem to have seen my email about #2306
      I can't use knitr_block/knitr_inline as class names since it would break the lightparser package; let me just get rid of these S3 methods, which are unnecessarily advanced---just use normal functions instead (i.e., use inherits() to do the dispatch by myself)
      CRAN release v1.46

knokknok (1):
      fix #2318: faster processing of dependencies in dep_auto() (#2321)
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Oct 26, 2024
(w3m -insecure -dump -T text https://github.com/yihui/knitr/releases)
knitr 1.48
BUG FIXES

  * Fix regression from 1.46 with collapse = TRUE option not correctly
    collapsing source code and output into one when code chunk returns multiple
    outputs (thanks, @jennybc, @florisvdh, tidyverse/reprex#463).

  * hook_purl() should not write the path of the R script to the output
    document (thanks, @fenguoerbian, #2348).

knitr 1.47
NEW FEATURES

  * For kable(), you can set the global option knitr.kable.max_rows to limit
    the number of rows to show in the table, e.g., options(knitr.kable.max_rows
    = 30). This is a way to prevent kable() from generating a huge table from a
    large data object by accident.

  * write_bib() now escapes all non-escaped "&" in the bibliography by default.
    Previously, it only escaped the title field of the package citation. You
    can disable the escape with the argument tweak = FALSE (thanks, @HedvigS #
    2335, @atusy #2342).

BUG FIXES

  * Fixed a bug that write_bib() fails to use the first URL of a package when
    multiple URLs are provided in DESCRIPTION and separated by \n (thanks,
    @bastistician, #2343).

MINOR CHANGES

  * The syntax highlighting LaTeX commands for Rnw documents, \hlstr and \
    hlstd, were renamed to \hlsng and \hldef, respectively, to maintain
    consistency with Andrew Simon's highlight package (thanks, @dcser123, #2341
    ).

knitr 1.46
NEW FEATURES

  * Added a new chunk option tab.cap to specify the table caption for kable()
    (thanks, @ulyngs, #1679). Previously, the caption could only be specified
    via the caption argument of kable(). Now you can set it in the chunk header
    if you want. Please note that this chunk option only works with a single
    kable() in each code chunk, and its value must be of length 1.

  * spin() now recognizes # %% as a valid code chunk delimiter (thanks,
    @kylebutts, #2307).

  * spin() also recognizes #| comments as code chunks now (thanks, @kylebutts,
    #2320).

  * Chunk hooks can have the ... argument now. Previously, only arguments
    before, options, envir, and name are accepted. If a chunk hook function has
    the ... argument, all the aforementioned four arguments are passed to the
    hook. This means the hook function no longer has to have the four arguments
    explicitly in its signature, e.g., function(before, ...) is also valid if
    only the before argument is used inside the hook. See https://yihui.org/
    knitr/hooks/#chunk-hooks for more information.

  * For package vignettes, PNG plots will be optimized by optipng and pngquant
    if they are installed and can be found from the system PATH variable. This
    can help reduce the package size if vignettes contain PNG plots (thanks,
    @nanxstats, https://nanx.me/blog/post/rpkgs-pngquant-ragg/).

BUG FIXES

  * spin() stopped working with input that cannot be parsed as R code due to #
    1605. Now it works again (thanks, @Hemken, #1773).

  * write_bib() generated empty entries for packages without URLs (thanks,
    @bastistician, #2304).

  * The family argument was not passed to the pdf device (thanks, @sebkopf,
    rstudio/rmarkdown#2526).

  * Trailing spaces escaped by \ should not be trimmed in kable() (thanks,
    @mjsmith037, #2308).

  * kable() fails when the value of the caption argument is of length > 1
    (thanks, @LeeMendelowitz, #2312).

  * include_graphics() may provide an incorrect plot width to LaTeX when the
    locale setting for LC_NUMERIC is not C because the decimal separator may
    not be a dot (thanks, @tdhock, rstudio/rmarkdown#2525).

  * When TinyTeX and the LaTeX package pdfcrop are installed, knitr::pdf_crop()
    is unable to find pdfcrop (thanks, @dmkaplan2000, rstudio/tinytex#435).

MAJOR CHANGES

  * Unbalanced chunk delimiters (fences) in R Markdown documents are no longer
    allowed, as announced two years ago at https://yihui.org/en/2021/10/
    unbalanced-delimiters/ (#2306). This means the opening delimiter must
    strictly match the closing delimiter, e.g., if a code chunk starts with
    four backticks, it must also end with four; or if a chunk header is
    indented by two spaces, the closing fence must be indented by exactly two
    spaces. For authors who cannot update their R Markdown documents for any
    reason at the moment, setting options(knitr.unbalanced.chunk = TRUE) (e.g.,
    in .Rprofile) can temporarily prevent knitr from throwing an error, but it
    is strongly recommended that you fix the problems as soon as possible,
    because this workaround will be removed in future.

  * Package vignettes are tangled by default during R CMD check, per request
    from CRAN maintainers (d0d1b47). The consequence is that R CMD check will
    check R scripts tangled from vignettes by default, unless you set the
    environment variable _R_CHECK_VIGNETTES_SKIP_RUN_MAYBE_=true. Previously,
    knitr would skip tangling vignettes during R CMD check, because R scripts
    tangled from vignettes are not guaranteed to valid. With the skip undone, R
    CMD check may fail in places other than CRAN (because CRAN has set the
    environment variable).

MINOR CHANGES

  * Fixed broken vignettes, improved CSS for HTML vignettes, and reduced the
    file sizes.

  * SQL code chunks that run ALTER statements are only executed and not tried
    to fecth a result (thanks, @maxschmi, #2330).

  * The function imgur_upload() has been moved to (and enhanced in) the xfun
    package as xfun::upload_imgur() so it is no longer tied to knitr and can be
    reused by other pakages. Now knitr::imgur_upload() is only a wrapper
    function of xfun::upload_imgur(). You are recommended to use the latter (#
    2325).

  * spin() dropped support for #- as the chunk delimiter token. Please use #+
    or # %% or #| instead.

  * Faster processing of cache dependencies in dep_auto() (thanks, @knokknok, #
    2318).

  * Removed some S3 methods that are used internally and changed them to normal
    functions: print.block -> print_block, print.inline -> print_inline,
    process_group.block/process_group.inline -> process_group, and
    process_tangle.block/process_tangle.inline -> process_tangle.

knitr 1.45
NEW FEATURES

  * Improved the error message to contain more specific information when YAML
    chunk options could not be parsed (thanks, @pedropark99, #2294).

BUG FIXES

  * Special characters in the chunk option fig.alt are properly escaped now
    (thanks, @jay-sf, #2290).

  * Negative numbers returned from inline R expressions lost their minus signs
    when formatted in the scientific notation (thanks, @fkohrt, #2288).

  * convert_chunk_header(type = 'yaml') will now use dash option name for known
    knitr options, and numeric option are kept with same significant digits,
    e.g fig.width = 10 is converted to fig-width: 10.

  * Add the necessary \newline to the last subfigure (thanks, @slrellison,
    rstudio/rmarkdown#2518).

  * Percent signs (%) in LaTeX figure captions and short captions are properly
    escaped now (thanks, @s-u, #2302).

MAJOR CHANGES

  * The object opts_current will be restored after each code chunk has finished
    executing. Previously, it would not be restored, which means even for
    inline R expressions, opts_current$get() will inherit chunk options from a
    previous code chunk (thanks, @rundel, #1988). Besides, opts_current$get
    ('label') will return a unique label for inline expressions. One possible
    application is to construct unique figure paths via fig_path() (e.g.,
    ropensci/magick#310).

  * opts_current$set() without opts_current$lock(FALSE) will trigger a warning
    instead of an error for now and it will become an error in future (#2296).

knitr 1.44
NEW FEATURES

  * kable() can generate Emacs org-mode tables now via kable(..., format =
    'org') (thanks, @xvrdm #1372, @maxecharel #2258).

  * Added support for the qmd (Quarto) output format to spin(), e.g., spin
    ('script.R', format = 'qmd') (thanks, @cderv, #2284).

  * write_bib() has a new argument packageURL to control whether to use a URL
    from the DESCRIPTION file or the one generated by utils::citation()
    (thanks, @dmurdoch, #2264).

  * Updated the package vignette vignette('knit_print', 'knitr') to mention
    that package authors no longer have to make knitr a hard dependency if they
    want to define S3 methods for knitr::knit_print with R >= 3.6.0 (thanks,
    @cderv, #1929).

  * Added a new function download_image() to download an image from a URL and
    include it via include_graphics(). This is mainly for including online
    images when the output format is not HTML (e.g., LaTeX), because the URL
    will not work as the image path, and it has to be downloaded beforehand
    (thanks, @bayeslearner, #2274).

BUG FIXES

  * Make the internal function add_html_caption() work with Quarto <= v1.3.353
    (thanks, @giabaio, #2261).

  * Fixed a bug in spin(format = 'Rnw') reported by @Tarious14 at yihui/
    yihui.org#769 (reply in thread)

  * When the chunk option dev = 'svglite', the svglite device should be used to
    record plots (thanks, @Darxor, #2272).

  * Figure captions are no longer escaped for reStructuredText output, and the
    alt text can also be specified via the fig.alt chunk option now (thanks,
    @trevorld, #2023).

  * Use the correct type of progress bar when rendering Quarto documents in
    RStudio, which takes place in RStudio's background jobs pane or build pane
    (thanks, @hadley, #2271).

  * The opts_current object can no longer be modified within code chunks via
    its $set() method (thanks, @AshesITR, #1798).

  * The argument col.names of kable() can be used to specify the column name of
    row names now, e.g., kable(head(mtcars), col.names = c("car", names
    (mtcars))) ("car" will be the column name of row names in the first column)
    (thanks, @iago-pssjd, #1933).

MAJOR CHANGES

  * Dashes (-) in the names of all chunk options are normalized to dots (.)
    now, e.g., fig-height will be converted to fig.height. This is to make
    knitr more compatible with Quarto since Quarto always use dashes in chunk
    option names (#2282).

MINOR CHANGES

  * In-body chunk options (#|) are now preserved when extracting code from a
    document via purl() (thanks, @LuisLauM, #2268).

  * A warning message will be issued when taking PDF screenshots for HTML
    widgets with the webshot2 package, because webshot2 doesn't use the correct
    figure size at the moment (thanks, @icejean, #2276).

  * If the title argument of knit2wp() is omitted and a title field is
    specified in the YAML metadata of the input document, the YAML title will
    be used (thanks, @arencambre, #1924).
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