Skip to content

Commit

Permalink
Get rid of globalVariables() call
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Nov 2, 2018
1 parent 6123e0e commit 18301ed
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
5 changes: 2 additions & 3 deletions R/group_data.R
Expand Up @@ -33,17 +33,16 @@ group_data <- function(.data) {
#' @export
group_data.data.frame <- function(.data) {
rows <- list(seq_len(nrow(.data)))
tibble(.rows := rows)
tibble(".rows" := rows)
}

#' @export
group_data.rowwise_df <- function(.data) {
rows <- as.list(seq_len(nrow(.data)))
tibble(.rows := rows)
tibble(".rows" := rows)
}

#' @export
group_data.grouped_df <- function(.data) {
group_data_grouped_df(.data)
}
utils::globalVariables(".rows")
2 changes: 1 addition & 1 deletion R/grouped-df.r
Expand Up @@ -43,7 +43,7 @@ grouped_df <- function(data, vars, drop) {
#' # 5 bootstrap samples
#' tbl <- new_grouped_df(
#' tibble(x = rnorm(10)),
#' groups = tibble(.rows := replicate(5, sample(1:10, replace = TRUE), simplify = FALSE))
#' groups = tibble(".rows" := replicate(5, sample(1:10, replace = TRUE), simplify = FALSE))
#' )
#' # mean of each bootstrap sample
#' summarise(tbl, x = mean(x))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-group-by.r
Expand Up @@ -110,7 +110,7 @@ test_that("group_by only applies the allow list to grouping variables", {

res <- group_by(df, x)
expect_equal(groups(res), list(sym("x")))
expect_identical(group_data(res), tibble(x := 1:5, .rows := as.list(1:5)))
expect_identical(group_data(res), tibble(x := 1:5, ".rows" := as.list(1:5)))
})

test_that("group_by fails when lists are used as grouping variables (#276)", {
Expand Down
14 changes: 7 additions & 7 deletions tests/testthat/test-group_data.R
Expand Up @@ -12,17 +12,17 @@ test_that("group_data returns a tidy tibble (#3489)", {

expect_identical(
group_data(df),
tibble(.rows := list(1:4))
tibble(".rows" := list(1:4))
)

expect_identical(
group_by(df,x) %>% group_data(),
tibble(x := c(1,2), .rows := list(1:2, 3:4))
tibble(x := c(1,2), ".rows" := list(1:2, 3:4))
)

expect_identical(
rowwise(df) %>% group_data(),
tibble(.rows := as.list(1:4))
tibble(".rows" := as.list(1:4))
)
})

Expand All @@ -32,9 +32,9 @@ test_that("group_rows and group_data work with 0 rows data frames (#3489)", {
expect_identical(group_rows(rowwise(df)), list())
expect_identical(group_rows(group_by(df, x)), list())

expect_identical(group_data(df), tibble(.rows := list(integer())))
expect_identical(group_data(rowwise(df)), tibble(.rows := list()))
expect_identical(group_data(group_by(df, x)), tibble(x := integer(), .rows := list()))
expect_identical(group_data(df), tibble(".rows" := list(integer())))
expect_identical(group_data(rowwise(df)), tibble(".rows" := list()))
expect_identical(group_data(group_by(df, x)), tibble(x := integer(), ".rows" := list()))
})

test_that("GroupDataFrame checks the structure of the groups attribute", {
Expand Down Expand Up @@ -69,7 +69,7 @@ test_that("GroupedDataFrame is compatible with older style grouped_df (#3604)",
vars = list(sym("x"))
)
g <- expect_warning(group_data(df))
expect_identical(g, tibble(x := 1, .rows := list(1L)))
expect_identical(g, tibble(x := 1, ".rows" := list(1L)))
expect_null(attr(df, "vars"))
})

4 changes: 2 additions & 2 deletions tests/testthat/test-new_grouped_df.R
Expand Up @@ -8,7 +8,7 @@ test_that("new grouped_df checks that `group_data` has a `.rows` column (#3837)"
test_that("new_grouped_df can create alternative grouping structures (#3837)", {
tbl <- new_grouped_df(
tibble(x = rnorm(10)),
groups = tibble(.rows := replicate(5, sample(1:10, replace = TRUE), simplify = FALSE))
groups = tibble(".rows" := replicate(5, sample(1:10, replace = TRUE), simplify = FALSE))
)
res <- summarise(tbl, x = mean(x))
expect_equal(nrow(res), 5L)
Expand All @@ -17,7 +17,7 @@ test_that("new_grouped_df can create alternative grouping structures (#3837)", {
test_that("validate_grouped_df (#3837)", {
df <- new_grouped_df(
tibble(x = 1:10),
groups = tibble(.rows := list(1:5, -1L))
groups = tibble(".rows" := list(1:5, -1L))
)
expect_error(validate_grouped_df(df), "indices of group 2 are out of bounds")

Expand Down

0 comments on commit 18301ed

Please sign in to comment.