Skip to content

Commit

Permalink
add support for collector-level na args to the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
khusmann committed Jul 17, 2024
1 parent 4a92232 commit 4c0a3f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/collectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class collector {
type_(derive_type(cpp11::strings(data_.attr("class"))[0])),
altrep_(altrep) {}
column_type type() const { return type_; }
SEXP na() const { return data_["na"]; }
SEXP name() const { return name_; }
SEXP operator[](const char* nme) { return data_[nme]; }
bool use_altrep() {
Expand Down Expand Up @@ -170,6 +171,8 @@ inline collectors resolve_collectors(
std::string my_col_type = cpp11::strings(my_collector.attr("class"))[0];

if (my_col_type == "collector_guess") {
auto my_col_na = my_collector["na"];
auto my_col_na_res = Rf_isNull(my_col_na) ? na : my_col_na;
cpp11::writable::strings col_vals(guess_num);
for (R_xlen_t j = 0; j < guess_num - 1; ++j) {
size_t row = j * guess_step;
Expand All @@ -187,10 +190,10 @@ inline collectors resolve_collectors(
locale_info->encoder_.makeSEXP(str.begin(), str.end(), true);
}

auto type = guess_type__(col_vals, na, locale_info.get(), false);
auto type = guess_type__(col_vals, my_col_na_res, locale_info.get(), false);
auto fun_name = std::string("col_") + type;
auto col_type = vroom[fun_name.c_str()];
my_collectors[col] = col_type();
my_collectors[col] = col_type("na"_nm = my_col_na);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/columns.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,14 @@ inline cpp11::list create_columns(
continue;
}

auto col_na = collector.na();
auto col_na_res = Rf_isNull(col_na) ? na : cpp11::strings(col_na);

// This is deleted in the finalizers when the vectors are GC'd by R
auto info = new vroom_vec_info{
idx->get_column(col),
num_threads,
std::make_shared<cpp11::strings>(na),
std::make_shared<cpp11::strings>(col_na_res),
locale_info,
*errors,
std::string()};
Expand Down

0 comments on commit 4c0a3f1

Please sign in to comment.