Skip to content

Commit

Permalink
return NULL even in case of partial matching
Browse files Browse the repository at this point in the history
- `$` doesn't attempt partial matching (#109).
  • Loading branch information
Kirill Müller committed Jun 30, 2016
1 parent 0ab6c61 commit 226ab7c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions R/tbl-df.r
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ print.tbl_df <- function(x, ..., n = NULL, width = NULL) {
`$.tbl_df` <- function(x, i) {
if (is.character(i) && !has_name(x, i)) {
warningc("Unknown column '", i, "'")
.subset2(x, i, exact = FALSE)
} else {
.subset2(x, i)
}
.subset2(x, i)
}

#' @export
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-tbl-df.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ test_that("can use two-dimensional indexing with [[", {

# $ -----------------------------------------------------------------------

test_that("$ throws error if name doesn't exist", {
test_that("$ throws warning if name doesn't exist", {
df <- data_frame(x = 1)
expect_warning(expect_null(df$y),
"Unknown column 'y'")
})

test_that("$ doesn't do partial matching", {
df <- data_frame(partial = 1)
expect_warning(expect_identical(df$p, 1),
expect_warning(expect_null(df$p),
"Unknown column 'p'")
expect_warning(expect_identical(df$part, 1),
expect_warning(expect_null(df$part),
"Unknown column 'part'")
expect_error(df$partial, NA)
})
Expand Down

0 comments on commit 226ab7c

Please sign in to comment.