Hi all,

If an Rcpp function throw an exception with UTF-8 encoding strings, the error 
message in R will lose the encoding setting. And the error message will be 
displayed as some other characters on Windows.

Here is an example:

    library(Rcpp)
    sourceCpp(code = "
    #include <Rcpp.h>
     
     // [[Rcpp::export]]
     void error_with_unicode(std::string input){
         Rcpp::stop(input);
    }
     ")

    error_with_unicode(enc2utf8("????"))
    #> Error: ??????

    tmp = try(error_with_unicode(enc2utf8("????")))
    #> Error : ??????

    Encoding(tmp)
    #> [1] "unknown"

    tmp
    #> [1] "Error : ??????\n"
    #> attr(,"class")
    #> [1] "try-error"
    #> attr(,"condition")
    #> <Rcpp::exception: ??????>

    Encoding(tmp) = "UTF-8"
    tmp
    #> [1] "Error : ????\n"
    #> attr(,"class")
    #> [1] "try-error"
    #> attr(,"condition")
    #> <Rcpp::exception: ??????>

I see this related post before 
http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-August/006286.html 
. But it seems that we can not set encoding for the error string.

Hope to get any help on this. Thanks.

Best,
Qin Wenfeng.
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to