Skip to content

Commit

Permalink
combine works with NA and character (Closes tidyverse#2203)
Browse files Browse the repository at this point in the history
This commit fixes tidyverse#2203 by adding compatibility to the character Collecter  so it accepts logical missing values and replaces them with NA_character_ as expected.
  • Loading branch information
zeehio authored Oct 27, 2016
1 parent 196deff commit 4f17288
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion inst/include/dplyr/Collecter.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ namespace dplyr {
collect_strings(index, v);
} else if (Rf_inherits(v, "factor")) {
collect_factor(index, v);
} else if (TYPEOF(v) == LGLSXP && all_na(v)) {
collect_logicalNA(index, v);
} else {
CharacterVector vec(v);
collect_strings(index, vec);
Expand All @@ -120,7 +122,7 @@ namespace dplyr {
}

inline bool compatible(SEXP x) {
return (STRSXP == TYPEOF(x)) || Rf_inherits(x, "factor");
return (STRSXP == TYPEOF(x)) || Rf_inherits(x, "factor") || (LGLSXP == TYPEOF(x) && all_na(x));
}

bool can_promote(SEXP x) const {
Expand All @@ -136,6 +138,14 @@ namespace dplyr {

private:

void collect_logicalNA(const SlicingIndex& index, LogicalVector source) {
SEXP* p_data = Rcpp::internal::r_vector_start<STRSXP>(data);
int n = index.size();
for (int i=0; i<n; i++) {
p_data[index[i]] = NA_STRING;
}
}

void collect_strings(const SlicingIndex& index, CharacterVector source) {
SEXP* p_source = Rcpp::internal::r_vector_start<STRSXP>(source);
SEXP* p_data = Rcpp::internal::r_vector_start<STRSXP>(data);
Expand Down

0 comments on commit 4f17288

Please sign in to comment.