| 153 | namespace r { |
| 154 | |
| 155 | arrow::Status InferSchemaFromDots(SEXP lst, SEXP schema_sxp, int num_fields, |
| 156 | std::shared_ptr<arrow::Schema>& schema) { |
| 157 | // maybe a schema was given |
| 158 | if (Rf_inherits(schema_sxp, "Schema")) { |
| 159 | schema = cpp11::as_cpp<std::shared_ptr<arrow::Schema>>(schema_sxp); |
| 160 | return arrow::Status::OK(); |
| 161 | } |
| 162 | |
| 163 | if (!Rf_isNull(schema_sxp)) { |
| 164 | return arrow::Status::RError("`schema` must be an arrow::Schema or NULL"); |
| 165 | } |
| 166 | |
| 167 | // infer the schema from the `...` |
| 168 | std::vector<std::shared_ptr<arrow::Field>> fields(num_fields); |
| 169 | |
| 170 | auto extract_one_field = [&fields](int j, SEXP x, std::string name) { |
| 171 | if (Rf_inherits(x, "ChunkedArray")) { |
| 172 | fields[j] = arrow::field( |
| 173 | name, cpp11::as_cpp<std::shared_ptr<arrow::ChunkedArray>>(x)->type()); |
| 174 | } else if (Rf_inherits(x, "Array")) { |
| 175 | fields[j] = |
| 176 | arrow::field(name, cpp11::as_cpp<std::shared_ptr<arrow::Array>>(x)->type()); |
| 177 | } else { |
| 178 | // TODO: we just need the type at this point |
| 179 | fields[j] = arrow::field(name, arrow::r::InferArrowType(x)); |
| 180 | } |
| 181 | }; |
| 182 | arrow::r::TraverseDots(lst, num_fields, extract_one_field); |
| 183 | |
| 184 | schema = std::make_shared<arrow::Schema>(std::move(fields)); |
| 185 | |
| 186 | return arrow::Status::OK(); |
| 187 | } |
| 188 | |
| 189 | SEXP arrow_attributes(SEXP x, bool only_top_level) { |
| 190 | SEXP call = PROTECT( |
no test coverage detected