Skip to content

set the LANG env when rendering rmarkdown#961

Merged
renkun-ken merged 2 commits intoREditorSupport:masterfrom
shrektan:fix933
Feb 3, 2022
Merged

set the LANG env when rendering rmarkdown#961
renkun-ken merged 2 commits intoREditorSupport:masterfrom
shrektan:fix933

Conversation

@shrektan
Copy link
Copy Markdown
Contributor

@shrektan shrektan commented Feb 3, 2022

What problem did you solve?

Closes #933

The process.env doesn't contain the LANG environment variable. Thus, when the child process calls R, R will set the locale to "C". This causes an issue that UTF-8 strings can't be corrected handled.

(If you have)Screenshot

image

(If you do not have screenshot) How can I check this pull request?

Open the below Rmd file in VSCode. Click the knit button to render the file. View the generated HTML file you will see:

(I only verified this on macOS and Windows. On Windows, setting the LANG won't affect the locale anyway.)

  1. Before: The locale is "C" and there's no string or garbaged string in the left-bottom corner.
  2. After: The locale is "xxx_UTF-8" and the left-bottom displays "科比", as expected.
---
title: "minimal example"
author: "Kobe Bryant"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F, warning = F, message = F, eval = T)
```

Chinese character in the main article can be rendered normally.
(正文区的中文可以正确的渲染)

Figure legends cannot be rendered normally.

```{r, fig.cap = "科比"}
print(Sys.getlocale())
plot(1:5, 1:5)
```

Copy link
Copy Markdown
Member

@renkun-ken renkun-ken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected. LGTM. Thanks!

@renkun-ken renkun-ken merged commit 41ba420 into REditorSupport:master Feb 3, 2022
@shrektan shrektan deleted the fix933 branch February 3, 2022 08:52
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

Successfully merging this pull request may close these issues.

Rmarkdown inside the VSCode-R cannot render Chinese character in figure/table caption correctly

2 participants