title: Read in file with UTF-8 character in path in R
body: <p>Let's assume I have a large amount of *.rds files with some have UTF-8 characters in their path. For some reason R can't handle some special accents. For example <code>enc2utf8(&quot;Č&quot;)</code>, which should print &quot;Č&quot; but on my end it converts to 'C&quot; which makes it impossible for R to recognize the file. Any ideas how to handle such cases/help R with the encoding?</p>
  <p>Session info output :</p>
  <pre><code>&gt;session.info()
  R version 4.0.2 (2020-06-22)
  Platform: x86_64-w64-mingw32/x64 (64-bit)
  Running under: Windows 10 x64 (build 19043)
  
  Matrix products: default
  
  locale:
  [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
  [4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
   [1] lubridate_1.7.9 here_0.1        forcats_0.5.0   stringr_1.4.0   dplyr_1.0.2     purrr_0.3.4    
   [7] readr_1.3.1     tidyr_1.1.2     tibble_3.0.3    ggplot2_3.3.2   tidyverse_1.3.0
  
  loaded via a namespace (and not attached):
   [1] Rcpp_1.0.5       cellranger_1.1.0 pillar_1.4.6     compiler_4.0.2   dbplyr_1.4.4     tools_4.0.2     
   [7] jsonlite_1.7.2   lifecycle_1.0.0  gtable_0.3.0     pkgconfig_2.0.3  rlang_0.4.10     reprex_0.3.0    
  [13] cli_2.4.0        DBI_1.1.0        rstudioapi_0.13  haven_2.3.1      withr_2.4.2      xml2_1.3.2      
  [19] httr_1.4.2       fs_1.5.0         generics_0.1.0   vctrs_0.3.3      hms_0.5.3        rprojroot_1.3-2 
  [25] neuralnet_1.44.2 grid_4.0.2       tidyselect_1.1.0 glue_1.4.2       R6_2.4.1         readxl_1.3.1    
  [31] modelr_0.1.8     blob_1.2.1       magrittr_1.5     backports_1.1.9  scales_1.1.1     ellipsis_0.3.1  
  [37] rvest_0.3.6      assertthat_0.2.1 colorspace_1.4-1 stringi_1.4.6    munsell_0.5.0    broom_0.7.0     
  [43] crayon_1.3.4   
  </code></pre>
  <p>@EDIT I :</p>
  <p>Clarification : R can't read the file path due to UTF-8 characters in the file name.</p>
  <p>Original file path example : G:/Users/SomeUser/Documents/University/2021/Project_M/data/procyclingstats/BORA_hansgrohe/POLJAŃSKI_Paweł_sprinter_point.rds</p>
  <p>Neither <code>readRDS</code> from <code>base</code> nor <code>read_rds</code> from the <code>readr</code> package can encode the path correctly.</p>
  <p>Both produce the following error :</p>
  <blockquote>
  <p>Error in gzfile(file, &quot;rb&quot;) : cannot open the connection In addition:
  Warning message: In gzfile(file, &quot;rb&quot;) :   cannot open compressed file
  '</p>
  <p>G:/Users/SomeUser/Documents/University/2021/Project_M/data/procyclingstats/BORA_hansgrohe/POLJANSKI_Pawel_sprinter_point.rds',
  probable reason 'No such file or directory</p>
  </blockquote>
  <p>I don't load the paths with a sourced *.txt file but have a function which creates a list of files in given directories.</p>
  <p>This function prints the file path correctly. So it's not a problem with my way to concatenate the path-string .</p>
  <pre><code> str_c(outputDIR_pro[i],
                     sub(&quot;.+/data/Strava/.+/([0-9]+?).txt&quot;, &quot;\\1&quot;, athlethes[[i]][[j]]) %&gt;% str_match('\\d+') %&gt;% 
                      str_detect(names_id_vec,.) %&gt;%
                       names_id_vec[.] %&gt;%
                       str_remove('\\d+;'),'_sprinter_point', '.rds') # %&gt;% readRDS
  [1] &quot; G:/Users/SomeUser/Documents/University/2021/Project_M/data/procyclingstats/BORA_hansgrohe /POLJAŃSKI_Paweł_sprinter_point.rds&quot;
  </code></pre>