Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine character and factor show warning. Closes #2317 #2478

Merged
merged 1 commit into from Feb 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Expand Up @@ -347,6 +347,9 @@

* `combine()` accepts `NA` values (#2203, @zeehio)

* `combine()` and `bind_rows()` with character and factor types now always warn
about the coercion to character (#2317, @zeehio)

# dplyr 0.5.0

## Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion inst/include/dplyr/Collecter.h
Expand Up @@ -228,6 +228,7 @@ namespace dplyr {

void collect_factor(const SlicingIndex& index, IntegerVector source) {
CharacterVector levels = get_levels(source);
Rf_warning("binding character and factor vector, coercing into character vector");
for (int i=0; i<index.size(); i++) {
if (source[i] == NA_INTEGER) {
data[index[i]] = NA_STRING;
Expand Down Expand Up @@ -431,7 +432,6 @@ namespace dplyr {
// we however do not assume that they are in the same order
IntegerVector source(v);
CharacterVector levels = get_levels(source);

SEXP* levels_ptr = Rcpp::internal::r_vector_start<STRSXP>(levels);
int* source_ptr = Rcpp::internal::r_vector_start<INTSXP>(source);
for (int i=0; i<index.size(); i++) {
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/helper-combine.R
Expand Up @@ -82,7 +82,8 @@ give_a_warning <- function(item1, item2,
}

# factor and character give a warning when combined (coercion to character)
if (class1 == "factor" && class2 == "character") {
if ((class1 == "factor" && class2 == "character") ||
(class1 == "character" && class2 == "factor")) {
return(TRUE)
}

Expand Down