| 566 | } |
| 567 | |
| 568 | XGB_DLL SEXP XGDMatrixSetStrFeatureInfo_R(SEXP handle, SEXP field, SEXP array) { |
| 569 | R_API_BEGIN(); |
| 570 | size_t len{0}; |
| 571 | if (!Rf_isNull(array)) { |
| 572 | len = Rf_xlength(array); |
| 573 | } |
| 574 | |
| 575 | SEXP str_info_holder = Rf_protect(Rf_allocVector(VECSXP, len)); |
| 576 | if (TYPEOF(array) == STRSXP) { |
| 577 | for (size_t i = 0; i < len; ++i) { |
| 578 | SET_VECTOR_ELT(str_info_holder, i, STRING_ELT(array, i)); |
| 579 | } |
| 580 | } else { |
| 581 | for (size_t i = 0; i < len; ++i) { |
| 582 | SET_VECTOR_ELT(str_info_holder, i, Rf_asChar(VECTOR_ELT(array, i))); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | SEXP field_ = Rf_protect(Rf_asChar(field)); |
| 587 | const char *name = CHAR(field_); |
| 588 | int res_code; |
| 589 | { |
| 590 | std::vector<std::string> str_info; |
| 591 | str_info.reserve(len); |
| 592 | for (size_t i = 0; i < len; ++i) { |
| 593 | str_info.emplace_back(CHAR(VECTOR_ELT(str_info_holder, i))); |
| 594 | } |
| 595 | std::vector<char const*> vec(len); |
| 596 | std::transform(str_info.cbegin(), str_info.cend(), vec.begin(), |
| 597 | [](std::string const &str) { return str.c_str(); }); |
| 598 | res_code = XGDMatrixSetStrFeatureInfo(R_ExternalPtrAddr(handle), name, vec.data(), len); |
| 599 | } |
| 600 | CHECK_CALL(res_code); |
| 601 | Rf_unprotect(2); |
| 602 | R_API_END(); |
| 603 | return R_NilValue; |
| 604 | } |
| 605 | |
| 606 | XGB_DLL SEXP XGDMatrixGetStrFeatureInfo_R(SEXP handle, SEXP field) { |
| 607 | SEXP ret; |