From c4bf67e536436bf69b8903f3eb471d31056faeb7 Mon Sep 17 00:00:00 2001 From: dcooley Date: Wed, 2 Mar 2022 12:21:37 +1100 Subject: [PATCH 1/5] testing Rcpp::String() --- inst/include/geojsonsf/geojson/geojson_properties.hpp | 2 +- src/RcppExports.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/inst/include/geojsonsf/geojson/geojson_properties.hpp b/inst/include/geojsonsf/geojson/geojson_properties.hpp index 1e35bee..acbebcb 100644 --- a/inst/include/geojsonsf/geojson/geojson_properties.hpp +++ b/inst/include/geojsonsf/geojson/geojson_properties.hpp @@ -108,7 +108,7 @@ namespace geojson_properties { const R_xlen_t& row_index ) { Rcpp::StringVector sv = sf[key]; - sv[row_index] = value; + sv[row_index] = Rcpp::String( value ); sf[key] = sv; } diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index bf987d3..dd2b696 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -5,6 +5,11 @@ using namespace Rcpp; +#ifdef RCPP_USE_GLOBAL_ROSTREAM +Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); +Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); +#endif + // rcpp_df_to_geojson_atomise Rcpp::StringVector rcpp_df_to_geojson_atomise(Rcpp::DataFrame& df, Rcpp::StringVector& geometry_columns, int& digits, bool& factors_as_string); RcppExport SEXP _geojsonsf_rcpp_df_to_geojson_atomise(SEXP dfSEXP, SEXP geometry_columnsSEXP, SEXP digitsSEXP, SEXP factors_as_stringSEXP) { From 7df062ad4175baa88f282308dfbf74c5a86d17bf Mon Sep 17 00:00:00 2001 From: dcooley Date: Wed, 2 Mar 2022 18:35:02 +1100 Subject: [PATCH 2/5] names #issue90 --- inst/include/geojsonsf/geojson/geojson_properties.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inst/include/geojsonsf/geojson/geojson_properties.hpp b/inst/include/geojsonsf/geojson/geojson_properties.hpp index acbebcb..020f6a0 100644 --- a/inst/include/geojsonsf/geojson/geojson_properties.hpp +++ b/inst/include/geojsonsf/geojson/geojson_properties.hpp @@ -78,7 +78,8 @@ namespace geojson_properties { R_xlen_t i; for( i = 0; i < n.size(); ++i ) { - sv[i] = n[i]; + Rcpp::String s = n[i]; + sv[i] = s; } properties.names() = sv; From e9dfeacae2822b45f1b2f628c8e40ea270d97faa Mon Sep 17 00:00:00 2001 From: dcooley Date: Wed, 2 Mar 2022 19:35:31 +1100 Subject: [PATCH 3/5] how about this #90 --- inst/include/geojsonsf/geojson/geojson_properties.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/inst/include/geojsonsf/geojson/geojson_properties.hpp b/inst/include/geojsonsf/geojson/geojson_properties.hpp index 020f6a0..d4ba657 100644 --- a/inst/include/geojsonsf/geojson/geojson_properties.hpp +++ b/inst/include/geojsonsf/geojson/geojson_properties.hpp @@ -78,11 +78,10 @@ namespace geojson_properties { R_xlen_t i; for( i = 0; i < n.size(); ++i ) { - Rcpp::String s = n[i]; - sv[i] = s; + std::string s = n[i]; + sv[i] = Rcpp::String( s ); } properties.names() = sv; - } inline void get_property_keys( From a43d0bbd435387ac01062ee11ae27ad828444cfd Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Wed, 2 Mar 2022 15:53:27 -0700 Subject: [PATCH 4/5] add a test for #90 --- inst/tinytest/test-geojson_sf.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inst/tinytest/test-geojson_sf.R b/inst/tinytest/test-geojson_sf.R index 8655331..7e8440f 100644 --- a/inst/tinytest/test-geojson_sf.R +++ b/inst/tinytest/test-geojson_sf.R @@ -71,3 +71,9 @@ expect_true( is.logical( sf$b ) ) expect_true( is.character( sf$c ) ) + ## Issue 90 + ## UTF8-encoded strings + geojson <- enc2utf8('{"type":"Feature","geometry":{"type":"Point","coordinates":[7.624747,51.954044]},"properties":{"örtchen":"Münster"}}') + out <- geojson_sf( geojson ) + expect_equal(out[1][[1]], "Münster") + expect_equal(names(out)[1], "örtchen") From 52ef035f1841005ad3895f0a0342f81401c4f80b Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Wed, 2 Mar 2022 16:15:39 -0700 Subject: [PATCH 5/5] Initialize names as Rcpp StringVector; #90 --- inst/include/geojsonsf/geojson/geojson_properties.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/include/geojsonsf/geojson/geojson_properties.hpp b/inst/include/geojsonsf/geojson/geojson_properties.hpp index d4ba657..3b4bda1 100644 --- a/inst/include/geojsonsf/geojson/geojson_properties.hpp +++ b/inst/include/geojsonsf/geojson/geojson_properties.hpp @@ -74,7 +74,7 @@ namespace geojson_properties { properties.names() = property_keys; std::vector< std::string > n = properties.names(); std::reverse( n.begin(), n.end() ); - std::vector< std::string > sv( n.size() ); + Rcpp::StringVector sv( n.size() ); R_xlen_t i; for( i = 0; i < n.size(); ++i ) {