Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dgrtwo/tidyr into dgrtwo-…
Browse files Browse the repository at this point in the history
…master
  • Loading branch information
hadley committed May 18, 2016
2 parents bae80df + 594d3bf commit ca3dd9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/simplifyPieces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ List simplifyPieces(ListOf<CharacterVector> pieces, int p,
} else if (x.size() < p) { // too small
tooSml.push_back(i + 1);

int gap = p - x.size();
for (int j = 0; j < p; ++j) {
int idx = fillLeft ? p - j - 1 : j;
out[idx][i] = (j < x.size()) ? x[j] : NA_STRING;
if (fillLeft) {
out[j][i] = (j >= gap) ? x[j - gap] : NA_STRING;
} else {
out[j][i] = (j < x.size()) ? x[j] : NA_STRING;
}
}

} else {
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-separate.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ test_that("too few pieces dealt with as requested", {

left <- separate(df, x, c("x", "y", "z"), fill = "left")
expect_equal(left$x, c(NA, "a"))
expect_equal(left$y, c("a", "b"))
expect_equal(left$z, c("b", "c"))

right <- separate(df, x, c("x", "y", "z"), fill = "right")
expect_equal(right$z, c(NA, "c"))
Expand Down

0 comments on commit ca3dd9e

Please sign in to comment.