Skip to content

Commit

Permalink
- [[ as fast as $ again, performs all relevant checks inline inst…
Browse files Browse the repository at this point in the history
…ead of relying on `vctrs::vec_as_location2()` (#780).

Closes #780.
  • Loading branch information
krlmlr committed Jun 14, 2020
1 parent 06ba0de commit d10ac73
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions R/subsetting.R
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,25 @@ tbl_subset2 <- function(x, j, j_arg) {
env = foreign_caller_env())

return(as.matrix(x)[[j]])
} else if (has_length(j, 2) && is.numeric(j)) {
deprecate_soft("3.0.0", "tibble::`[[.tbl_df`(j = 'can\\'t be a vector of length 2')",
details = "Recursive subsetting is deprecated for tibbles.",
env = foreign_caller_env())

return(.subset2(x, j))
} else if (is.character(j)) {
# Side effect: check that j is a scalar and not NA, allow invalid column names
vectbl_as_col_location2(j, length(x) + 1L, c(names(x), j), j_arg = j_arg)

# Don't warn when accessing invalid column names
return(.subset2(x, j))
} else if (is.numeric(j)) {
if (length(j) == 1L) {
if (j < 1 || j > length(x) || (is.double(j) && j != trunc(j))) {
# Side effect: throw error for invalid j
vectbl_as_col_location2(j, length(x), j_arg = j_arg)
}
} else if (length(j) == 2L) {
deprecate_soft("3.0.0", "tibble::`[[.tbl_df`(j = 'can\\'t be a vector of length 2')",
details = "Recursive subsetting is deprecated for tibbles.",
env = foreign_caller_env())
} else {
# Side effect: throw error for invalid j
vectbl_as_col_location2(j, length(x), j_arg = j_arg)
}
} else if (is.logical(j) || length(j) != 1L || !is_bare_atomic(j) || is.na(j)) {
# Side effect: throw error for invalid j
vectbl_as_col_location2(j, length(x), names(x), j_arg = j_arg)
}

j <- vectbl_as_col_location2(j, length(x), names(x), j_arg = j_arg)
.subset2(x, j)
}

Expand Down

0 comments on commit d10ac73

Please # to comment.