rmarkdown
rmarkdown copied to clipboard
PDF document fails to compile when output file argument contains absolute path with tilde in Windows
The tilde abbreviation of a folder name can (apparently) happen automatically in Windows.
I noticed it because I created an absolute file path for the output PDF file in the temporary folder from windows, for use in unit tests. The temporary folder file path will contain a tilde abbreviation if the Windows user name is long (for example, "C:/Users/Johnny with Long Name" will be abbreviated to "C:/Users/JOHNNY~1").
The problem only occurs with creating PDF documents, when attempting to convert the intermediate latex document to PDF.
See reprex below:
EDIT: fixed reprex
# This will error under windows:
local({
folder_name <- "VERY_L~1"
temp_dir <- file.path(tempdir(), folder_name)
dir.create(temp_dir)
temp_rmd <- file.path(temp_dir, "test.Rmd")
temp_report <- file.path(temp_dir, "report.pdf")
on.exit(unlink(temp_dir, recursive = TRUE))
writeLines("---\ntitle: 'Test report'\n---\n\ntest report", temp_rmd)
rmarkdown::render(temp_rmd, output_file = temp_report)
})
# but this will not error:
local({
folder_name <- "VERY_L~1"
temp_dir <- file.path(tempdir(), folder_name)
dir.create(temp_dir)
temp_rmd <- file.path(temp_dir, "test.Rmd")
## removed report absolute file path:
temp_report <- "report.pdf"
on.exit(unlink(temp_dir, recursive = TRUE))
writeLines("---\ntitle: 'Test report'\n---\n\ntest report", temp_rmd)
rmarkdown::render(temp_rmd, output_file = temp_report)
})
Output results:
Error: LaTeX failed to compile *****\AppData\Local\Temp\Rtmp2ttLaR/VERY_L~1/report.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips.
tex log created:
This is pdfTeX, Version 3.141592653-2.6-1.40.26 (TeX Live 2024) (preloaded format=pdflatex 2024.5.3) 6 MAY 2024 12:41
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
****AppData/Local/Temp/Rtmp2ttLaR/VERY_L~1/report.tex
! Emergency stop.
<to be read again>
\protect
<*> *****/AppData/Local/Temp/Rtmp2ttLaR/VERY_L~
1/report.tex
Here is how much of TeX's memory you used:
4 strings out of 476009
111 string characters out of 5789395
1925754 words of memory out of 5000000
22279 multiletter control sequences out of 15000+600000
558069 words of font info for 36 fonts, out of 8000000 for 9000
14 hyphenation exceptions out of 8191
2i,0n,0p,1b,6s stack positions out of 10000i,1000n,20000p,200000b,200000s
! ==> Fatal error occurred, no output PDF file produced!
Session Info
R version 4.4.0 (2024-04-24 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows 11 x64 (build 22631) Locale: LC_COLLATE=English_Germany.utf8 LC_CTYPE=English_Germany.utf8 LC_MONETARY=English_Germany.utf8 LC_NUMERIC=C LC_TIME=English_Germany.utf8Package version:
base64enc_0.1.3 bslib_0.7.0 cachem_1.0.8 cli_3.6.2 digest_0.6.35 evaluate_0.23
fastmap_1.1.1 fontawesome_0.5.2 fs_1.6.4 glue_1.7.0 graphics_4.4.0 grDevices_4.4.0
highr_0.10 htmltools_0.5.8.1 jquerylib_0.1.4 jsonlite_1.8.8 knitr_1.46 lifecycle_1.0.4
memoise_2.0.1 methods_4.4.0 mime_0.12 R6_2.5.1 rappdirs_0.3.3 rlang_1.1.3
rmarkdown_2.26.2 sass_0.4.9 stats_4.4.0 tinytex_0.50 tools_4.4.0 utils_4.4.0
xfun_0.43 yaml_2.3.8
Pandoc version: 3.1.11
Checklist
When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:
-
[x] formatted your issue so it is easier for us to read?
-
[x] included a minimal, self-contained, and reproducible example?
-
[x] pasted the output from
xfun::session_info('rmarkdown')
in your issue? -
[x] upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?
-
[x] installed and tested your bug with the development version of the rmarkdown package using
remotes::install_github("rstudio/rmarkdown")
?