Skip to content

Commit

Permalink
avoid mutate() since it has not exactly dplyr::mutate() schemantics (…
Browse files Browse the repository at this point in the history
…nse, !!, etc.) and it's not intended to be used in source code anyways
  • Loading branch information
lorenzwalthert committed Jun 12, 2023
1 parent b6cbe96 commit 196a032
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
9 changes: 0 additions & 9 deletions R/compat-dplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,3 @@ map_dfr <- function(.x, .f, ...) {
res <- map(.x, .f, ...)
vec_rbind(!!!res)
}

mutate <- function(.data, ...) {
collected <- list(...)
for (idx in seq_along(collected)) {
.data[names(collected)[idx]] <- unname(collected[[idx]])
}

.data
}
16 changes: 8 additions & 8 deletions tests/testthat/test-cache-low-level-api.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
test_that("caching utils make right blocks with semi-colon", {
blocks_simple_uncached <- compute_parse_data_nested(c("1 + 1", "2; 1+1")) %>%
mutate(is_cached = FALSE) %>%
base::transform(is_cached = FALSE) %>%
cache_find_block()
expect_equal(blocks_simple_uncached, c(1, 1, 1, 1))

blocks_simple_cached <- compute_parse_data_nested(c("1 + 1", "2; 1+1")) %>%
mutate(is_cached = TRUE) %>%
base::transform(is_cached = TRUE) %>%
cache_find_block()
expect_equal(blocks_simple_cached, c(1, 1, 1, 1))

blocks_edge <- compute_parse_data_nested(c("1 + 1", "2; 1+1")) %>%
mutate(is_cached = c(TRUE, TRUE, FALSE, FALSE)) %>%
base::transform(is_cached = c(TRUE, TRUE, FALSE, FALSE)) %>%
cache_find_block()
expect_equal(blocks_edge, c(1, 2, 2, 2))
})
Expand All @@ -30,7 +30,7 @@ test_that("caching utils make right blocks with comments", {


blocks_simple_uncached <- compute_parse_data_nested(text) %>%
mutate(is_cached = c(
base::transform(is_cached = c(
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE,
TRUE, FALSE, FALSE, FALSE
)) %>%
Expand All @@ -48,7 +48,7 @@ test_that("caching utils make right blocks with comments", {
tau1 = 1 # here?
"
blocks_simple_cached <- compute_parse_data_nested(text) %>%
mutate(is_cached = c(
base::transform(is_cached = c(
FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE
)) %>%
cache_find_block()
Expand Down Expand Up @@ -101,17 +101,17 @@ test_that("blank lines are correctly identified", {

test_that("caching utils make right blocks with comments", {
blocks_simple_uncached <- compute_parse_data_nested(c("1 + 1", "2 # comment")) %>%
mutate(is_cached = FALSE) %>%
base::transform(is_cached = FALSE) %>%
cache_find_block()
expect_equal(blocks_simple_uncached, c(1, 1, 1))

blocks_simple_cached <- compute_parse_data_nested(c("1 + 1", "2 # comment2")) %>%
mutate(is_cached = TRUE) %>%
base::transform(is_cached = TRUE) %>%
cache_find_block()
expect_equal(blocks_simple_cached, c(1, 1, 1))

blocks_edge <- compute_parse_data_nested(c("1 + 1", "2 # 1+1")) %>%
mutate(is_cached = c(TRUE, TRUE, FALSE)) %>%
base::transform(is_cached = c(TRUE, TRUE, FALSE)) %>%
cache_find_block()
expect_equal(blocks_edge, c(1, 2, 2))
})
Expand Down

0 comments on commit 196a032

Please sign in to comment.