是否可以使用knitr和R-studio将字母“æ”,“ø”和“å”作为R演示文稿中的变量名称? 我发现我不能将这些字母用作变量名。
以下代码显示了1个可用的块,以及3个没有的块。 3个不起作用的块使用“æ”,“ø”或“å”:
minimal slide that works:
================================
```{r}
# iris$nal <- "works"
```
minimal slide which dont work 1
==================================
```{r}
# iris$næl <- "dontwork"
```
minimal slide which dont work 2
==================================
```{r}
# iris$nøl <- "dontwork"
```
minimal slide which dont work 3
===================================
```{r}
iris$nål <- "dontwork"
```
(我已经注释掉了一些行,删除#以查看该块的错误)
奇怪的是,每封信都会收到不同的错误消息。对于“æ”和“ø”,我收到一条明显的错误信息:
Error in parse(text = x, srcfile = src) : <text>:2:9: unexpected input
1:
2: iris$næ
但是对于“å”,我得到了一个更加模糊的错误信息(至少对我来说是模糊的)
processing file: minimal4.Rpres
Warning in block_exec(params) :
the package option stop_on_error was deprecated; use the chunk option error = FALSE instead
Warning in block_exec(params) :
the package option stop_on_error was deprecated; use the chunk option error = FALSE instead
Warning in block_exec(params) :
the package option stop_on_error was deprecated; use the chunk option error = FALSE instead
Warning in block_exec(params) :
the package option stop_on_error was deprecated; use the chunk option error = FALSE instead
我使用UTF-8编码。 SessionInfo()
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] xtable_1.7-1 plyr_1.8 scales_0.2.3 ggplot2_0.9.3.1 knitr_1.5 XML_3.98-1.1 markdown_0.6.3
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 dichromat_2.0-0 digest_0.6.3 evaluate_0.5 formatR_0.9 grid_3.0.2
[7] gtable_0.1.2 labeling_0.2 MASS_7.3-29 munsell_0.4.2 proto_0.3-10 RColorBrewer_1.0-5
[13] reshape2_1.2.2 stringr_0.6.2 tools_3.0.2
答案 0 :(得分:2)
这是一个评论,但它没有作为评论正确格式化。
作为一种解决方法,如果你使用反引号,例如:
iris$`næl` <- "nowworks"
文档编译,你得到包含反引号的输出。
您还可以使用[
作为选择变量的方法,例如:
iris["nål"] <- "nowworks"