-
-
Notifications
You must be signed in to change notification settings - Fork 978
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
pdflatex error when rendering in locale LC_NUMERIC=fr_FR.UTF-8 #2525
Comments
Do you mean this only occurs for the |
r engine works fine, for example this MRE works: cat('---
title: "R code chunk test"
author: "Toby Dylan Hocking"
output:
beamer_presentation:
dev: png
---
```{r}
Sys.setlocale("LC_NUMERIC","fr_FR.UTF-8")
(width <- 4.5)
```
```{r fig.width=width}
plot(1:4)
```
', file="fig-size-bug.Rmd")
rmarkdown::render("fig-size-bug.Rmd")
system("grep 4,5 fig-size-bug.tex")
xfun::session_info("rmarkdown") |
FWIW On windows I can't reproduce this with latest RStudio version too Session info after rendering
If I do Also using latest reticulate > xfun::session_info("reticulate")
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621), RStudio 2023.12.0.201
Locale:
LC_COLLATE=French_France.utf8
LC_CTYPE=French_France.utf8
LC_MONETARY=French_France.utf8
LC_NUMERIC=fr_FR.UTF-8
LC_TIME=French_France.utf8
time zone: Europe/Paris
tzcode source: internal
Package version:
graphics_4.3.1 grDevices_4.3.1
grid_4.3.1 here_1.0.1
jsonlite_1.8.7 lattice_0.21.9
Matrix_1.6.1.1 methods_4.3.1
png_0.1.8 rappdirs_0.3.3
Rcpp_1.0.11 RcppTOML_0.2.2
reticulate_1.34.0.9000 rlang_1.1.1
rprojroot_2.0.3 stats_4.3.1
utils_4.3.1 withr_2.5.1 |
Hi @yihui can you please have a second look about fixing this in knitr? I'm not sure this is reticulate issue, and it's not clear to me what we can do to fix it in reticulate. In reticulate::eng_python() we only read chunk options options$fig.width and options$fig.height and pass them through to the appropriate python contexts for rendering plots; we don't munge on the options any further, and return them unmodified. I think this might be a knitr::include_graphics() bug, since that's how reticulate includes python plots, and is a difference between the Python MRE and the R examples in #2525 (comment) |
I confirm this is still an issue for me with the following package versions:
|
Thanks! That's it. The problem came from here: https://github.com/yihui/knitr/blob/a14074c58e46fb51f61b219c8a195a8ef4914971/R/plot.R#L534 I'm not sure what we should do about it, though. R will warn against setting
The problem is that decimal points will be commas after you change Another solution is specify the chunk option |
hi! thanks for suggesting the The fix that I would suggest in your code is to temporarily set LC_NUMERIC to C when you convert numeric/fig.width (4.5) to text/out.width, and then switch locale back to whatever the user had before that. This issue should affect anybody in French speaking countries, with a French locale on their computer, so I'm surprised I'm the only one having reported this issue so far. Even though R warns that it may function strangely, most people in French speaking countries probably do want to display code chunk numeric decimal output using the traditional French comma/virgule/, (instead of the English period/point/.) cat('---
title: "matplotlib test"
author: "Toby Dylan Hocking"
output:
beamer_presentation:
dev: png
---\n```{r}
Sys.setenv(RETICULATE_PYTHON="/home/tdhock/miniconda3/envs/2023-08-artificial-intelligence/bin/python")
width.in <- 4.5
Sys.setlocale("LC_NUMERIC", "C")
(out.width <- paste0(width.in,"in"))
Sys.setlocale("LC_NUMERIC", "fr_FR.UTF-8")
width.in
\n```\n```{python out.width=out.width}
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.show()\n```
', file="fig-size-bug.Rmd")
rmarkdown::render("fig-size-bug.Rmd") |
(note that I am french) Usually, I will do that in the formatting function to set comma in printed values. There is also a global option for this (that
But this can cause issues with functions and packages that do not handle this correctly especially if the value printed must have a I think even using Anyhow, It explains the warning you see. So I am not sure this should be used to change a period to a comma. Not sure we should handle it either directly. Though, maybe we should ensure to use I don't remember any report of this though, so maybe it is just due to LC_NUMERIC change. 🤷 |
@tdhock Using the French locale should be fine. The problem arises only when you manipulate Even under the French locale,
My locale is Can we fix it? Yes we can, but I wish to understand why the problem occurs first. As I said, even we fix this specific problem in knitr, there is a chance that @cderv We have been bitten by this |
thanks for the detailed comments/feedback. Actually to clarify, I'm not setting the LC_NUMERIC specifically in my code usually, I just did that in the code above for reproducibility. On my computer (Ubuntu jammy) the LC_NUMERIC locale is fr_FR.UTF-8 by default, which is why I filed the issue in the first place (and it took me quite a while to figure out the comma issue, so by filing this issue I am trying to avoid similar headaches for others in the future). |
Okay. We'll fix this particular issue and rethink how we could address similar problems if they arise in the future. Thanks for the report! |
…l be fixed in knitr later
Should be fixed in the development version of knitr now: remotes::install_github('yihui/knitr') |
works now, thanks very much.
|
Sure. Done: remotes::install_github('yihui/xfun') |
Yihui Xie (32): start the next version deprecate isFALSE() for all users (not limiting to R CMD check) (#75) v could be NULL when the error message doesn't contain the version info I expected the number of revdeps of knitr has exceeded the limit of AWS batch jobs, so check at most 9000 revdeps at a time allow for pkgs = character(0) get_fun() was used earlier vectorize check_old_package() submit all groups of jobs at once, and then wait for them to finish, instead of submitting sequentially add news for #75 add a link to the error message, and delete examples of isFALSE() point out the possibly outdated packages to make it easier for users to know what to do with the deprecation of xfun::isFALSE: yihui/yihui.org#1470 (comment) add the `envir` argument to `yaml_load()` add ... argument to yaml_body() add a `merge_comments` argument to `split_source()` no need to `<<-` since broken is in scope no need to use xfun:: inside this package Create FUNDING.yml add a `skip` argument to split_source() so that it's possible to skip the rest of code when the skip token is found make split_lines() work with \r\n, too let the `skip` argument of split_source() take value from a global option store the source line number in split_source() output add a function `record()` to record the results of R code factor out some code from knitr to this package as functions csv_options() and divide_chunk() put record.css at the end to prioritize its rules add a `line_number` argument to split_source() import grDevices for record() on Windows, an empty new plot file is created (and locked) upon opening a device, so we need to clean up plot files before opening the device, otherwise we can't delete the initial empty file a helper function decimal_dot() for rstudio/rmarkdown#2525, which will be fixed in knitr later update license year don't return the engine in the divide_chunk() output (it would be a break change: https://github.com/yihui/knitr/actions/runs/7809970020) suppress warnings from Sys.setlocale('LC_NUMERIC'): rstudio/rmarkdown#2525 (comment) CRAN release v0.42
# CHANGES IN xfun VERSION 0.42 - `isFALSE()` has been fully deprecated for R >= 3.5.0, and will be completely removed from this package in the future (<https://yihui.org/en/2023/02/xfun-isfalse/>). - Added a function `record()` to run R code and record the results, which is similar to `evaluate::evaluate()` but less sophisticated and technically simpler. One major difference is that `xfun::record()` records plots directly to files instead of saving them as display lists. - `yaml_load()` gained an `envir` argument, which can be used to specify the environment to evaluate R expressions in YAML (i.e., expressions written after `!expr` or `!r`). This is not straightforward in the upstream **yaml** package (thanks, @viking, vubiostat/r-yaml#54). - `yaml_body()` gained the `...` argument to pass more arguments to `yaml_load()`. - `split_source()` gained a `merge_comments` argument to merge consecutive lines of comments into the next code block, a `line_number` argument to store the line number of each expression in the returned value, and a `skip` argument to skip the rest of the code when the skip token is found. - `check_old_package()` has been vectorized, i.e., the arguments `name` and `version` can take vectors now. - Factored out the code for parsing chunk options and dividing a chunk into chunk options and chunk body from **knitr** to this package as functions `csv_options()` and `divide_chunk()`, respectively. They will be used by **knitr** and other packages in future. - Added a function `decimal_dot()` to evaluate an expression after forcing `options(OutDec = '.')` and `Sys.setlocale(LC_NUMERIC = 'C')` (for rstudio/rmarkdown#2525).
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)
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. |
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")
?Hi! first of all, thanks very much for supporting the rmarkdown package, which I find very useful.
I am trying to render Rmd to beamer slides on a computer with LC_NUMERIC=fr_FR.UTF-8 meaning that the decimal separator prints as a comma (one half is 0,5).
I expected that I should be able to render rmarkdown to beamer slides, but I observe that there is an error.
The issue is that there is a line in the generated tex file which looks like
\includegraphics[width=4,5in]{figure}
and that is problematic because pdflatex interprets the comma as a separator between optional arguments in the [ ].The issue only happens when dev: png is specified in the yaml header.
The work-around that users can do, is to set LC_NUMERIC=C, and then the compilation works fine.
The fix in the rmarkdown package is to change the comma to a period,
\includegraphics[width=4.5in]{figure}
or maybe to set LC_NUMERIC=C while generating the tex file?Below is a minimal reproducible example R script
When running the code above on my system, the output is shown below:
Please note that in the grep command, the first 4,5 is expected, because I set the french locale in my Rmd, so I would like to see that in the generated R code chunk output blocks (but it should be 4.5 in the tex file includegraphics width line).
The text was updated successfully, but these errors were encountered: