@@ -876,15 +876,23 @@ inline r_vector<T>::r_vector(std::initializer_list<named_arg> il)
876876 // SAFETY: We've validated type and length ahead of this.
877877 const underlying_type elt = get_elt (value, 0 );
878878
879- // TODO: The equivalent ctor from `initializer_list<r_string>` has a specialization
880- // for `<r_string>` to translate `elt` to UTF-8 before assigning. Should we have
881- // that here too? `named_arg` doesn't do any checking here.
882- if (data_p_ != nullptr ) {
883- data_p_[i] = elt;
879+ if constexpr (std::is_same<T, cpp11::r_string>::value) {
880+ // Translate to UTF-8 before assigning for string types
881+ SEXP translated_elt = Rf_mkCharCE (Rf_translateCharUTF8 (elt), CE_UTF8);
882+
883+ if (data_p_ != nullptr ) {
884+ data_p_[i] = translated_elt;
885+ } else {
886+ // Handles STRSXP case. VECSXP case has its own specialization.
887+ // We don't expect any ALTREP cases since we just freshly allocated `data_`.
888+ set_elt (data_, i, translated_elt);
889+ }
884890 } else {
885- // Handles STRSXP case. VECSXP case has its own specialization.
886- // We don't expect any ALTREP cases since we just freshly allocated `data_`.
887- set_elt (data_, i, elt);
891+ if (data_p_ != nullptr ) {
892+ data_p_[i] = elt;
893+ } else {
894+ set_elt (data_, i, elt);
895+ }
888896 }
889897
890898 SEXP name = Rf_mkCharCE (it->name (), CE_UTF8);
0 commit comments