MCPcopy Create free account
hub / github.com/apache/arrow / csv___ConvertOptions__initialize

Function csv___ConvertOptions__initialize

r/src/csv.cpp:115–187  ·  view source on GitHub ↗

[[arrow::export]]

Source from the content-addressed store, hash-verified

113
114// [[arrow::export]]
115std::shared_ptr<arrow::csv::ConvertOptions> csv___ConvertOptions__initialize(
116 cpp11::list options) {
117 auto res = std::make_shared<arrow::csv::ConvertOptions>(
118 arrow::csv::ConvertOptions::Defaults());
119 res->check_utf8 = cpp11::as_cpp<bool>(options["check_utf8"]);
120 // Recognized spellings for null values
121 res->null_values = cpp11::as_cpp<std::vector<std::string>>(options["null_values"]);
122 // Whether string / binary columns can have null values.
123 // If true, then strings in "null_values" are considered null for string columns.
124 // If false, then all strings are valid string values.
125 res->strings_can_be_null = cpp11::as_cpp<bool>(options["strings_can_be_null"]);
126
127 res->true_values = cpp11::as_cpp<std::vector<std::string>>(options["true_values"]);
128 res->false_values = cpp11::as_cpp<std::vector<std::string>>(options["false_values"]);
129
130 SEXP col_types = options["col_types"];
131 if (Rf_inherits(col_types, "Schema")) {
132 auto schema = cpp11::as_cpp<std::shared_ptr<arrow::Schema>>(col_types);
133 std::unordered_map<std::string, std::shared_ptr<arrow::DataType>> column_types;
134 for (const auto& field : schema->fields()) {
135 column_types.insert(std::make_pair(field->name(), field->type()));
136 }
137 res->column_types = column_types;
138 }
139
140 res->auto_dict_encode = cpp11::as_cpp<bool>(options["auto_dict_encode"]);
141 res->auto_dict_max_cardinality =
142 cpp11::as_cpp<int>(options["auto_dict_max_cardinality"]);
143 res->include_columns =
144 cpp11::as_cpp<std::vector<std::string>>(options["include_columns"]);
145 res->include_missing_columns = cpp11::as_cpp<bool>(options["include_missing_columns"]);
146
147 SEXP op_timestamp_parsers = options["timestamp_parsers"];
148 if (!Rf_isNull(op_timestamp_parsers)) {
149 std::vector<std::shared_ptr<arrow::TimestampParser>> timestamp_parsers;
150
151 // if we have a character vector, convert to arrow::StrptimeTimestampParser
152 if (TYPEOF(op_timestamp_parsers) == STRSXP) {
153 cpp11::strings s_timestamp_parsers(op_timestamp_parsers);
154 for (cpp11::r_string s : s_timestamp_parsers) {
155 timestamp_parsers.push_back(arrow::TimestampParser::MakeStrptime(s));
156 }
157
158 } else if (TYPEOF(op_timestamp_parsers) == VECSXP) {
159 cpp11::list lst_parsers(op_timestamp_parsers);
160
161 for (SEXP x : lst_parsers) {
162 // handle scalar string and TimestampParser instances
163 if (TYPEOF(x) == STRSXP && XLENGTH(x) == 1) {
164 timestamp_parsers.push_back(
165 arrow::TimestampParser::MakeStrptime(CHAR(STRING_ELT(x, 0))));
166 } else if (Rf_inherits(x, "TimestampParser")) {
167 timestamp_parsers.push_back(
168 cpp11::as_cpp<std::shared_ptr<arrow::TimestampParser>>(x));
169 } else {
170 cpp11::stop(
171 "unsupported timestamp parser, must be a scalar string or a "
172 "<TimestampParser> object");

Calls 7

stopFunction · 0.85
push_backMethod · 0.80
DefaultsFunction · 0.50
fieldsMethod · 0.45
insertMethod · 0.45
nameMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected