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

Method ExtendSetup

r/src/r_to_arrow.cpp:1158–1203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1156 }
1157
1158 Status ExtendSetup(SEXP x, int64_t size, int64_t offset) {
1159 // check that x is compatible
1160 R_xlen_t n_columns = XLENGTH(x);
1161
1162 if (!Rf_inherits(x, "data.frame") && !Rf_inherits(x, "POSIXlt")) {
1163 return Status::Invalid("Can only convert data frames to Struct type");
1164 }
1165
1166 auto fields = this->struct_type_->fields();
1167 if (n_columns != static_cast<R_xlen_t>(fields.size())) {
1168 return Status::RError("Number of fields in struct (", fields.size(),
1169 ") incompatible with number of columns in the data frame (",
1170 n_columns, ")");
1171 }
1172
1173 cpp11::strings x_names = Rf_getAttrib(x, R_NamesSymbol);
1174
1175 RETURN_NOT_OK(cpp11::unwind_protect([&] {
1176 for (int i = 0; i < n_columns; i++) {
1177 const char* name_i = arrow::r::unsafe::utf8_string(x_names[i]);
1178 auto field_name = fields[i]->name();
1179 if (field_name != name_i) {
1180 return Status::RError(
1181 "Field name in position ", i, " (", field_name,
1182 ") does not match the name of the column of the data frame (", name_i, ")");
1183 }
1184 }
1185
1186 return Status::OK();
1187 }));
1188
1189 for (R_xlen_t i = 0; i < n_columns; i++) {
1190 SEXP x_i = VECTOR_ELT(x, i);
1191 if (arrow::r::vec_size(x_i) < size) {
1192 return Status::RError("Degenerated data frame");
1193 }
1194 }
1195
1196 RETURN_NOT_OK(this->Reserve(size - offset));
1197
1198 for (R_xlen_t i = 0; i < size; i++) {
1199 RETURN_NOT_OK(struct_builder_->Append());
1200 }
1201
1202 return Status::OK();
1203 }
1204};
1205
1206template <>

Callers

nothing calls this directly

Calls 10

RErrorFunction · 0.85
utf8_stringFunction · 0.85
vec_sizeFunction · 0.85
InvalidClass · 0.50
OKFunction · 0.50
fieldsMethod · 0.45
sizeMethod · 0.45
nameMethod · 0.45
ReserveMethod · 0.45
AppendMethod · 0.45

Tested by

no test coverage detected