Skip to content

Commit 2efade7

Browse files
committed
more explicit and more correct cleaning up of env var
1 parent 3b71868 commit 2efade7

1 file changed

Lines changed: 34 additions & 24 deletions

File tree

r/tests/testthat/test-compute.R

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ test_that("register_scalar_function() adds a compute function to the registry",
106106
Scalar$create(32L, float64())
107107
)
108108

109-
withr::with_envvar(list(R_ARROW_COLLECT_WITH_UDF = "true"), {
110-
expect_identical(
111-
record_batch(a = 1L) %>%
112-
dplyr::mutate(b = times_32(a)) %>%
113-
dplyr::collect(),
114-
tibble::tibble(a = 1L, b = 32.0)
115-
)
116-
})
109+
expect_identical(
110+
record_batch(a = 1L) %>%
111+
dplyr::mutate(b = times_32(a)) %>%
112+
dplyr::collect(),
113+
tibble::tibble(a = 1L, b = 32.0)
114+
)
115+
116+
Sys.unsetenv("R_ARROW_COLLECT_WITH_UDF")
117117
})
118118

119119
test_that("arrow_scalar_function() with bad return type errors", {
@@ -148,6 +148,9 @@ test_that("arrow_scalar_function() with bad return type errors", {
148148
call_function("times_32_bad_return_type_scalar", Array$create(1L)),
149149
"Expected return Array or Scalar with type 'double'"
150150
)
151+
152+
# TODO(ARROW-17178) remove the need for this!
153+
Sys.unsetenv("R_ARROW_COLLECT_WITH_UDF")
151154
})
152155

153156
test_that("register_user_defined_function() can register multiple kernels", {
@@ -208,6 +211,9 @@ test_that("register_user_defined_function() errors for unsupported specification
208211
),
209212
"Kernels for user-defined function must accept the same number of arguments"
210213
)
214+
215+
# TODO(ARROW-17178) remove the need for this!
216+
Sys.unsetenv("R_ARROW_COLLECT_WITH_UDF")
211217
})
212218

213219
test_that("user-defined functions work during multi-threaded execution", {
@@ -245,26 +251,27 @@ test_that("user-defined functions work during multi-threaded execution", {
245251
)
246252
on.exit(unregister_binding("times_32", update_cache = TRUE))
247253

248-
withr::with_envvar(list(R_ARROW_COLLECT_WITH_UDF = "true"), {
249-
# check a regular collect()
250-
result <- open_dataset(tf_dataset) %>%
251-
dplyr::mutate(fun_result = times_32(value)) %>%
252-
dplyr::collect() %>%
253-
dplyr::arrange(row_num)
254+
# check a regular collect()
255+
result <- open_dataset(tf_dataset) %>%
256+
dplyr::mutate(fun_result = times_32(value)) %>%
257+
dplyr::collect() %>%
258+
dplyr::arrange(row_num)
254259

255-
expect_identical(result$fun_result, example_df$value * 32)
260+
expect_identical(result$fun_result, example_df$value * 32)
256261

257-
# check a write_dataset()
258-
open_dataset(tf_dataset) %>%
259-
dplyr::mutate(fun_result = times_32(value)) %>%
260-
write_dataset(tf_dest)
262+
# check a write_dataset()
263+
open_dataset(tf_dataset) %>%
264+
dplyr::mutate(fun_result = times_32(value)) %>%
265+
write_dataset(tf_dest)
261266

262-
result2 <- dplyr::collect(open_dataset(tf_dest)) %>%
263-
dplyr::arrange(row_num) %>%
264-
dplyr::collect()
267+
result2 <- dplyr::collect(open_dataset(tf_dest)) %>%
268+
dplyr::arrange(row_num) %>%
269+
dplyr::collect()
265270

266-
expect_identical(result2$fun_result, example_df$value * 32)
267-
})
271+
expect_identical(result2$fun_result, example_df$value * 32)
272+
273+
# TODO(ARROW-17178) remove the need for this!
274+
Sys.unsetenv("R_ARROW_COLLECT_WITH_UDF")
268275
})
269276

270277
test_that("user-defined error when called from an unsupported context", {
@@ -314,4 +321,7 @@ test_that("user-defined error when called from an unsupported context", {
314321
"Call to R \\(.*?\\) from a non-R thread from an unsupported context"
315322
)
316323
}
324+
325+
# TODO(ARROW-17178) remove the need for this!
326+
Sys.unsetenv("R_ARROW_COLLECT_WITH_UDF")
317327
})

0 commit comments

Comments
 (0)