Rmarkdown生成html时,中文显示乱码
tctcab
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)China.936
[2] LC_CTYPE=Chinese (Simplified)China.936
[3] LC_MONETARY=Chinese (Simplified)China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_2.2.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.17 digest_0.6.15 rprojroot_1.3-2 plyr_1.8.4
[5] grid_3.5.0 gtable_0.2.0 backports_1.1.2 magrittr_1.5
[9] scales_0.5.0 evaluate_0.10.1 pillar_1.2.3 highr_0.6
[13] rlang_0.2.1 stringi_1.1.7 lazyeval_0.2.1 rmarkdown_1.9.17
[17] labeling_0.3 tools_3.5.0 stringr_1.3.1 munsell_0.4.3
[21] yaml_2.1.19 compiler_3.5.0 colorspace_1.3-2 htmltools_0.3.6
[25] knitr_1.20 tibble_1.4.2
tctcab
还有就是在Rstudio中,是可以直接编码显示中文的,不会乱码。
新 <- mtcars
str(新)
'data.frame': 32 obs. of 11 variables:
$ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
$ cyl : num 6 6 4 6 8 6 8 4 4 6 ...
$ disp: num 160 160 108 258 360 ...
$ hp : num 110 110 93 110 175 105 245 62 95 123 ...
$ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
$ wt : num 2.62 2.88 2.32 3.21 3.44 ...
$ qsec: num 16.5 17 18.6 19.4 17 ...
$ vs : num 0 0 1 1 0 1 0 1 1 1 ...
$ am : num 1 1 1 0 0 0 0 0 0 0 ...
$ gear: num 4 4 4 3 3 3 3 4 4 4 ...
$ carb: num 4 4 1 1 2 1 4 2 2 4 ...
newlife 如果文件编码是 UTF-8,那么需要 rmarkdown::render('你的文件.Rmd', encoding = 'UTF-8')
。
yihui
谢老大,既然你出现了,我就厚颜再问一个问题。
运行含有shiny语句和中文的UTF-8形式的Rmd文件,直接运行run语句,中文无法正常显示,
但运行如下的语句:
rmarkdown::run("E:/R/shiny.Rmd", render_args=list(encoding = 'UTF-8')),返回的提示是
Error in yaml::yaml.load(string, ...) :
Reader error: invalid trailing UTF-8 octet: #DA at 9
这要咋个处理啊?含shiny语句的UTF-8形式的Rmd文件,run语句中的参数该咋设置啊?
叩谢谢老大!!