#ifndef dplyr_collapse_H #define dplyr_collapse_H namespace dplyr { template const char* to_string_utf8(typename Rcpp::traits::storage_type::type from) { SEXP s = Rcpp::internal::r_coerce(from); return Rf_translateCharUTF8(s); } template std::string collapse_utf8(const Vector& x, const char* sep = ", ", const char* quote = "") { std::stringstream ss; int n = x.size(); if (n > 0) { ss << quote << to_string_utf8(x[0]) << quote; for (int i = 1; i < n; i++) { const char* st = to_string_utf8(x[i]); ss << sep << quote << st << quote; } } return ss.str(); } } #endif