Since I have an umlaut (special character) in the path, sourcing a cpp file using Rcpp throws the error that the file is not found.
I am working in R-Studio under Windows. Sourcing R files works well when I use the function source
, since it allows to set the encoding.
source_dir <- "D:/path/with/umläut/inside"
source(paste0(source_dir, "/some_r_file.R"), encoding = "UTF-8")
However, when I source a cpp file:
Rcpp::sourceCpp(paste0(source_dir, "/portfolio.cpp"))
I get the following error:
Error in Rcpp::sourceCpp(paste0(source_dir, "/portfolio.cpp"))
file not found: 'D:/path/with/umläut/inside/portfolio.cpp'
This is because under the current encoding ä in the variable source_dir
is interpreted as ä. I had the same issue with the function source
and the encoding = "UTF-8"
option solved it. However, it seems that the function Rcpp::sourceCpp
does not allow the encoding and I don't know how to set it.
Any idea on how can I get around this?