我用R语言读一个中文路径的文件时
relative_path="C:/路径/"
fread(str_c(relative_path,"a.csv"))
报错
Error in fread(str_c(relat_path, "sy.csv")) :
Unable to open file after 5 attempts (error 3): C:/璁$畻鏈哄/sy.csv
但是直接fread("C:/路径/a.csv")
就可以正确读取文件。
另外直接读变量的编码如下所示
>Encoding(str_c(relat_path,"a.csv"))
[1] "UTF-8"
> Encoding("C:/路径/a.csv")
[1] "unknown"
locale设置为中文,Rstudio里面设置成了UTF-8
sessioninfo()
R version 3.5.1 (2018-07-02)
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 LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936 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] lubridate_1.7.4 forcats_0.3.0 stringr_1.3.1 dplyr_0.7.6
[5] purrr_0.2.5 readr_1.1.1 tidyr_0.8.1 tibble_1.4.2
[9] ggplot2_3.0.0 tidyverse_1.2.1 data.table_1.11.4 BiocInstaller_1.30.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.18 cellranger_1.1.0 pillar_1.3.0 compiler_3.5.1 plyr_1.8.4
[6] bindr_0.1.1 tools_3.5.1 jsonlite_1.5 nlme_3.1-137 gtable_0.2.0
[11] lattice_0.20-35 pkgconfig_2.0.2 rlang_0.2.2 cli_1.0.0 rstudioapi_0.7
[16] yaml_2.2.0 haven_1.1.2 bindrcpp_0.2.2 withr_2.1.2 xml2_1.2.0
[21] httr_1.3.1 hms_0.4.2 grid_3.5.1 tidyselect_0.2.4 glue_1.3.0
[26] R6_2.2.2 readxl_1.1.0 modelr_0.1.2 magrittr_1.5 backports_1.1.2
[31] scales_1.0.0 rvest_0.3.2 assertthat_0.2.0 colorspace_1.3-2 stringi_1.1.7
[36] lazyeval_0.2.1 munsell_0.5.0 broom_0.5.0 crayon_1.3.4