-
Notifications
You must be signed in to change notification settings - Fork 0
/
99_custom_bindings.R
72 lines (52 loc) · 1.38 KB
/
99_custom_bindings.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
library(arrow)
library(testthat)
# Define Custom R Functions -----------------------------------------------
custom_scales_pct <- function(x, accuracy = 0.1) {
scales::label_percent(accuracy = accuracy)(x)
}
custom_str_replace_na <- function(x, y) {
stringr::str_replace_na(x, y)
}
# Perform Unit Tests ------------------------------------------------------
test_that("custom_scales_pct behaves identically in dplyr and Arrow", {
df <- tibble(x = c(0.1, 0.2, 0.75, 0.9))
compare_dplyr_binding(
.input |>
filter(custom_scales_pct(x, "b")) |>
collect(),
df
)
})
# Map R Function to C++ Kernel --------------------------------------------
arrow::register_binding(
fun_name = "arrow::custom_scales_pct",
fun = function(x, ...) {
Expression$create(
"custom_scales_pct",
x,
options = list(...)
)
})
test_that("startsWith behaves identically in dplyr and Arrow", {
df <- tibble(x = c("Foo", "bar", "baz", "qux"))
compare_dplyr_binding(
.input %>%
filter(startsWith(x, "b")) %>%
collect(),
df
)
})
reprex::reprex({
library(testthat)
library(dplyr)
library(arrow)
test_that("startsWith behaves identically in dplyr and Arrow", {
df <- tibble(x = c("Foo", "bar", "baz", "qux"))
compare_dplyr_binding(
.input %>%
filter(startsWith(x, "b")) %>%
collect(),
df
)
})
})