| 760 | } |
| 761 | |
| 762 | SEXP GetLevels() const { |
| 763 | // R factor levels must be type "character" so coerce `dict` to STRSXP |
| 764 | // TODO (npr): this coercion should be optional, "dictionariesAsFactors" ;) |
| 765 | // Alternative: preserve the logical type of the dictionary values |
| 766 | // (e.g. if dict is timestamp, return a POSIXt R vector, not factor) |
| 767 | if (dictionary_->type_id() != Type::STRING && |
| 768 | dictionary_->type_id() != Type::LARGE_STRING) { |
| 769 | cpp11::safe[Rf_warning]("Coercing dictionary values to R character factor levels"); |
| 770 | } |
| 771 | |
| 772 | SEXP vec = PROTECT(Converter::Convert(dictionary_)); |
| 773 | SEXP strings_vec = PROTECT(Rf_coerceVector(vec, STRSXP)); |
| 774 | UNPROTECT(2); |
| 775 | return strings_vec; |
| 776 | } |
| 777 | }; |
| 778 | |
| 779 | class Converter_Struct : public Converter { |