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

Support for raw vectors #2952

Merged
merged 18 commits into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
handle raw in grouped and rowwise mutate #1803
  • Loading branch information
Romain Francois committed Dec 13, 2017
commit b710fa51ec8238aaccf28b143a42983114908558
2 changes: 2 additions & 0 deletions inst/include/dplyr/Collecter.h
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ inline Collecter* collecter(SEXP model, int n) {
stop("Columns of class data.frame not supported");
}
return new Collecter_Impl<VECSXP>(n);
case RAWSXP:
return new Collecter_Impl<RAWSXP>(n);
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions inst/include/dplyr/Gatherer.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ inline Gatherer* constant_gatherer(SEXP x, int n, const SymbolString& name) {
return new ConstantGathererImpl<CPLXSXP>(x, n);
case VECSXP:
return new ConstantGathererImpl<VECSXP>(x, n);
case RAWSXP:
return new ConstantGathererImpl<RAWSXP>(x, n);
default:
break;
}
Expand Down
4 changes: 4 additions & 0 deletions inst/include/dplyr/Result/GroupedSubset.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ inline GroupedSubset* grouped_subset(SEXP x, int max_size) {
return new GroupedSubsetTemplate<VECSXP>(x, max_size);
case CPLXSXP:
return new GroupedSubsetTemplate<CPLXSXP>(x, max_size);
case RAWSXP:
return new GroupedSubsetTemplate<RAWSXP>(x, max_size);
default:
break;
}
Expand Down Expand Up @@ -126,6 +128,8 @@ inline GroupedSubset* summarised_subset(SummarisedVariable x) {
return new SummarisedSubsetTemplate<VECSXP>(x);
case CPLXSXP:
return new SummarisedSubsetTemplate<CPLXSXP>(x);
case RAWSXP:
return new SummarisedSubsetTemplate<RAWSXP>(x);
default:
break;
}
Expand Down
2 changes: 0 additions & 2 deletions src/mutate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,10 @@ DataFrame mutate_grouped(const DataFrame& df, const QuosureList& dots) {
} else {
variable = validate_unquoted_value(call, gdf.nrows(), name);
}

Rf_setAttrib(variable, R_NamesSymbol, R_NilValue);
proxy.input(name, variable);
accumulator.set(name, variable);
}

return structure_mutate(accumulator, df, get_class(df));
}

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-mutate.r
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ test_that("mutate handles raw vectors in columns (#1803)", {
expect_identical( mutate(df, b = 1), data_frame(a = 1:3, b = 1) )
expect_identical( mutate(df, c = 1), data_frame(a = 1:3, b = as.raw(1:3), c = 1) )
expect_identical( mutate(df, c = as.raw(a)), data_frame(a = 1:3, b = as.raw(1:3), c = as.raw(1:3)) )

df <- data_frame(a = 1:4, g = c(1,1,2,2))
expect_identical( mutate(df, b = as.raw(a)) %>% group_by(g) %>% pull(b), as.raw(1:4) )
expect_identical( mutate(df, b = as.raw(a)) %>% rowwise() %>% pull(b), as.raw(1:4) )
})

test_that("grouped mutate errors on incompatible column type (#1641)", {
Expand Down