0

Update: From @tospig reply, I'm expecting there to be a .set_encoding() method on cpp11::writables::strings, which is a missing feature at the moment. Therefore, now I ask for an equivalent method to set the encoding.

I'm trying to understand a bit of Rcpp vs cpp11 and I found a non-documented case when trying to set the encoding, which is compatible within the std library.

This works with Rcpp:

using namespace Rcpp;
...
Rcpp::Strings x_utf8 = x;
x_utf8.set_encoding(CE_UTF8);

This doesn't work with cpp11:

using namespace cpp11;
...
cpp11::writables::strings x_utf8 = x;
x_utf8.set_encoding(CE_UTF8);

The corresponding error is error: ‘cpp11::writable::strings’ {aka ‘class cpp11::writable::r_vector<cpp11::r_string>’} has no member named ‘set_encoding’

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
pachadotdev
  • 3,345
  • 6
  • 33
  • 60

1 Answers1

1

There is no such method as cpp11 uses UTF8 everywhere. From the vignette:

... whenever text data is converted from R data structures to C++ data structures by cpp11 the data is translated into UTF-8. Conversely any text data coming from C++ code is assumed to be UTF-8 and marked as such for R.

stephematician
  • 844
  • 6
  • 17