为了精简我的Rmarkdown代码,我想在R文件中写一些代码,然后源代码到Rmarkdown:
my_script_01.R
library(tidyverse)
df1 <- tribble(
~id, ~col1,
1, "Ãb",
2, "Ab",
3, "ÃB",
4, "OB"
)
df1
df2 <- tibble(id = c(1:4),
tester = c("umlaut", "no_umlaut", "umlaut", "no_umlaut"))
df3 <- left_join(df1, df2, by="id")
原则上,它运行良好:
-
只有当我用德语元音变音符(¥,等)来源代码时,源代码不能正常工作,它会给出奇怪的字母(蓝色矩形,代码1)。
-
如果我把代码放在r标记块中,那么一切都很完美(红圈,代码2)
Rmd代码1:
---
title: "test"
author: "Me"
date: '2022-06-25'
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
source("my_script_01.R")
```
```{r}
df3 %>%
count(col1) %>%
ggplot(aes(x=col1, y=n)) +
geom_col()+
theme_minimal(base_size = 26)
```
Rmd代码2:
---
title: "test"
author: "Me"
date: '2022-06-25'
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
source("my_script_01.R")
```
```{r}
df1 <- tribble(
~id, ~col1,
1, "Ãb",
2, "Ab",
3, "ÃB",
4, "OB"
)
df2 <- tibble(id = c(1:4),
tester = c("umlaut", "no_umlaut", "umlaut", "no_umlaut"))
df3 <- left_join(df1, df2, by="id")
df3 %>%
count(col1) %>%
ggplot(aes(x=col1, y=n)) +
geom_col()+
theme_minimal(base_size = 26)
```
我的默认文本编码是UTF-8。
我想知道为什么会出现这种行为,以及是否有可能从德语元音变音符中找到来源。
例如,我环顾四周
here
或
here
但无法找到解决方案。