You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by br...@apache.org on 2025/10/06 20:07:34 UTC
(arrow) branch main updated: GH-47106: [R] Update R package to use R 4.1+ native forward pipe syntax (#47622)
This is an automated email from the ASF dual-hosted git repository.
brycemecum pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 48a2e889a4 GH-47106: [R] Update R package to use R 4.1+ native forward pipe syntax (#47622)
48a2e889a4 is described below
commit 48a2e889a4dcb776889964ef9f5c04db49729da6
Author: Nic Crane <th...@gmail.com>
AuthorDate: Mon Oct 6 21:07:26 2025 +0100
GH-47106: [R] Update R package to use R 4.1+ native forward pipe syntax (#47622)
### Rationale for this change
Don't need base pipe
### What changes are included in this PR?
Update package to use native pipe
### Are these changes tested?
Sure
### Are there any user-facing changes?
Nah
* GitHub Issue: #47106
Authored-by: Nic Crane <th...@gmail.com>
Signed-off-by: Bryce Mecum <pe...@gmail.com>
---
r/R/dataset-write.R | 8 +-
r/R/dplyr-funcs-augmented.R | 8 +-
r/R/dplyr-funcs-type.R | 4 +-
r/R/dplyr-summarize.R | 6 +-
r/R/dplyr.R | 8 +-
r/R/duckdb.R | 20 +-
r/R/type.R | 4 +-
r/R/udf.R | 6 +-
r/data-raw/codegen.R | 28 +-
r/data-raw/docgen.R | 16 +-
r/tests/testthat/_snaps/dataset-dplyr.md | 2 +-
r/tests/testthat/_snaps/dplyr-across.md | 2 +-
r/tests/testthat/_snaps/dplyr-funcs-datetime.md | 4 +-
r/tests/testthat/_snaps/dplyr-glimpse.md | 9 +-
r/tests/testthat/_snaps/dplyr-mutate.md | 4 +-
r/tests/testthat/_snaps/dplyr-summarize.md | 8 +-
r/tests/testthat/helper-filesystems.R | 22 +-
r/tests/testthat/test-RecordBatch.R | 32 +-
r/tests/testthat/test-Table.R | 10 +-
r/tests/testthat/test-compute-sort.R | 4 +-
r/tests/testthat/test-csv.R | 2 +-
r/tests/testthat/test-dataset-csv.R | 156 ++--
r/tests/testthat/test-dataset-dplyr.R | 184 ++--
r/tests/testthat/test-dataset-json.R | 16 +-
r/tests/testthat/test-dataset-uri.R | 40 +-
r/tests/testthat/test-dataset-write.R | 230 ++---
r/tests/testthat/test-dataset.R | 450 ++++-----
r/tests/testthat/test-dplyr-across.R | 8 +-
r/tests/testthat/test-dplyr-arrange.R | 154 ++--
r/tests/testthat/test-dplyr-collapse.R | 132 +--
r/tests/testthat/test-dplyr-count.R | 62 +-
r/tests/testthat/test-dplyr-distinct.R | 104 +--
r/tests/testthat/test-dplyr-filter.R | 274 +++---
r/tests/testthat/test-dplyr-funcs-conditional.R | 166 ++--
r/tests/testthat/test-dplyr-funcs-datetime.R | 1110 +++++++++++------------
r/tests/testthat/test-dplyr-funcs-math.R | 172 ++--
r/tests/testthat/test-dplyr-funcs-string.R | 660 +++++++-------
r/tests/testthat/test-dplyr-funcs-type.R | 262 +++---
r/tests/testthat/test-dplyr-glimpse.R | 28 +-
r/tests/testthat/test-dplyr-group-by.R | 226 ++---
r/tests/testthat/test-dplyr-join.R | 164 ++--
r/tests/testthat/test-dplyr-mutate.R | 376 ++++----
r/tests/testthat/test-dplyr-query.R | 450 ++++-----
r/tests/testthat/test-dplyr-select.R | 112 +--
r/tests/testthat/test-dplyr-slice.R | 74 +-
r/tests/testthat/test-dplyr-summarize.R | 656 +++++++-------
r/tests/testthat/test-dplyr-union.R | 24 +-
r/tests/testthat/test-duckdb.R | 120 +--
r/tests/testthat/test-extension.R | 10 +-
r/tests/testthat/test-metadata.R | 36 +-
r/tests/testthat/test-parquet.R | 2 +-
r/tests/testthat/test-python.R | 10 +-
r/tests/testthat/test-query-engine.R | 2 +-
r/tests/testthat/test-udf.R | 42 +-
r/vignettes/arrow.Rmd | 14 +-
r/vignettes/data_wrangling.Rmd | 64 +-
r/vignettes/dataset.Rmd | 70 +-
r/vignettes/flight.Rmd | 6 +-
58 files changed, 3440 insertions(+), 3433 deletions(-)
diff --git a/r/R/dataset-write.R b/r/R/dataset-write.R
index 288da4ffde..3d6daf65e0 100644
--- a/r/R/dataset-write.R
+++ b/r/R/dataset-write.R
@@ -105,8 +105,8 @@
#' # output directory will be different.
#' library(dplyr)
#' two_levels_tree_2 <- tempfile()
-#' mtcars %>%
-#' group_by(cyl, gear) %>%
+#' mtcars |>
+#' group_by(cyl, gear) |>
#' write_dataset(two_levels_tree_2)
#' list.files(two_levels_tree_2, recursive = TRUE)
#'
@@ -115,8 +115,8 @@
#'
#' # Write a structure X/Y/part-Z.parquet.
#' two_levels_tree_no_hive <- tempfile()
-#' mtcars %>%
-#' group_by(cyl, gear) %>%
+#' mtcars |>
+#' group_by(cyl, gear) |>
#' write_dataset(two_levels_tree_no_hive, hive_style = FALSE)
#' list.files(two_levels_tree_no_hive, recursive = TRUE)
#' @export
diff --git a/r/R/dplyr-funcs-augmented.R b/r/R/dplyr-funcs-augmented.R
index dca5ca16fa..97b924b5e1 100644
--- a/r/R/dplyr-funcs-augmented.R
+++ b/r/R/dplyr-funcs-augmented.R
@@ -28,16 +28,16 @@
#' augmented column.
#'
#' @examples \dontrun{
-#' open_dataset("nyc-taxi") %>% mutate(
+#' open_dataset("nyc-taxi") |> mutate(
#' file =
#' add_filename()
#' )
#'
#' # To use a verb like mutate() with add_filename() we need to first call
#' # compute()
-#' open_dataset("nyc-taxi") %>%
-#' mutate(file = add_filename()) %>%
-#' compute() %>%
+#' open_dataset("nyc-taxi") |>
+#' mutate(file = add_filename()) |>
+#' compute() |>
#' mutate(filename_length = nchar(file))
#' }
#'
diff --git a/r/R/dplyr-funcs-type.R b/r/R/dplyr-funcs-type.R
index 1b42e52baa..02f50b2836 100644
--- a/r/R/dplyr-funcs-type.R
+++ b/r/R/dplyr-funcs-type.R
@@ -38,8 +38,8 @@ register_bindings_type <- function() {
#'
#' @examples
#' \dontrun{
-#' mtcars %>%
-#' arrow_table() %>%
+#' mtcars |>
+#' arrow_table() |>
#' mutate(cyl = cast(cyl, string()))
#' }
#' @keywords internal
diff --git a/r/R/dplyr-summarize.R b/r/R/dplyr-summarize.R
index 0cd93f5960..2bfb5289f7 100644
--- a/r/R/dplyr-summarize.R
+++ b/r/R/dplyr-summarize.R
@@ -57,8 +57,8 @@ do_arrow_summarize <- function(.data, ..., .groups = NULL) {
# and aggregations, but that's not how Acero works. For example, for us to do
# summarize(mean = sum(x) / n())
# we basically have to translate it into
- # summarize(..temp0 = sum(x), ..temp1 = n()) %>%
- # mutate(mean = ..temp0 / ..temp1) %>%
+ # summarize(..temp0 = sum(x), ..temp1 = n()) |>
+ # mutate(mean = ..temp0 / ..temp1) |>
# select(-starts_with("..temp"))
# That is, "first aggregate, then transform the result further."
#
@@ -97,7 +97,7 @@ do_arrow_summarize <- function(.data, ..., .groups = NULL) {
# One last check: it's possible that an expression like y - mean(y) would
# successfully evaluate, but it's not supported. It gets transformed to:
# nolint start
- # summarize(..temp0 = mean(y)) %>%
+ # summarize(..temp0 = mean(y)) |>
# mutate(y - ..temp0)
# nolint end
# but y is not in the schema of the data after summarize(). To catch this
diff --git a/r/R/dplyr.R b/r/R/dplyr.R
index 93fcfdef28..d59b21caca 100644
--- a/r/R/dplyr.R
+++ b/r/R/dplyr.R
@@ -279,10 +279,10 @@ tail.arrow_dplyr_query <- function(x, n = 6L, ...) {
#'
#' @examplesIf arrow_with_dataset() && requireNamespace("dplyr", quietly = TRUE)
#' library(dplyr)
-#' mtcars %>%
-#' arrow_table() %>%
-#' filter(mpg > 20) %>%
-#' mutate(x = gear / carb) %>%
+#' mtcars |>
+#' arrow_table() |>
+#' filter(mpg > 20) |>
+#' mutate(x = gear / carb) |>
#' show_exec_plan()
show_exec_plan <- function(x) {
result <- as_record_batch_reader(as_adq(x))
diff --git a/r/R/duckdb.R b/r/R/duckdb.R
index 65c70243e7..4b79abc110 100644
--- a/r/R/duckdb.R
+++ b/r/R/duckdb.R
@@ -45,10 +45,10 @@
#'
#' ds <- InMemoryDataset$create(mtcars)
#'
-#' ds %>%
-#' filter(mpg < 30) %>%
-#' group_by(cyl) %>%
-#' to_duckdb() %>%
+#' ds |>
+#' filter(mpg < 30) |>
+#' group_by(cyl) |>
+#' to_duckdb() |>
#' slice_min(disp)
to_duckdb <- function(.data,
con = arrow_duck_connection(),
@@ -154,12 +154,12 @@ duckdb_disconnector <- function(con, tbl_name) {
#'
#' ds <- InMemoryDataset$create(mtcars)
#'
-#' ds %>%
-#' filter(mpg < 30) %>%
-#' to_duckdb() %>%
-#' group_by(cyl) %>%
-#' summarize(mean_mpg = mean(mpg, na.rm = TRUE)) %>%
-#' to_arrow() %>%
+#' ds |>
+#' filter(mpg < 30) |>
+#' to_duckdb() |>
+#' group_by(cyl) |>
+#' summarize(mean_mpg = mean(mpg, na.rm = TRUE)) |>
+#' to_arrow() |>
#' collect()
to_arrow <- function(.data) {
# If this is an Arrow object already, return quickly since we're already Arrow
diff --git a/r/R/type.R b/r/R/type.R
index 1552d1dfa5..145881f5d4 100644
--- a/r/R/type.R
+++ b/r/R/type.R
@@ -408,11 +408,11 @@ NestedType <- R6Class("NestedType", inherit = DataType)
#' # You can also use `cast()` in an Arrow dplyr query.
#' if (requireNamespace("dplyr", quietly = TRUE)) {
#' library(dplyr, warn.conflicts = FALSE)
-#' arrow_table(mtcars) %>%
+#' arrow_table(mtcars) |>
#' transmute(
#' col1 = cast(cyl, string()),
#' col2 = cast(cyl, int8())
-#' ) %>%
+#' ) |>
#' compute()
#' }
int8 <- function() Int8__initialize()
diff --git a/r/R/udf.R b/r/R/udf.R
index 0415fbac3c..42584f28fc 100644
--- a/r/R/udf.R
+++ b/r/R/udf.R
@@ -66,9 +66,9 @@
#' auto_convert = TRUE
#' )
#'
-#' as_arrow_table(mtcars) %>%
-#' transmute(mpg, mpg_predicted = mtcars_predict_mpg(disp, cyl)) %>%
-#' collect() %>%
+#' as_arrow_table(mtcars) |>
+#' transmute(mpg, mpg_predicted = mtcars_predict_mpg(disp, cyl)) |>
+#' collect() |>
#' head()
#'
register_scalar_function <- function(name, fun, in_type, out_type,
diff --git a/r/data-raw/codegen.R b/r/data-raw/codegen.R
index d211dc412c..faa9cab62c 100644
--- a/r/data-raw/codegen.R
+++ b/r/data-raw/codegen.R
@@ -41,13 +41,13 @@ suppressPackageStartupMessages({
})
get_exported_functions <- function(decorations, export_tag) {
- out <- decorations %>%
- filter(decoration %in% paste0(export_tag, "::export")) %>%
- mutate(functions = map(context, decor:::parse_cpp_function)) %>%
+ out <- decorations |>
+ filter(decoration %in% paste0(export_tag, "::export")) |>
+ mutate(functions = map(context, decor:::parse_cpp_function)) |>
{
vec_cbind(., vec_rbind(!!!pull(., functions)))
- } %>%
- select(-functions) %>%
+ } |>
+ select(-functions) |>
mutate(decoration = sub("::export", "", decoration))
message(glue("*** > {n} functions decorated with [[{tags}::export]]", n = nrow(out), tags = paste0(export_tag, collapse = "|")))
out
@@ -123,8 +123,8 @@ extern "C" SEXP {sexp_signature}{{
#endif\n\n')
}
-cpp_functions_definitions <- arrow_exports %>%
- select(name, return_type, args, file, line, decoration) %>%
+cpp_functions_definitions <- arrow_exports |>
+ select(name, return_type, args, file, line, decoration) |>
pmap_chr(function(name, return_type, args, file, line, decoration) {
sexp_params <- glue_collapse_data(args, "SEXP {name}_sexp")
sexp_signature <- glue("_arrow_{name}({sexp_params})")
@@ -147,14 +147,14 @@ cpp_functions_definitions <- arrow_exports %>%
",
sep = "\n"
)
- }) %>%
+ }) |>
glue_collapse(sep = "\n")
-cpp_functions_registration <- arrow_exports %>%
- select(name, return_type, args) %>%
+cpp_functions_registration <- arrow_exports |>
+ select(name, return_type, args) |>
pmap_chr(function(name, return_type, args) {
glue('\t\t{{ "_arrow_{name}", (DL_FUNC) &_arrow_{name}, {nrow(args)}}}, ')
- }) %>%
+ }) |>
glue_collapse(sep = "\n")
cpp_file_header <- '// Generated by using data-raw/codegen.R -> do not edit by hand
@@ -198,8 +198,8 @@ static const R_CallMethodDef CallEntries[] = {
write_if_modified(arrow_exports_cpp, "src/arrowExports.cpp")
-r_functions <- arrow_exports %>%
- select(name, return_type, args) %>%
+r_functions <- arrow_exports |>
+ select(name, return_type, args) |>
pmap_chr(function(name, return_type, args) {
params <- if (nrow(args)) {
paste0(", ", glue_collapse_data(args, "{name}"))
@@ -220,7 +220,7 @@ r_functions <- arrow_exports %>%
list_params = glue_collapse_data(args, "{name}"),
sep = "\n"
)
- }) %>%
+ }) |>
glue_collapse(sep = "\n")
arrow_exports_r <- glue::glue("
diff --git a/r/data-raw/docgen.R b/r/data-raw/docgen.R
index 45773d2465..730772eb8d 100644
--- a/r/data-raw/docgen.R
+++ b/r/data-raw/docgen.R
@@ -115,8 +115,8 @@ render_fun <- function(fun, pkg_fun, notes) {
# This renders a bulleted list under a package heading
render_pkg <- function(df, pkg) {
- bullets <- df %>%
- transmute(render_fun(fun, pkg_fun, notes)) %>%
+ bullets <- df |>
+ transmute(render_fun(fun, pkg_fun, notes)) |>
pull()
header <- paste0("## ", pkg, "\n#'")
# Some packages have global notes to include
@@ -158,7 +158,7 @@ docs <- c(docs, setNames(rep(list(NULL), length(tidyselect)), tidyselect))
fun_df <- tibble::tibble(
pkg_fun = names(docs),
notes = docs
-) %>%
+) |>
mutate(
has_pkg = grepl("::", pkg_fun),
fun = sub("^.*?:{+}", "", pkg_fun),
@@ -167,7 +167,7 @@ fun_df <- tibble::tibble(
pkg = if_else(has_pkg, pkg, "base"),
# Flatten notes to a single string
notes = map_chr(notes, ~ paste(., collapse = "\n#' "))
- ) %>%
+ ) |>
arrange(pkg, fun)
# Group by package name and render the lists
@@ -182,13 +182,13 @@ dplyr_verbs <- c(
verb_bullets <- tibble::tibble(
fun = names(dplyr_verbs),
notes = dplyr_verbs
-) %>%
+) |>
mutate(
pkg_fun = paste0("dplyr::", fun),
notes = map_chr(notes, ~ paste(., collapse = " "))
- ) %>%
- arrange(fun) %>%
- transmute(render_fun(fun, pkg_fun, notes)) %>%
+ ) |>
+ arrange(fun) |>
+ transmute(render_fun(fun, pkg_fun, notes)) |>
pull()
writeLines(
diff --git a/r/tests/testthat/_snaps/dataset-dplyr.md b/r/tests/testthat/_snaps/dataset-dplyr.md
index a2d9820a4e..bb88796826 100644
--- a/r/tests/testthat/_snaps/dataset-dplyr.md
+++ b/r/tests/testthat/_snaps/dataset-dplyr.md
@@ -1,7 +1,7 @@
# dplyr method not implemented messages
Code
- ds %>% filter(int > 6, dbl > max(dbl))
+ filter(ds, int > 6, dbl > max(dbl))
Condition
Error in `dbl > max(dbl)`:
! Expression not supported in filter() in Arrow
diff --git a/r/tests/testthat/_snaps/dplyr-across.md b/r/tests/testthat/_snaps/dplyr-across.md
index 47b5bd61b3..4a8bd7ba9b 100644
--- a/r/tests/testthat/_snaps/dplyr-across.md
+++ b/r/tests/testthat/_snaps/dplyr-across.md
@@ -1,7 +1,7 @@
# expand_across correctly expands quosures
Code
- InMemoryDataset$create(example_data) %>% mutate(across(c(dbl, dbl2), round,
+ mutate(InMemoryDataset$create(example_data), across(c(dbl, dbl2), round,
digits = -1))
Condition
Error in `mutate.Dataset()`:
diff --git a/r/tests/testthat/_snaps/dplyr-funcs-datetime.md b/r/tests/testthat/_snaps/dplyr-funcs-datetime.md
index 036c8b49e8..1110cce6c9 100644
--- a/r/tests/testthat/_snaps/dplyr-funcs-datetime.md
+++ b/r/tests/testthat/_snaps/dplyr-funcs-datetime.md
@@ -1,8 +1,8 @@
# `as.Date()` and `as_date()`
Code
- test_df %>% InMemoryDataset$create() %>% transmute(date_char_ymd = as.Date(
- character_ymd_var, tryFormats = c("%Y-%m-%d", "%Y/%m/%d"))) %>% collect()
+ collect(transmute(InMemoryDataset$create(test_df), date_char_ymd = as.Date(
+ character_ymd_var, tryFormats = c("%Y-%m-%d", "%Y/%m/%d"))))
Condition
Error in `as.Date()`:
! `as.Date()` with multiple `tryFormats` not supported in Arrow
diff --git a/r/tests/testthat/_snaps/dplyr-glimpse.md b/r/tests/testthat/_snaps/dplyr-glimpse.md
index 5e3b074908..1ffd9fc16d 100644
--- a/r/tests/testthat/_snaps/dplyr-glimpse.md
+++ b/r/tests/testthat/_snaps/dplyr-glimpse.md
@@ -86,7 +86,7 @@
# glimpse() calls print() instead of showing data for RBR
Code
- example_data %>% as_record_batch_reader() %>% glimpse()
+ glimpse(as_record_batch_reader(example_data))
Message
Cannot glimpse() data from a RecordBatchReader because it can only be read one time; call `as_arrow_table()` to consume it first.
Output
@@ -103,7 +103,7 @@
---
Code
- example_data %>% as_record_batch_reader() %>% select(int) %>% glimpse()
+ glimpse(select(as_record_batch_reader(example_data), int))
Message
Cannot glimpse() data from a RecordBatchReader because it can only be read one time. Call `compute()` to evaluate the query first.
Output
@@ -131,7 +131,7 @@
# glimpse() on Dataset query only shows data for streaming eval
Code
- ds %>% summarize(max(int)) %>% glimpse()
+ glimpse(summarize(ds, max(int)))
Message
This query requires a full table scan, so glimpse() may be expensive. Call `compute()` to evaluate the query first.
Output
@@ -143,8 +143,7 @@
# glimpse() on in-memory query shows data even if aggregating
Code
- example_data %>% arrow_table() %>% summarize(sum(int, na.rm = TRUE)) %>%
- glimpse()
+ glimpse(summarize(arrow_table(example_data), sum(int, na.rm = TRUE)))
Output
Table (query)
?? rows x 1 columns
diff --git a/r/tests/testthat/_snaps/dplyr-mutate.md b/r/tests/testthat/_snaps/dplyr-mutate.md
index a5bbc0163b..97cd658988 100644
--- a/r/tests/testthat/_snaps/dplyr-mutate.md
+++ b/r/tests/testthat/_snaps/dplyr-mutate.md
@@ -1,8 +1,8 @@
# transmute() defuses dots arguments (ARROW-13262)
Code
- tbl %>% Table$create() %>% transmute(a = stringr::str_c(padded_strings,
- padded_strings), b = stringr::str_squish(a)) %>% collect()
+ collect(transmute(Table$create(tbl), a = stringr::str_c(padded_strings,
+ padded_strings), b = stringr::str_squish(a)))
Condition
Warning:
In stringr::str_squish(a):
diff --git a/r/tests/testthat/_snaps/dplyr-summarize.md b/r/tests/testthat/_snaps/dplyr-summarize.md
index 449a194d68..864223edb4 100644
--- a/r/tests/testthat/_snaps/dplyr-summarize.md
+++ b/r/tests/testthat/_snaps/dplyr-summarize.md
@@ -1,7 +1,7 @@
# Functions that take ... but we only accept a single arg
Code
- InMemoryDataset$create(tbl) %>% summarize(distinct = n_distinct())
+ summarize(InMemoryDataset$create(tbl), distinct = n_distinct())
Condition
Error in `n_distinct()`:
! n_distinct() with 0 arguments not supported in Arrow
@@ -16,7 +16,7 @@
# Expressions on aggregations
Code
- record_batch(tbl) %>% summarise(any(any(lgl)))
+ summarise(record_batch(tbl), any(any(lgl)))
Condition
Warning:
In any(any(lgl)):
@@ -31,8 +31,8 @@
# Can use across() within summarise()
Code
- data.frame(x = 1, y = 2) %>% arrow_table() %>% group_by(x) %>% summarise(across(
- everything())) %>% collect()
+ collect(summarise(group_by(arrow_table(data.frame(x = 1, y = 2)), x), across(
+ everything())))
Condition
Warning:
In y:
diff --git a/r/tests/testthat/helper-filesystems.R b/r/tests/testthat/helper-filesystems.R
index 2ad6d23b01..7b37abf764 100644
--- a/r/tests/testthat/helper-filesystems.R
+++ b/r/tests/testthat/helper-filesystems.R
@@ -88,8 +88,8 @@ test_filesystem <- function(name, fs, path_formatter, uri_formatter) {
test_that(sprintf("open_dataset with an %s file (not directory) URI", name), {
skip_if_not_available("parquet")
expect_identical(
- open_dataset(uri_formatter("test.parquet")) %>% collect() %>% arrange(int),
- example_data %>% arrange(int)
+ open_dataset(uri_formatter("test.parquet")) |> collect() |> arrange(int),
+ example_data |> arrange(int)
)
})
@@ -98,10 +98,10 @@ test_filesystem <- function(name, fs, path_formatter, uri_formatter) {
open_dataset(
c(uri_formatter("test.feather"), uri_formatter("test2.feather")),
format = "feather"
- ) %>%
- arrange(int) %>%
+ ) |>
+ arrange(int) |>
collect(),
- rbind(example_data, example_data) %>% arrange(int)
+ rbind(example_data, example_data) |> arrange(int)
)
})
@@ -157,8 +157,8 @@ test_filesystem <- function(name, fs, path_formatter, uri_formatter) {
test_that(sprintf("open_dataset with %s", name), {
ds <- open_dataset(fs$path(path_formatter("hive_dir")))
expect_identical(
- ds %>% select(int, dbl, lgl) %>% collect() %>% arrange(int),
- rbind(df1[, c("int", "dbl", "lgl")], df2[, c("int", "dbl", "lgl")]) %>% arrange(int)
+ ds |> select(int, dbl, lgl) |> collect() |> arrange(int),
+ rbind(df1[, c("int", "dbl", "lgl")], df2[, c("int", "dbl", "lgl")]) |> arrange(int)
)
})
@@ -174,16 +174,16 @@ test_filesystem <- function(name, fs, path_formatter, uri_formatter) {
expect_length(dir(td), 2)
ds <- open_dataset(td)
expect_identical(
- ds %>% select(int, dbl, lgl) %>% collect() %>% arrange(int),
- rbind(df1[, c("int", "dbl", "lgl")], df2[, c("int", "dbl", "lgl")]) %>% arrange(int)
+ ds |> select(int, dbl, lgl) |> collect() |> arrange(int),
+ rbind(df1[, c("int", "dbl", "lgl")], df2[, c("int", "dbl", "lgl")]) |> arrange(int)
)
# Let's copy the other way and use a SubTreeFileSystem rather than URI
copy_files(td, fs$path(path_formatter("hive_dir2")))
ds2 <- open_dataset(fs$path(path_formatter("hive_dir2")))
expect_identical(
- ds2 %>% select(int, dbl, lgl) %>% collect() %>% arrange(int),
- rbind(df1[, c("int", "dbl", "lgl")], df2[, c("int", "dbl", "lgl")]) %>% arrange(int)
+ ds2 |> select(int, dbl, lgl) |> collect() |> arrange(int),
+ rbind(df1[, c("int", "dbl", "lgl")], df2[, c("int", "dbl", "lgl")]) |> arrange(int)
)
})
} # if(arrow_with_dataset())
diff --git a/r/tests/testthat/test-RecordBatch.R b/r/tests/testthat/test-RecordBatch.R
index 4d04d77e8c..933020a2b2 100644
--- a/r/tests/testthat/test-RecordBatch.R
+++ b/r/tests/testthat/test-RecordBatch.R
@@ -659,37 +659,37 @@ test_that("ARROW-11769/ARROW-13860/ARROW-17085 - grouping preserved in record ba
)
expect_r6_class(
- tbl %>%
- group_by(fct, fct2) %>%
+ tbl |>
+ group_by(fct, fct2) |>
record_batch(),
"RecordBatch"
)
expect_identical(
- tbl %>%
- record_batch() %>%
+ tbl |>
+ record_batch() |>
group_vars(),
group_vars(tbl)
)
expect_identical(
- tbl %>%
- group_by(fct, fct2) %>%
- record_batch() %>%
+ tbl |>
+ group_by(fct, fct2) |>
+ record_batch() |>
group_vars(),
c("fct", "fct2")
)
expect_identical(
- tbl %>%
- group_by(fct, fct2) %>%
- record_batch() %>%
- ungroup() %>%
+ tbl |>
+ group_by(fct, fct2) |>
+ record_batch() |>
+ ungroup() |>
group_vars(),
character()
)
expect_identical(
- tbl %>%
- group_by(fct, fct2) %>%
- record_batch() %>%
- select(-int) %>%
+ tbl |>
+ group_by(fct, fct2) |>
+ record_batch() |>
+ select(-int) |>
group_vars(),
c("fct", "fct2")
)
@@ -778,7 +778,7 @@ test_that("RecordBatchReader to C-interface to arrow_dplyr_query", {
# create an arrow_dplyr_query() from the recordbatch reader
reader_adq <- arrow_dplyr_query(circle)
- tab_from_c_new <- reader_adq %>%
+ tab_from_c_new <- reader_adq |>
dplyr::compute()
expect_equal(tab_from_c_new, tab)
diff --git a/r/tests/testthat/test-Table.R b/r/tests/testthat/test-Table.R
index 50bab5251d..4113f2a765 100644
--- a/r/tests/testthat/test-Table.R
+++ b/r/tests/testthat/test-Table.R
@@ -597,15 +597,15 @@ test_that("ARROW-11769/ARROW-17085 - grouping preserved in table creation", {
)
expect_identical(
- tbl %>%
- Table$create() %>%
+ tbl |>
+ Table$create() |>
dplyr::group_vars(),
dplyr::group_vars(tbl)
)
expect_identical(
- tbl %>%
- dplyr::group_by(fct, fct2) %>%
- Table$create() %>%
+ tbl |>
+ dplyr::group_by(fct, fct2) |>
+ Table$create() |>
dplyr::group_vars(),
c("fct", "fct2")
)
diff --git a/r/tests/testthat/test-compute-sort.R b/r/tests/testthat/test-compute-sort.R
index b8c8482d64..3e7d655f1e 100644
--- a/r/tests/testthat/test-compute-sort.R
+++ b/r/tests/testthat/test-compute-sort.R
@@ -147,7 +147,7 @@ test_that("Table$SortIndices()", {
)
expect_equal_data_frame(
x$Take(x$SortIndices(c("int", "dbl"), c(FALSE, FALSE))),
- tbl %>% arrange(int, dbl)
+ tbl |> arrange(int, dbl)
)
})
@@ -155,6 +155,6 @@ test_that("RecordBatch$SortIndices()", {
x <- record_batch(tbl)
expect_equal_data_frame(
x$Take(x$SortIndices(c("chr", "int", "dbl"), TRUE)),
- tbl %>% arrange(desc(chr), desc(int), desc(dbl))
+ tbl |> arrange(desc(chr), desc(int), desc(dbl))
)
})
diff --git a/r/tests/testthat/test-csv.R b/r/tests/testthat/test-csv.R
index 769c2c98f1..94308b6117 100644
--- a/r/tests/testthat/test-csv.R
+++ b/r/tests/testthat/test-csv.R
@@ -603,7 +603,7 @@ test_that("write_csv_arrow can write from RecordBatchReader objects", {
skip_if_not_available("dataset")
library(dplyr, warn.conflicts = FALSE)
- query_obj <- arrow_table(tbl_no_dates) %>%
+ query_obj <- arrow_table(tbl_no_dates) |>
filter(lgl == TRUE)
csv_file <- tempfile()
diff --git a/r/tests/testthat/test-dataset-csv.R b/r/tests/testthat/test-dataset-csv.R
index 91e93192ed..b908600b1e 100644
--- a/r/tests/testthat/test-dataset-csv.R
+++ b/r/tests/testthat/test-dataset-csv.R
@@ -53,19 +53,19 @@ test_that("CSV dataset", {
expect_identical(dim(ds), c(20L, 7L))
expect_equal(
- ds %>%
- select(string = chr, integer = int, part) %>%
- filter(integer > 6 & part == 5) %>%
- collect() %>%
+ ds |>
+ select(string = chr, integer = int, part) |>
+ filter(integer > 6 & part == 5) |>
+ collect() |>
summarize(mean = mean(as.numeric(integer))), # as.numeric bc they're being parsed as int64
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
# Collecting virtual partition column works
expect_equal(
- collect(ds) %>% arrange(part) %>% pull(part),
+ collect(ds) |> arrange(part) |> pull(part),
c(rep(5, 10), rep(6, 10))
)
})
@@ -85,7 +85,7 @@ test_that("CSV scan options", {
write.csv(df, dst_file, row.names = FALSE, quote = FALSE)
ds <- open_dataset(dst_dir, format = "csv")
- expect_equal(ds %>% collect(), df)
+ expect_equal(ds |> collect(), df)
sb <- ds$NewScan()
sb$FragmentScanOptions(options)
@@ -99,7 +99,7 @@ test_that("CSV scan options", {
strings_can_be_null = TRUE
)
ds <- open_dataset(dst_dir, format = csv_format)
- expect_equal(ds %>% collect(), tibble(chr = c("foo", NA)))
+ expect_equal(ds |> collect(), tibble(chr = c("foo", NA)))
# Set both parse and convert options
df <- tibble(chr = c("foo", "mynull"), chr2 = c("bar", "baz"))
@@ -110,15 +110,15 @@ test_that("CSV scan options", {
null_values = c("mynull"),
strings_can_be_null = TRUE
)
- expect_equal(ds %>% collect(), tibble(
+ expect_equal(ds |> collect(), tibble(
chr = c("foo", NA),
chr2 = c("bar", "baz")
))
expect_equal(
- ds %>%
- group_by(chr2) %>%
- summarize(na = all(is.na(chr))) %>%
- arrange(chr2) %>%
+ ds |>
+ group_by(chr2) |>
+ summarize(na = all(is.na(chr))) |>
+ arrange(chr2) |>
collect(),
tibble(
chr2 = c("bar", "baz"),
@@ -138,14 +138,14 @@ test_that("compressed CSV dataset", {
expect_r6_class(ds$filesystem, "LocalFileSystem")
expect_equal(
- ds %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6 & integer < 11) %>%
- collect() %>%
+ ds |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6 & integer < 11) |>
+ collect() |>
summarize(mean = mean(integer)),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
@@ -160,18 +160,18 @@ test_that("CSV dataset options", {
ds <- open_dataset(dst_dir, format = format)
expect_equal(
- ds %>%
- select(string = a) %>%
+ ds |>
+ select(string = a) |>
collect(),
- df1[-1, ] %>%
+ df1[-1, ] |>
select(string = chr)
)
ds <- open_dataset(dst_dir, format = "csv", column_names = c("foo"))
expect_equal(
- ds %>%
- select(string = foo) %>%
+ ds |>
+ select(string = foo) |>
collect(),
tibble(string = c(c("chr"), letters[1:10]))
)
@@ -180,27 +180,27 @@ test_that("CSV dataset options", {
test_that("Other text delimited dataset", {
ds1 <- open_dataset(tsv_dir, partitioning = "part", format = "tsv")
expect_equal(
- ds1 %>%
- select(string = chr, integer = int, part) %>%
- filter(integer > 6 & part == 5) %>%
- collect() %>%
+ ds1 |>
+ select(string = chr, integer = int, part) |>
+ filter(integer > 6 & part == 5) |>
+ collect() |>
summarize(mean = mean(as.numeric(integer))), # as.numeric bc they're being parsed as int64
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
ds2 <- open_dataset(tsv_dir, partitioning = "part", format = "text", delimiter = "\t")
expect_equal(
- ds2 %>%
- select(string = chr, integer = int, part) %>%
- filter(integer > 6 & part == 5) %>%
- collect() %>%
+ ds2 |>
+ select(string = chr, integer = int, part) |>
+ filter(integer > 6 & part == 5) |>
+ collect() |>
summarize(mean = mean(as.numeric(integer))), # as.numeric bc they're being parsed as int64
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
@@ -261,14 +261,14 @@ test_that("readr parse options", {
# With only readr parse options (and omitting format = "text")
ds1 <- open_dataset(tsv_dir, partitioning = "part", delim = "\t")
expect_equal(
- ds1 %>%
- select(string = chr, integer = int, part) %>%
- filter(integer > 6 & part == 5) %>%
- collect() %>%
+ ds1 |>
+ select(string = chr, integer = int, part) |>
+ filter(integer > 6 & part == 5) |>
+ collect() |>
summarize(mean = mean(as.numeric(integer))), # as.numeric bc they're being parsed as int64
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
@@ -281,7 +281,7 @@ test_that("Can set null string values", {
csv_contents <- readLines(list.files(dst_dir, full.names = TRUE)[1])
expect_equal(csv_contents, c("\"x\"", "1", "NULL_VALUE", "3"))
- back <- open_dataset(dst_dir, null_values = "NULL_VALUE", format = "csv") %>% collect()
+ back <- open_dataset(dst_dir, null_values = "NULL_VALUE", format = "csv") |> collect()
expect_equal(df, back)
# Also works with `na` parameter
@@ -291,7 +291,7 @@ test_that("Can set null string values", {
csv_contents <- readLines(list.files(dst_dir, full.names = TRUE)[1])
expect_equal(csv_contents, c("\"x\"", "1", "another_null", "3"))
- back <- open_dataset(dst_dir, null_values = "another_null", format = "csv") %>% collect()
+ back <- open_dataset(dst_dir, null_values = "another_null", format = "csv") |> collect()
expect_equal(df, back)
})
@@ -339,7 +339,7 @@ test_that("Column names can be inferred from schema", {
format = "csv",
schema = schema(int = int32(), dbl = float64())
)
- expect_equal(ds %>% collect(), tbl)
+ expect_equal(ds |> collect(), tbl)
})
test_that("Can use col_names readr parameter", {
@@ -350,7 +350,7 @@ test_that("Can use col_names readr parameter", {
col_names = expected_names
)
expect_named(ds, expected_names)
- expect_equal(ds %>% collect(), set_names(tbl, expected_names))
+ expect_equal(ds |> collect(), set_names(tbl, expected_names))
# WITHOUT header, makes up names
ds <- open_dataset(
@@ -359,7 +359,7 @@ test_that("Can use col_names readr parameter", {
col_names = FALSE
)
expect_named(ds, c("f0", "f1"))
- expect_equal(ds %>% collect(), set_names(tbl, c("f0", "f1")))
+ expect_equal(ds |> collect(), set_names(tbl, c("f0", "f1")))
# WITH header, gets names
ds <- open_dataset(
@@ -368,7 +368,7 @@ test_that("Can use col_names readr parameter", {
col_names = TRUE
)
expect_named(ds, c("int", "dbl"))
- expect_equal(ds %>% collect(), tbl)
+ expect_equal(ds |> collect(), tbl)
ds <- open_dataset(
header_csv_dir,
@@ -377,7 +377,7 @@ test_that("Can use col_names readr parameter", {
skip = 1
)
expect_named(ds, c("f0", "f1"))
- expect_equal(ds %>% collect(), set_names(tbl, c("f0", "f1")))
+ expect_equal(ds |> collect(), set_names(tbl, c("f0", "f1")))
expect_error(
open_dataset(headerless_csv_dir, format = "csv", col_names = c("my_int"))
@@ -390,7 +390,7 @@ test_that("open_dataset() deals with BOMs (byte-order-marks) correctly", {
writeLines("\xef\xbb\xbfa,b\n3,4\n", con = file.path(temp_dir, "file2.csv"))
expect_equal(
- open_dataset(temp_dir, format = "csv") %>% collect() %>% arrange(b),
+ open_dataset(temp_dir, format = "csv") |> collect() |> arrange(b),
tibble(a = c(1, 3), b = c(2, 4))
)
})
@@ -463,7 +463,7 @@ test_that("CSV reading/parsing/convert options can be passed in as lists", {
format = "csv",
convert_options = list(null_values = c("NA", "NULL"), strings_can_be_null = TRUE),
read_options = list(skip_rows = 1L)
- ) %>%
+ ) |>
collect()
ds2 <- open_dataset(
@@ -471,7 +471,7 @@ test_that("CSV reading/parsing/convert options can be passed in as lists", {
format = "csv",
convert_options = csv_convert_options(null_values = c(NA, "NA", "NULL"), strings_can_be_null = TRUE),
read_options = csv_read_options(skip_rows = 1L)
- ) %>%
+ ) |>
collect()
expect_equal(ds1, ds2)
@@ -491,11 +491,11 @@ test_that("open_delim_dataset params passed through to open_dataset", {
df <- data.frame(a = c(1, 2), b = c("'abc'", "'def'"))
write.csv(df, dst_file, row.names = FALSE, quote = FALSE)
- ds_quote <- open_csv_dataset(dst_dir, quote = "'") %>% collect()
+ ds_quote <- open_csv_dataset(dst_dir, quote = "'") |> collect()
expect_equal(ds_quote$b, c("abc", "def"))
# na
- ds <- open_csv_dataset(csv_dir, partitioning = "part", na = c("", "NA", "FALSE")) %>% collect()
+ ds <- open_csv_dataset(csv_dir, partitioning = "part", na = c("", "NA", "FALSE")) |> collect()
expect_identical(ds$lgl, c(
TRUE, NA, NA, TRUE, NA, TRUE, NA, NA, TRUE, NA, TRUE, NA, NA,
TRUE, NA, TRUE, NA, NA, TRUE, NA
@@ -507,7 +507,7 @@ test_that("open_delim_dataset params passed through to open_dataset", {
partitioning = "part",
col_names = paste0("col_", 1:6),
skip = 1
- ) %>% collect()
+ ) |> collect()
expect_named(ds, c("col_1", "col_2", "col_3", "col_4", "col_5", "col_6", "part"))
expect_equal(nrow(ds), 20)
@@ -542,14 +542,14 @@ test_that("open_delim_dataset params passed through to open_dataset", {
tf <- tempfile()
writeLines('"x"\n"y"\nNA\nNA\n"NULL"\n\n\n', tf)
- ds <- open_csv_dataset(tf, skip_empty_rows = FALSE) %>% collect()
+ ds <- open_csv_dataset(tf, skip_empty_rows = FALSE) |> collect()
expect_equal(nrow(ds), 7)
# convert_options
ds <- open_csv_dataset(
csv_dir,
convert_options = list(null_values = c("NA", "", "FALSE"), strings_can_be_null = TRUE)
- ) %>% collect()
+ ) |> collect()
expect_equal(
ds$lgl,
@@ -560,7 +560,7 @@ test_that("open_delim_dataset params passed through to open_dataset", {
ds <- open_csv_dataset(
csv_dir,
read_options = list(column_names = paste0("col_", 1:6))
- ) %>% collect()
+ ) |> collect()
expect_named(ds, c("col_1", "col_2", "col_3", "col_4", "col_5", "col_6"))
@@ -572,7 +572,7 @@ test_that("open_delim_dataset params passed through to open_dataset", {
fct = utf8(), ts = timestamp(unit = "s")
),
skip = 1
- ) %>% collect()
+ ) |> collect()
expect_named(ds, c("int", "dbl", "lgl", "chr", "fct", "ts"))
@@ -580,10 +580,10 @@ test_that("open_delim_dataset params passed through to open_dataset", {
dst_dir <- make_temp_dir()
dst_file <- file.path(dst_dir, "data.csv")
writeLines("text,num\none,1\ntwo,2\n,3\nfour,4", dst_file)
- ds <- open_csv_dataset(dst_dir, quoted_na = TRUE) %>% collect()
+ ds <- open_csv_dataset(dst_dir, quoted_na = TRUE) |> collect()
expect_equal(ds$text, c("one", "two", NA, "four"))
- ds <- open_csv_dataset(dst_dir, quoted_na = FALSE) %>% collect()
+ ds <- open_csv_dataset(dst_dir, quoted_na = FALSE) |> collect()
expect_equal(ds$text, c("one", "two", "", "four"))
# parse_options
@@ -593,7 +593,7 @@ test_that("open_delim_dataset params passed through to open_dataset", {
ds <- open_csv_dataset(
dst_dir,
parse_options = csv_parse_options(ignore_empty_lines = FALSE)
- ) %>% collect()
+ ) |> collect()
expect_equal(ds$x, c(NA, 1L, NA, NA, 2L, NA, 3L))
# timestamp_parsers
@@ -605,7 +605,7 @@ test_that("open_delim_dataset params passed through to open_dataset", {
df <- data.frame(time = "2023-01-16 19:47:57")
write.csv(df, dst_file, row.names = FALSE, quote = FALSE)
- ds <- open_csv_dataset(dst_dir, timestamp_parsers = c(TimestampParser$create(format = "%d-%m-%y"))) %>% collect()
+ ds <- open_csv_dataset(dst_dir, timestamp_parsers = c(TimestampParser$create(format = "%d-%m-%y"))) |> collect()
expect_equal(ds$time, "16-01-2023")
})
@@ -651,14 +651,14 @@ test_that("GH-34640 - CSV datasets are read in correctly when both schema and pa
expect_equal(schema(ds), target_schema)
expect_equal(
- ds %>%
- select(string = chr, integer = int, part) %>%
- filter(integer > 6 & part == 5) %>%
- collect() %>%
+ ds |>
+ select(string = chr, integer = int, part) |>
+ filter(integer > 6 & part == 5) |>
+ collect() |>
summarize(mean = mean(as.numeric(integer))),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
@@ -668,12 +668,12 @@ test_that("open_dataset() with `decimal_point` argument", {
writeLines("x\ty\n1,2\tc", con = file.path(temp_dir, "file1.csv"))
expect_equal(
- open_dataset(temp_dir, format = "tsv") %>% collect(),
+ open_dataset(temp_dir, format = "tsv") |> collect(),
tibble(x = "1,2", y = "c")
)
expect_equal(
- open_dataset(temp_dir, format = "tsv", decimal_point = ",") %>% collect(),
+ open_dataset(temp_dir, format = "tsv", decimal_point = ",") |> collect(),
tibble(x = 1.2, y = "c")
)
})
diff --git a/r/tests/testthat/test-dataset-dplyr.R b/r/tests/testthat/test-dataset-dplyr.R
index d5c8dc9820..09ca0ef155 100644
--- a/r/tests/testthat/test-dataset-dplyr.R
+++ b/r/tests/testthat/test-dataset-dplyr.R
@@ -40,9 +40,9 @@ test_that("Setup (putting data in the dir)", {
test_that("filter() with is.nan()", {
ds <- open_dataset(dataset_dir, partitioning = schema(part = uint8()))
expect_equal(
- ds %>%
- select(part, dbl) %>%
- filter(!is.nan(dbl), part == 2) %>%
+ ds |>
+ select(part, dbl) |>
+ filter(!is.nan(dbl), part == 2) |>
collect(),
tibble(part = 2L, dbl = df2$dbl[!is.nan(df2$dbl)])
)
@@ -51,9 +51,9 @@ test_that("filter() with is.nan()", {
test_that("filter() with %in%", {
ds <- open_dataset(dataset_dir, partitioning = schema(part = uint8()))
expect_equal(
- ds %>%
- select(int, part) %>%
- filter(int %in% c(6, 4, 3, 103, 107), part == 1) %>%
+ ds |>
+ select(int, part) |>
+ filter(int %in% c(6, 4, 3, 103, 107), part == 1) |>
collect(),
tibble(int = df1$int[c(3, 4, 6)], part = 1)
)
@@ -61,9 +61,9 @@ test_that("filter() with %in%", {
# ARROW-9606: bug in %in% filter on partition column with >1 partition columns
ds <- open_dataset(hive_dir)
expect_equal(
- ds %>%
- filter(group %in% 2) %>%
- select(names(df2)) %>%
+ ds |>
+ filter(group %in% 2) |>
+ select(names(df2)) |>
collect(),
df2
)
@@ -74,20 +74,20 @@ test_that("filter() on timestamp columns", {
ds <- open_dataset(dataset_dir, partitioning = schema(part = uint8()))
expect_equal(
- ds %>%
- filter(ts >= lubridate::ymd_hms("2015-05-04 03:12:39")) %>%
- filter(part == 1) %>%
- select(ts) %>%
+ ds |>
+ filter(ts >= lubridate::ymd_hms("2015-05-04 03:12:39")) |>
+ filter(part == 1) |>
+ select(ts) |>
collect(),
df1[5:10, c("ts")],
)
# Now with Date
expect_equal(
- ds %>%
- filter(ts >= as.Date("2015-05-04")) %>%
- filter(part == 1) %>%
- select(ts) %>%
+ ds |>
+ filter(ts >= as.Date("2015-05-04")) |>
+ filter(part == 1) |>
+ select(ts) |>
collect(),
df1[5:10, c("ts")],
)
@@ -95,10 +95,10 @@ test_that("filter() on timestamp columns", {
# Now with bare string date
skip("Implement more aggressive implicit casting for scalars (ARROW-11402)")
expect_equal(
- ds %>%
- filter(ts >= "2015-05-04") %>%
- filter(part == 1) %>%
- select(ts) %>%
+ ds |>
+ filter(ts >= "2015-05-04") |>
+ filter(part == 1) |>
+ select(ts) |>
collect(),
df1[5:10, c("ts")],
)
@@ -111,9 +111,9 @@ test_that("filter() on date32 columns", {
write_parquet(df, file.path(tmp, "file.parquet"))
expect_equal(
- open_dataset(tmp) %>%
- filter(date > as.Date("2020-02-02")) %>%
- collect() %>%
+ open_dataset(tmp) |>
+ filter(date > as.Date("2020-02-02")) |>
+ collect() |>
nrow(),
1L
)
@@ -122,9 +122,9 @@ test_that("filter() on date32 columns", {
# Also with timestamp scalar
expect_equal(
- open_dataset(tmp) %>%
- filter(date > lubridate::ymd_hms("2020-02-02 00:00:00")) %>%
- collect() %>%
+ open_dataset(tmp) |>
+ filter(date > lubridate::ymd_hms("2020-02-02 00:00:00")) |>
+ collect() |>
nrow(),
1L
)
@@ -133,9 +133,9 @@ test_that("filter() on date32 columns", {
test_that("mutate()", {
ds <- open_dataset(dataset_dir, partitioning = schema(part = uint8()))
- mutated <- ds %>%
- select(chr, dbl, int) %>%
- filter(dbl * 2 > 14 & dbl - 50 < 3L) %>%
+ mutated <- ds |>
+ select(chr, dbl, int) |>
+ filter(dbl * 2 > 14 & dbl - 50 < 3L) |>
mutate(twice = int * 2)
expect_output(
print(mutated),
@@ -150,13 +150,13 @@ See $.data for the source Arrow object",
fixed = TRUE
)
expect_equal(
- mutated %>%
- collect() %>%
+ mutated |>
+ collect() |>
arrange(dbl),
rbind(
df1[8:10, c("chr", "dbl", "int")],
df2[1:2, c("chr", "dbl", "int")]
- ) %>%
+ ) |>
mutate(
twice = int * 2
)
@@ -166,8 +166,8 @@ See $.data for the source Arrow object",
test_that("filter scalar validation doesn't crash (ARROW-7772)", {
ds <- open_dataset(dataset_dir, partitioning = schema(part = uint8()))
expect_error(
- ds %>%
- filter(int == Expression$scalar("fff"), part == 1) %>%
+ ds |>
+ filter(int == Expression$scalar("fff"), part == 1) |>
collect(),
"'equal' has no kernel matching input types .int32, string."
)
@@ -175,7 +175,7 @@ test_that("filter scalar validation doesn't crash (ARROW-7772)", {
test_that("collect() on Dataset works (if fits in memory)", {
expect_equal(
- collect(open_dataset(dataset_dir)) %>% arrange(int),
+ collect(open_dataset(dataset_dir)) |> arrange(int),
rbind(df1, df2)
)
})
@@ -184,23 +184,23 @@ test_that("count()", {
ds <- open_dataset(dataset_dir)
df <- rbind(df1, df2)
expect_equal(
- ds %>%
- filter(int > 6, int < 108) %>%
- count(chr) %>%
- arrange(chr) %>%
+ ds |>
+ filter(int > 6, int < 108) |>
+ count(chr) |>
+ arrange(chr) |>
collect(),
- df %>%
- filter(int > 6, int < 108) %>%
+ df |>
+ filter(int > 6, int < 108) |>
count(chr)
)
})
test_that("arrange()", {
ds <- open_dataset(dataset_dir, partitioning = schema(part = uint8()))
- arranged <- ds %>%
- select(chr, dbl, int) %>%
- filter(dbl * 2 > 14 & dbl - 50 < 3L) %>%
- mutate(twice = int * 2) %>%
+ arranged <- ds |>
+ select(chr, dbl, int) |>
+ filter(dbl * 2 > 14 & dbl - 50 < 3L) |>
+ mutate(twice = int * 2) |>
arrange(chr, desc(twice), dbl + int)
expect_output(
print(arranged),
@@ -216,7 +216,7 @@ See $.data for the source Arrow object",
fixed = TRUE
)
expect_equal(
- arranged %>%
+ arranged |>
collect(),
rbind(
df1[8, c("chr", "dbl", "int")],
@@ -224,7 +224,7 @@ See $.data for the source Arrow object",
df1[9, c("chr", "dbl", "int")],
df2[1, c("chr", "dbl", "int")],
df1[10, c("chr", "dbl", "int")]
- ) %>%
+ ) |>
mutate(
twice = int * 2
)
@@ -234,43 +234,43 @@ See $.data for the source Arrow object",
test_that("compute()/collect(as_data_frame=FALSE)", {
ds <- open_dataset(dataset_dir)
- tab1 <- ds %>% compute()
+ tab1 <- ds |> compute()
expect_r6_class(tab1, "Table")
- tab2 <- ds %>% collect(as_data_frame = FALSE)
+ tab2 <- ds |> collect(as_data_frame = FALSE)
expect_r6_class(tab2, "Table")
- tab3 <- ds %>%
- mutate(negint = -int) %>%
- filter(negint > -100) %>%
- arrange(chr) %>%
- select(negint) %>%
+ tab3 <- ds |>
+ mutate(negint = -int) |>
+ filter(negint > -100) |>
+ arrange(chr) |>
+ select(negint) |>
compute()
expect_r6_class(tab3, "Table")
expect_equal(
- tab3 %>% collect(),
+ tab3 |> collect(),
tibble(negint = -1:-10)
)
- tab4 <- ds %>%
- mutate(negint = -int) %>%
- filter(negint > -100) %>%
- arrange(chr) %>%
- select(negint) %>%
+ tab4 <- ds |>
+ mutate(negint = -int) |>
+ filter(negint > -100) |>
+ arrange(chr) |>
+ select(negint) |>
collect(as_data_frame = FALSE)
expect_r6_class(tab3, "Table")
expect_equal(
- tab4 %>% collect(),
+ tab4 |> collect(),
tibble(negint = -1:-10)
)
- tab5 <- ds %>%
- mutate(negint = -int) %>%
- group_by(fct) %>%
+ tab5 <- ds |>
+ mutate(negint = -int) |>
+ group_by(fct) |>
compute()
expect_r6_class(tab5, "Table")
@@ -284,37 +284,37 @@ test_that("head/tail on query on dataset", {
ds <- open_dataset(dataset_dir)
expect_identical(
- ds %>%
- filter(int > 6) %>%
- head(5) %>%
- compute() %>%
+ ds |>
+ filter(int > 6) |>
+ head(5) |>
+ compute() |>
nrow(),
5L
)
expect_equal(
- ds %>%
- filter(int > 6) %>%
- arrange(int) %>%
- head() %>%
+ ds |>
+ filter(int > 6) |>
+ arrange(int) |>
+ head() |>
collect(),
rbind(df1[7:10, ], df2[1:2, ])
)
expect_equal(
- ds %>%
- filter(int < 105) %>%
- tail(4) %>%
- compute() %>%
+ ds |>
+ filter(int < 105) |>
+ tail(4) |>
+ compute() |>
nrow(),
4L
)
expect_equal(
- ds %>%
- filter(int < 105) %>%
- arrange(int) %>%
- tail() %>%
+ ds |>
+ filter(int < 105) |>
+ arrange(int) |>
+ tail() |>
collect(),
rbind(df1[9:10, ], df2[1:4, ])
)
@@ -324,7 +324,7 @@ test_that("dplyr method not implemented messages", {
ds <- open_dataset(dataset_dir)
# This one is more nuanced
expect_snapshot(
- ds %>% filter(int > 6, dbl > max(dbl)),
+ ds |> filter(int > 6, dbl > max(dbl)),
error = TRUE
)
})
@@ -337,7 +337,7 @@ test_that("show_exec_plan(), show_query() and explain() with datasets", {
# minimal test
expect_output(
- ds %>%
+ ds |>
show_exec_plan(),
regexp = paste0(
"ExecPlan with .* nodes:.*", # boiler plate for ExecPlan
@@ -348,9 +348,9 @@ test_that("show_exec_plan(), show_query() and explain() with datasets", {
# filter and select
expect_output(
- ds %>%
- select(string = chr, integer = int, part) %>%
- filter(integer > 6L & part == 1) %>%
+ ds |>
+ select(string = chr, integer = int, part) |>
+ filter(integer > 6L & part == 1) |>
show_exec_plan(),
regexp = paste0(
"ExecPlan with .* nodes:.*", # boiler plate for ExecPlan
@@ -363,9 +363,9 @@ test_that("show_exec_plan(), show_query() and explain() with datasets", {
# group_by and summarise
expect_output(
- ds %>%
- group_by(part) %>%
- summarise(avg = mean(int)) %>%
+ ds |>
+ group_by(part) |>
+ summarise(avg = mean(int)) |>
show_exec_plan(),
regexp = paste0(
"ExecPlan with .* nodes:.*", # boiler plate for ExecPlan
@@ -379,9 +379,9 @@ test_that("show_exec_plan(), show_query() and explain() with datasets", {
# arrange and head
expect_output(
- ds %>%
- filter(lgl) %>%
- arrange(chr) %>%
+ ds |>
+ filter(lgl) |>
+ arrange(chr) |>
show_exec_plan(),
regexp = paste0(
"ExecPlan with .* nodes:.*", # boiler plate for ExecPlan
diff --git a/r/tests/testthat/test-dataset-json.R b/r/tests/testthat/test-dataset-json.R
index 1265b928cd..17537aaf46 100644
--- a/r/tests/testthat/test-dataset-json.R
+++ b/r/tests/testthat/test-dataset-json.R
@@ -43,19 +43,19 @@ test_that("JSON dataset", {
expect_identical(dim(ds), c(20L, 7L))
expect_equal(
- ds %>%
- select(string = chr, integer = int, part) %>%
- filter(integer > 6 & part == 5) %>%
- collect() %>%
+ ds |>
+ select(string = chr, integer = int, part) |>
+ filter(integer > 6 & part == 5) |>
+ collect() |>
summarize(mean = mean(as.numeric(integer))), # as.numeric bc they're being parsed as int64
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
# Collecting virtual partition column works
expect_equal(
- collect(ds) %>% arrange(part) %>% pull(part),
+ collect(ds) |> arrange(part) |> pull(part),
c(rep(5, 10), rep(6, 10))
)
})
diff --git a/r/tests/testthat/test-dataset-uri.R b/r/tests/testthat/test-dataset-uri.R
index bdcccf2827..d0cda5c287 100644
--- a/r/tests/testthat/test-dataset-uri.R
+++ b/r/tests/testthat/test-dataset-uri.R
@@ -42,10 +42,10 @@ test_that("dataset from single local file path", {
ds <- open_dataset(files[1])
expect_r6_class(ds, "Dataset")
expect_equal(
- ds %>%
- select(chr, dbl) %>%
- filter(dbl > 7) %>%
- collect() %>%
+ ds |>
+ select(chr, dbl) |>
+ filter(dbl > 7) |>
+ collect() |>
arrange(dbl),
df1[8:10, c("chr", "dbl")]
)
@@ -55,10 +55,10 @@ test_that("dataset from vector of file paths", {
ds <- open_dataset(files)
expect_r6_class(ds, "Dataset")
expect_equal(
- ds %>%
- select(chr, dbl) %>%
- filter(dbl > 7 & dbl < 53L) %>%
- collect() %>%
+ ds |>
+ select(chr, dbl) |>
+ filter(dbl > 7 & dbl < 53L) |>
+ collect() |>
arrange(dbl),
rbind(
df1[8:10, c("chr", "dbl")],
@@ -72,10 +72,10 @@ test_that("dataset from directory URI", {
ds <- open_dataset(uri, partitioning = schema(part = uint8()))
expect_r6_class(ds, "Dataset")
expect_equal(
- ds %>%
- select(chr, dbl) %>%
- filter(dbl > 7 & dbl < 53L) %>%
- collect() %>%
+ ds |>
+ select(chr, dbl) |>
+ filter(dbl > 7 & dbl < 53L) |>
+ collect() |>
arrange(dbl),
rbind(
df1[8:10, c("chr", "dbl")],
@@ -89,10 +89,10 @@ test_that("dataset from single file URI", {
ds <- open_dataset(uri)
expect_r6_class(ds, "Dataset")
expect_equal(
- ds %>%
- select(chr, dbl) %>%
- filter(dbl > 7) %>%
- collect() %>%
+ ds |>
+ select(chr, dbl) |>
+ filter(dbl > 7) |>
+ collect() |>
arrange(dbl),
df1[8:10, c("chr", "dbl")]
)
@@ -103,10 +103,10 @@ test_that("dataset from vector of file URIs", {
ds <- open_dataset(uris)
expect_r6_class(ds, "Dataset")
expect_equal(
- ds %>%
- select(chr, dbl) %>%
- filter(dbl > 7 & dbl < 53L) %>%
- collect() %>%
+ ds |>
+ select(chr, dbl) |>
+ filter(dbl > 7 & dbl < 53L) |>
+ collect() |>
arrange(dbl),
rbind(
df1[8:10, c("chr", "dbl")],
diff --git a/r/tests/testthat/test-dataset-write.R b/r/tests/testthat/test-dataset-write.R
index 9f69380c55..79952b670e 100644
--- a/r/tests/testthat/test-dataset-write.R
+++ b/r/tests/testthat/test-dataset-write.R
@@ -50,14 +50,14 @@ test_that("Writing a dataset: CSV->IPC", {
new_ds <- open_dataset(dst_dir, format = "feather")
expect_equal(
- new_ds %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6 & integer < 11) %>%
- collect() %>%
+ new_ds |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6 & integer < 11) |>
+ collect() |>
summarize(mean = mean(integer)),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
@@ -81,14 +81,14 @@ test_that("Writing a dataset: Parquet->IPC", {
new_ds <- open_dataset(dst_dir, format = "feather")
expect_equal(
- new_ds %>%
- select(string = chr, integer = int, group) %>%
- filter(integer > 6 & group == 1) %>%
- collect() %>%
+ new_ds |>
+ select(string = chr, integer = int, group) |>
+ filter(integer > 6 & group == 1) |>
+ collect() |>
summarize(mean = mean(integer)),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
@@ -104,14 +104,14 @@ test_that("Writing a dataset: CSV->Parquet", {
new_ds <- open_dataset(dst_dir)
expect_equal(
- new_ds %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6 & integer < 11) %>%
- collect() %>%
+ new_ds |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6 & integer < 11) |>
+ collect() |>
summarize(mean = mean(integer)),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
@@ -127,14 +127,14 @@ test_that("Writing a dataset: Parquet->Parquet (default)", {
new_ds <- open_dataset(dst_dir)
expect_equal(
- new_ds %>%
- select(string = chr, integer = int, group) %>%
- filter(integer > 6 & group == 1) %>%
- collect() %>%
+ new_ds |>
+ select(string = chr, integer = int, group) |>
+ filter(integer > 6 & group == 1) |>
+ collect() |>
summarize(mean = mean(integer)),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
@@ -186,14 +186,14 @@ test_that("Writing a dataset: existing data behavior", {
new_ds <- open_dataset(dst_dir, format = "feather")
expect_equal(
- new_ds %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6 & integer < 11) %>%
- collect() %>%
+ new_ds |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6 & integer < 11) |>
+ collect() |>
summarize(mean = mean(integer)),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
}
@@ -225,7 +225,7 @@ test_that("Writing a dataset: no format specified", {
inherits(new_ds$format, "ParquetFileFormat")
)
expect_equal(
- new_ds %>% collect(),
+ new_ds |> collect(),
example_data
)
})
@@ -235,65 +235,65 @@ test_that("Dataset writing: dplyr methods", {
ds <- open_dataset(hive_dir)
dst_dir <- tempfile()
# Specify partition vars by group_by
- ds %>%
- group_by(int) %>%
+ ds |>
+ group_by(int) |>
write_dataset(dst_dir, format = "feather")
expect_true(dir.exists(dst_dir))
expect_identical(dir(dst_dir), sort(paste("int", c(1:10, 101:110), sep = "=")))
# select to specify schema (and rename)
dst_dir2 <- tempfile()
- ds %>%
- group_by(int) %>%
- select(chr, dubs = dbl) %>%
+ ds |>
+ group_by(int) |>
+ select(chr, dubs = dbl) |>
write_dataset(dst_dir2, format = "feather")
new_ds <- open_dataset(dst_dir2, format = "feather")
expect_equal(
- collect(new_ds) %>% arrange(int),
- rbind(df1[c("chr", "dbl", "int")], df2[c("chr", "dbl", "int")]) %>% rename(dubs = dbl)
+ collect(new_ds) |> arrange(int),
+ rbind(df1[c("chr", "dbl", "int")], df2[c("chr", "dbl", "int")]) |> rename(dubs = dbl)
)
# filter to restrict written rows
dst_dir3 <- tempfile()
- ds %>%
- filter(int == 4) %>%
+ ds |>
+ filter(int == 4) |>
write_dataset(dst_dir3, format = "feather")
new_ds <- open_dataset(dst_dir3, format = "feather")
expect_equal(
- new_ds %>% select(names(df1)) %>% collect(),
- df1 %>% filter(int == 4)
+ new_ds |> select(names(df1)) |> collect(),
+ df1 |> filter(int == 4)
)
# mutate
dst_dir3 <- tempfile()
- ds %>%
- filter(int == 4) %>%
- mutate(twice = int * 2) %>%
+ ds |>
+ filter(int == 4) |>
+ mutate(twice = int * 2) |>
write_dataset(dst_dir3, format = "feather")
new_ds <- open_dataset(dst_dir3, format = "feather")
expect_equal(
- new_ds %>% select(c(names(df1), "twice")) %>% collect(),
- df1 %>% filter(int == 4) %>% mutate(twice = int * 2)
+ new_ds |> select(c(names(df1), "twice")) |> collect(),
+ df1 |> filter(int == 4) |> mutate(twice = int * 2)
)
# head
dst_dir4 <- tempfile()
- ds %>%
- mutate(twice = int * 2) %>%
- arrange(int) %>%
- head(3) %>%
+ ds |>
+ mutate(twice = int * 2) |>
+ arrange(int) |>
+ head(3) |>
write_dataset(dst_dir4, format = "feather")
new_ds <- open_dataset(dst_dir4, format = "feather")
expect_equal(
- new_ds %>%
- select(c(names(df1), "twice")) %>%
+ new_ds |>
+ select(c(names(df1), "twice")) |>
collect(),
- df1 %>%
- mutate(twice = int * 2) %>%
+ df1 |>
+ mutate(twice = int * 2) |>
head(3)
)
})
@@ -334,13 +334,13 @@ test_that("Dataset writing: partition on null", {
ds_readback <- open_dataset(dst_dir, partitioning = hive_partition(lgl = boolean(), null_fallback = "xyz"))
expect_identical(
- ds %>%
- select(int, lgl) %>%
- collect() %>%
+ ds |>
+ select(int, lgl) |>
+ collect() |>
arrange(lgl, int),
- ds_readback %>%
- select(int, lgl) %>%
- collect() %>%
+ ds_readback |>
+ select(int, lgl) |>
+ collect() |>
arrange(lgl, int)
)
})
@@ -348,8 +348,8 @@ test_that("Dataset writing: partition on null", {
test_that("Dataset writing: from data.frame", {
dst_dir <- tempfile()
stacked <- rbind(df1, df2)
- stacked %>%
- group_by(int) %>%
+ stacked |>
+ group_by(int) |>
write_dataset(dst_dir, format = "feather")
expect_true(dir.exists(dst_dir))
expect_identical(dir(dst_dir), sort(paste("int", c(1:10, 101:110), sep = "=")))
@@ -357,14 +357,14 @@ test_that("Dataset writing: from data.frame", {
new_ds <- open_dataset(dst_dir, format = "feather")
expect_equal(
- new_ds %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6 & integer < 11) %>%
- collect() %>%
+ new_ds |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6 & integer < 11) |>
+ collect() |>
summarize(mean = mean(integer)),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
@@ -372,9 +372,9 @@ test_that("Dataset writing: from data.frame", {
test_that("Dataset writing: from RecordBatch", {
dst_dir <- tempfile()
stacked <- record_batch(rbind(df1, df2))
- stacked %>%
- mutate(twice = int * 2) %>%
- group_by(int) %>%
+ stacked |>
+ mutate(twice = int * 2) |>
+ group_by(int) |>
write_dataset(dst_dir, format = "feather")
expect_true(dir.exists(dst_dir))
expect_identical(dir(dst_dir), sort(paste("int", c(1:10, 101:110), sep = "=")))
@@ -382,14 +382,14 @@ test_that("Dataset writing: from RecordBatch", {
new_ds <- open_dataset(dst_dir, format = "feather")
expect_equal(
- new_ds %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6 & integer < 11) %>%
- collect() %>%
+ new_ds |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6 & integer < 11) |>
+ collect() |>
summarize(mean = mean(integer)),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
@@ -408,14 +408,14 @@ test_that("Writing a dataset: Ipc format options & compression", {
new_ds <- open_dataset(dst_dir, format = "feather")
expect_equal(
- new_ds %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6 & integer < 11) %>%
- collect() %>%
+ new_ds |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6 & integer < 11) |>
+ collect() |>
summarize(mean = mean(integer)),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
@@ -453,14 +453,14 @@ test_that("Writing a dataset: Parquet format options", {
new_ds <- open_dataset(dst_dir)
expect_equal(
- new_ds %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6 & integer < 11) %>%
- collect() %>%
+ new_ds |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6 & integer < 11) |>
+ collect() |>
summarize(mean = mean(integer)),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
})
@@ -477,7 +477,7 @@ test_that("Writing a dataset: CSV format options", {
write_dataset(df, dst_dir, format = "csv")
expect_true(dir.exists(dst_dir))
new_ds <- open_dataset(dst_dir, format = "csv")
- expect_equal(new_ds %>% collect(), df)
+ expect_equal(new_ds |> collect(), df)
dst_dir <- make_temp_dir()
write_dataset(df, dst_dir, format = "csv", include_header = FALSE)
@@ -486,7 +486,7 @@ test_that("Writing a dataset: CSV format options", {
format = "csv",
column_names = c("int", "dbl", "lgl", "chr")
)
- expect_equal(new_ds %>% collect(), df)
+ expect_equal(new_ds |> collect(), df)
})
test_that("Dataset writing: unsupported features/input validation", {
@@ -739,9 +739,9 @@ test_that("Dataset min_rows_per_group", {
ds <- open_dataset(dst_dir)
- row_group_sizes <- ds %>%
- map_batches(~ record_batch(nrows = .$num_rows)) %>%
- pull(nrows) %>%
+ row_group_sizes <- ds |>
+ map_batches(~ record_batch(nrows = .$num_rows)) |>
+ pull(nrows) |>
as.vector()
index <- 1
@@ -780,10 +780,10 @@ test_that("Dataset write max rows per group", {
# writes only to a single file with multiple groups
file_path <- paste(dst_dir, written_files[[1]], sep = "/")
ds <- open_dataset(file_path)
- row_group_sizes <- ds %>%
- map_batches(~ record_batch(nrows = .$num_rows)) %>%
- pull(nrows) %>%
- as.vector() %>%
+ row_group_sizes <- ds |>
+ map_batches(~ record_batch(nrows = .$num_rows)) |>
+ pull(nrows) |>
+ as.vector() |>
sort()
expect_equal(row_group_sizes, c(12, 18))
@@ -825,19 +825,19 @@ test_that("Writing a dataset to text files with wrapper functions.", {
write_delim_dataset(df, dst_dir)
expect_true(dir.exists(dst_dir))
new_ds <- open_dataset(dst_dir, format = "text")
- expect_equal(new_ds %>% collect(), df)
+ expect_equal(new_ds |> collect(), df)
dst_dir <- make_temp_dir()
write_csv_dataset(df, dst_dir)
expect_true(dir.exists(dst_dir))
new_ds <- open_dataset(dst_dir, format = "csv")
- expect_equal(new_ds %>% collect(), df)
+ expect_equal(new_ds |> collect(), df)
dst_dir <- make_temp_dir()
write_tsv_dataset(df, dst_dir)
expect_true(dir.exists(dst_dir))
new_ds <- open_dataset(dst_dir, format = "tsv")
- expect_equal(new_ds %>% collect(), df)
+ expect_equal(new_ds |> collect(), df)
})
test_that("Writing a flat file dataset: `basename_template` default behavior", {
@@ -945,7 +945,7 @@ test_that("Dataset can write flat files using readr::write_csv() options.", {
dst_dir <- make_temp_dir()
write_dataset(df, dst_dir, format = "csv", quoting_style = "AllValid")
ds <- open_dataset(dst_dir, format = "csv")
- expect_equal(df, ds %>% collect())
+ expect_equal(df, ds |> collect())
lines <- paste(readLines(paste0(dst_dir, "/part-0.csv")), sep = "\n")
expect_equal(lines[2], "\"1\",\"1\",\"true\",\"a\"")
@@ -995,7 +995,7 @@ test_that("Dataset write wrappers can write flat files using readr::write_csv()
dst_dir <- make_temp_dir()
write_csv_dataset(df, dst_dir, quote = "all", delim = ";")
ds <- open_dataset(dst_dir, format = "csv", delim = ";")
- expect_equal(df, ds %>% collect())
+ expect_equal(df, ds |> collect())
lines <- paste(readLines(paste0(dst_dir, "/part-0.csv")), sep = "\n")
expect_equal(lines[2], "\"1\";\"1\";\"true\";\"a\"")
@@ -1003,13 +1003,13 @@ test_that("Dataset write wrappers can write flat files using readr::write_csv()
dst_dir <- make_temp_dir()
write_tsv_dataset(df, dst_dir, quote = "all", eol = "\r\n")
ds <- open_dataset(dst_dir, format = "tsv")
- expect_equal(df, ds %>% collect())
+ expect_equal(df, ds |> collect())
lines <- paste(readLines(paste0(dst_dir, "/part-0.tsv")), sep = "\n")
expect_equal(lines[2], "\"1\"\t\"1\"\t\"true\"\t\"a\"")
dst_dir <- make_temp_dir()
write_tsv_dataset(df, dst_dir, na = "NOVALUE")
- ds <- open_dataset(dst_dir, format = "tsv") %>% collect()
+ ds <- open_dataset(dst_dir, format = "tsv") |> collect()
expect_equal(
ds$lgl,
diff --git a/r/tests/testthat/test-dataset.R b/r/tests/testthat/test-dataset.R
index 3f9b08221c..5981a5ea22 100644
--- a/r/tests/testthat/test-dataset.R
+++ b/r/tests/testthat/test-dataset.R
@@ -54,20 +54,20 @@ test_that("IPC/Feather format data", {
expect_identical(dim(ds), c(20L, 7L))
expect_equal(
- ds %>%
- select(string = chr, integer = int, part) %>%
- filter(integer > 6 & part == 3) %>%
- collect() %>%
+ ds |>
+ select(string = chr, integer = int, part) |>
+ filter(integer > 6 & part == 3) |>
+ collect() |>
summarize(mean = mean(integer)),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
# Collecting virtual partition column works
expect_equal(
- ds %>% arrange(part) %>% pull(part) %>% as.vector(),
+ ds |> arrange(part) |> pull(part) |> as.vector(),
c(rep(3, 10), rep(4, 10))
)
})
@@ -132,11 +132,11 @@ test_that("URI-decoding with directory partitioning", {
ds <- factory$Finish(schm)
# Can't directly inspect partition expressions, so do it implicitly via scan
expect_equal(
- ds %>%
- filter(date == "2021-05-04 00:00:00", string == "$") %>%
- select(int) %>%
+ ds |>
+ filter(date == "2021-05-04 00:00:00", string == "$") |>
+ select(int) |>
collect(),
- df1 %>% select(int) %>% collect()
+ df1 |> select(int) |> collect()
)
partitioning_factory <- DirectoryPartitioningFactory$create(
@@ -149,11 +149,11 @@ test_that("URI-decoding with directory partitioning", {
schm <- factory$Inspect()
ds <- factory$Finish(schm)
expect_equal(
- ds %>%
- filter(date == "2021-05-04 00%3A00%3A00", string == "%24") %>%
- select(int) %>%
+ ds |>
+ filter(date == "2021-05-04 00%3A00%3A00", string == "%24") |>
+ select(int) |>
collect(),
- df1 %>% select(int) %>% collect()
+ df1 |> select(int) |> collect()
)
})
@@ -194,11 +194,11 @@ test_that("URI-decoding with hive partitioning", {
ds <- factory$Finish(schm)
# Can't directly inspect partition expressions, so do it implicitly via scan
expect_equal(
- ds %>%
- filter(date == "2021-05-04 00:00:00", string == "$") %>%
- select(int) %>%
+ ds |>
+ filter(date == "2021-05-04 00:00:00", string == "$") |>
+ select(int) |>
collect(),
- df1 %>% select(int) %>% collect()
+ df1 |> select(int) |> collect()
)
partitioning_factory <- hive_partition(segment_encoding = "none")
@@ -208,11 +208,11 @@ test_that("URI-decoding with hive partitioning", {
schm <- factory$Inspect()
ds <- factory$Finish(schm)
expect_equal(
- ds %>%
- filter(date == "2021-05-04 00%3A00%3A00", string == "%24") %>%
- select(int) %>%
+ ds |>
+ filter(date == "2021-05-04 00%3A00%3A00", string == "%24") |>
+ select(int) |>
collect(),
- df1 %>% select(int) %>% collect()
+ df1 |> select(int) |> collect()
)
})
@@ -244,11 +244,11 @@ test_that("URI-decoding with hive partitioning with key encoded", {
schm <- factory$Inspect()
ds <- factory$Finish(schm)
expect_equal(
- ds %>%
- filter(`test key` == "2021-05-04 00:00:00", `test key1` == "$") %>%
- select(int) %>%
+ ds |>
+ filter(`test key` == "2021-05-04 00:00:00", `test key1` == "$") |>
+ select(int) |>
collect(),
- df1 %>% select(int) %>% collect()
+ df1 |> select(int) |> collect()
)
# no segment encoding
@@ -259,11 +259,11 @@ test_that("URI-decoding with hive partitioning with key encoded", {
schm <- factory$Inspect()
ds <- factory$Finish(schm)
expect_equal(
- ds %>%
- filter(`test%20key` == "2021-05-04 00%3A00%3A00", `test%20key1` == "%24") %>%
- select(int) %>%
+ ds |>
+ filter(`test%20key` == "2021-05-04 00%3A00%3A00", `test%20key1` == "%24") |>
+ select(int) |>
collect(),
- df1 %>% select(int) %>% collect()
+ df1 |> select(int) |> collect()
)
})
@@ -281,10 +281,10 @@ test_that("Simple interface for datasets", {
expect_r6_class(ds$filesystem, "LocalFileSystem")
expect_r6_class(ds, "Dataset")
expect_equal(
- ds %>%
- select(chr, dbl) %>%
- filter(dbl > 7 & dbl < 53L) %>% # Testing the auto-casting of scalars
- collect() %>%
+ ds |>
+ select(chr, dbl) |>
+ filter(dbl > 7 & dbl < 53L) |> # Testing the auto-casting of scalars
+ collect() |>
arrange(dbl),
rbind(
df1[8:10, c("chr", "dbl")],
@@ -293,20 +293,20 @@ test_that("Simple interface for datasets", {
)
expect_equal(
- ds %>%
- select(string = chr, integer = int, part) %>%
- filter(integer > 6 & part == 1) %>% # 6 not 6L to test autocasting
- collect() %>%
+ ds |>
+ select(string = chr, integer = int, part) |>
+ filter(integer > 6 & part == 1) |> # 6 not 6L to test autocasting
+ collect() |>
summarize(mean = mean(integer)),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
# Collecting virtual partition column works
expect_equal(
- ds %>% arrange(part) %>% pull(part) %>% as.vector(),
+ ds |> arrange(part) |> pull(part) |> as.vector(),
c(rep(1, 10), rep(2, 10))
)
})
@@ -345,21 +345,21 @@ test_that("dim() correctly determine numbers of rows and columns on arrow_dplyr_
ds <- open_dataset(dataset_dir, partitioning = schema(part = uint8()))
expect_identical(
- ds %>%
- filter(chr == "a") %>%
+ ds |>
+ filter(chr == "a") |>
dim(),
c(2L, 7L)
)
expect_equal(
- ds %>%
- select(chr, fct, int) %>%
+ ds |>
+ select(chr, fct, int) |>
dim(),
c(20L, 3L)
)
expect_identical(
- ds %>%
- select(chr, fct, int) %>%
- filter(chr == "a") %>%
+ ds |>
+ select(chr, fct, int) |>
+ filter(chr == "a") |>
dim(),
c(2L, 3L)
)
@@ -377,11 +377,11 @@ test_that("Hive partitioning", {
ds <- open_dataset(hive_dir, partitioning = hive_partition(other = utf8(), group = uint8()))
expect_r6_class(ds, "Dataset")
expect_equal(
- ds %>%
- filter(group == 2) %>%
- select(chr, dbl) %>%
- filter(dbl > 7 & dbl < 53) %>%
- collect() %>%
+ ds |>
+ filter(group == 2) |>
+ select(chr, dbl) |>
+ filter(dbl > 7 & dbl < 53) |>
+ collect() |>
arrange(dbl),
df2[1:2, c("chr", "dbl")]
)
@@ -398,25 +398,25 @@ test_that("Partitioning inference", {
ds1 <- open_dataset(dataset_dir, partitioning = "part")
expect_named(ds1, c(names(df1), "part"))
expect_equal(
- ds1 %>%
- select(string = chr, integer = int, part) %>%
- filter(integer > 6 & part == 1) %>%
- collect() %>%
+ ds1 |>
+ select(string = chr, integer = int, part) |>
+ filter(integer > 6 & part == 1) |>
+ collect() |>
summarize(mean = mean(integer)),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
summarize(mean = mean(integer))
)
ds2 <- open_dataset(hive_dir)
expect_named(ds2, c(names(df1), "group", "other"))
expect_equal(
- ds2 %>%
- filter(group == 2) %>%
- select(chr, dbl) %>%
- filter(dbl > 7 & dbl < 53) %>%
- collect() %>%
+ ds2 |>
+ filter(group == 2) |>
+ select(chr, dbl) |>
+ filter(dbl > 7 & dbl < 53) |>
+ collect() |>
arrange(dbl),
df2[1:2, c("chr", "dbl")]
)
@@ -522,13 +522,13 @@ test_that("Dataset with multiple file formats", {
))
expect_named(ds, c(names(df1), "part"))
expect_equal(
- ds %>%
- filter(int > 6 & part %in% c(1, 3)) %>%
- select(string = chr, integer = int) %>%
+ ds |>
+ filter(int > 6 & part %in% c(1, 3)) |>
+ select(string = chr, integer = int) |>
collect(),
- df1 %>%
- select(string = chr, integer = int) %>%
- filter(integer > 6) %>%
+ df1 |>
+ select(string = chr, integer = int) |>
+ filter(integer > 6) |>
rbind(., .) # Stack it twice
)
})
@@ -539,10 +539,10 @@ test_that("Creating UnionDataset", {
union1 <- open_dataset(list(ds1, ds2))
expect_r6_class(union1, "UnionDataset")
expect_equal(
- union1 %>%
- select(chr, dbl) %>%
- filter(dbl > 7 & dbl < 53L) %>% # Testing the auto-casting of scalars
- collect() %>%
+ union1 |>
+ select(chr, dbl) |>
+ filter(dbl > 7 & dbl < 53L) |> # Testing the auto-casting of scalars
+ collect() |>
arrange(dbl),
rbind(
df1[8:10, c("chr", "dbl")],
@@ -554,10 +554,10 @@ test_that("Creating UnionDataset", {
union2 <- c(ds1, ds2)
expect_r6_class(union2, "UnionDataset")
expect_equal(
- union2 %>%
- select(chr, dbl) %>%
- filter(dbl > 7 & dbl < 53L) %>% # Testing the auto-casting of scalars
- collect() %>%
+ union2 |>
+ select(chr, dbl) |>
+ filter(dbl > 7 & dbl < 53L) |> # Testing the auto-casting of scalars
+ collect() |>
arrange(dbl),
rbind(
df1[8:10, c("chr", "dbl")],
@@ -588,8 +588,8 @@ test_that("UnionDataset can merge schemas", {
ds2 <- open_dataset(path2, format = "parquet")
ds <- c(ds1, ds2)
- actual <- ds %>%
- collect() %>%
+ actual <- ds |>
+ collect() |>
arrange(x)
expect_equal(colnames(actual), c("x", "y", "z"))
@@ -609,10 +609,10 @@ test_that("UnionDataset can merge schemas", {
ds <- open_dataset(list(ds1, ds2), unify_schemas = FALSE)
expected <- union_all_common(
as_tibble(sub_df1),
- as_tibble(sub_df2) %>% select(x)
+ as_tibble(sub_df2) |> select(x)
)
- actual <- ds %>%
- collect() %>%
+ actual <- ds |>
+ collect() |>
arrange(x)
expect_equal(colnames(actual), c("x", "y"))
expect_equal(actual, expected)
@@ -631,8 +631,8 @@ test_that("UnionDataset handles InMemoryDatasets", {
ds1 <- InMemoryDataset$create(sub_df1)
ds2 <- InMemoryDataset$create(sub_df2)
ds <- c(ds1, ds2)
- actual <- ds %>%
- arrange(x) %>%
+ actual <- ds |>
+ arrange(x) |>
compute()
expected <- concat_tables(sub_df1, sub_df2)
expect_equal(actual, expected)
@@ -643,16 +643,16 @@ test_that("scalar aggregates with many batches (ARROW-16904)", {
write_parquet(data.frame(x = 1:100), tf, chunk_size = 20)
ds <- open_dataset(tf)
- replicate(100, ds %>% summarize(min(x)) %>% pull())
+ replicate(100, ds |> summarize(min(x)) |> pull())
expect_true(
all(
- replicate(100, ds %>% summarize(min(x)) %>% pull() %>% as.vector()) == 1
+ replicate(100, ds |> summarize(min(x)) |> pull() |> as.vector()) == 1
)
)
expect_true(
all(
- replicate(100, ds %>% summarize(max(x)) %>% pull() %>% as.vector()) == 100
+ replicate(100, ds |> summarize(max(x)) |> pull() |> as.vector()) == 100
)
)
})
@@ -664,57 +664,57 @@ test_that("streaming map_batches into an ExecPlan", {
# summarize returns arrow_dplyr_query, which gets collected into a tibble
expect_equal(
- ds %>%
- filter(int > 5) %>%
- select(int, lgl) %>%
- map_batches(~ summarize(., min_int = min(int))) %>%
- arrange(min_int) %>%
+ ds |>
+ filter(int > 5) |>
+ select(int, lgl) |>
+ map_batches(~ summarize(., min_int = min(int))) |>
+ arrange(min_int) |>
collect(),
tibble(min_int = c(6L, 101L))
)
# $num_rows returns integer vector, so we need to wrap it in a RecordBatch
expect_equal(
- ds %>%
- filter(int > 5) %>%
- select(int, lgl) %>%
- map_batches(~ record_batch(nrows = .$num_rows)) %>%
- pull(nrows) %>%
- as.vector() %>%
+ ds |>
+ filter(int > 5) |>
+ select(int, lgl) |>
+ map_batches(~ record_batch(nrows = .$num_rows)) |>
+ pull(nrows) |>
+ as.vector() |>
sort(),
c(5, 10)
)
# Can take a raw dataset as X argument
expect_equal(
- ds %>%
- map_batches(~ count(., part)) %>%
- arrange(part) %>%
+ ds |>
+ map_batches(~ count(., part)) |>
+ arrange(part) |>
collect(),
tibble(part = c(1, 2), n = c(10, 10))
)
# $Take returns RecordBatch
expect_equal(
- ds %>%
- filter(int > 5) %>%
- select(int, lgl) %>%
- map_batches(~ .$Take(0)) %>%
- arrange(int) %>%
+ ds |>
+ filter(int > 5) |>
+ select(int, lgl) |>
+ map_batches(~ .$Take(0)) |>
+ arrange(int) |>
collect(),
tibble(int = c(6, 101), lgl = c(TRUE, TRUE))
)
# Do things in R and put back into Arrow
expect_equal(
- ds %>%
- filter(int < 5) %>%
- select(int) %>%
+ ds |>
+ filter(int < 5) |>
+ select(int) |>
map_batches(
- # as_mapper() can't handle %>%?
+ # as_mapper() can't handle |>?
~ mutate(as.data.frame(.), lets = letters[int])
- ) %>%
- arrange(int) %>%
+ ) |>
+ arrange(int) |>
collect(),
tibble(int = 1:4, lets = letters[1:4])
)
@@ -842,8 +842,8 @@ test_that("unique()", {
expect_s3_class(unique(rbr), "arrow_dplyr_query")
# on a arrow_dplyr_query
- adq_eg <- ds %>%
- select(fct) %>%
+ adq_eg <- ds |>
+ select(fct) |>
unique()
expect_s3_class(adq_eg, "arrow_dplyr_query")
@@ -852,14 +852,14 @@ test_that("unique()", {
# on a arrow table
expect_equal(
- at %>%
- unique() %>%
+ at |>
+ unique() |>
collect(),
unique(in_r_mem)
)
expect_equal(
- rbr %>%
- unique() %>%
+ rbr |>
+ unique() |>
collect(),
unique(in_r_mem)
)
@@ -892,8 +892,8 @@ test_that("Dataset [ (take by index)", {
)
# Take from a query
- ds2 <- ds %>%
- filter(int > 6) %>%
+ ds2 <- ds |>
+ filter(int > 6) |>
select(int, lgl)
expect_equal_data_frame(
ds2[c(2, 5), ],
@@ -943,7 +943,7 @@ test_that("Dataset and query print methods", {
fixed = TRUE
)
expect_output(
- print(q %>% filter(integer == 6) %>% group_by(lgl)),
+ print(q |> filter(integer == 6) |> group_by(lgl)),
paste(
"Dataset (query)",
"string: string",
@@ -968,15 +968,15 @@ test_that("Can delete filesystem dataset files after collection", {
write_dataset(ds0, dataset_dir2)
ds <- open_dataset(dataset_dir2)
- collected <- ds %>%
- arrange(int) %>%
+ collected <- ds |>
+ arrange(int) |>
collect()
unlink(dataset_dir2, recursive = TRUE)
expect_false(dir.exists(dataset_dir2))
expect_identical(
collected,
- ds0 %>% arrange(int) %>% collect()
+ ds0 |> arrange(int) |> collect()
)
# Also try with head(), since this creates a nested query whose interior
@@ -984,17 +984,17 @@ test_that("Can delete filesystem dataset files after collection", {
# dataset
write_dataset(ds0, dataset_dir2)
ds <- open_dataset(dataset_dir2)
- collected <- ds %>%
- arrange(int) %>%
- head() %>%
- arrange(int) %>%
+ collected <- ds |>
+ arrange(int) |>
+ head() |>
+ arrange(int) |>
collect()
unlink(dataset_dir2, recursive = TRUE)
expect_false(dir.exists(dataset_dir2))
expect_identical(
collected,
- ds0 %>% arrange(int) %>% head() %>% arrange(int) %>% collect()
+ ds0 |> arrange(int) |> head() |> arrange(int) |> collect()
)
})
@@ -1011,10 +1011,10 @@ test_that("Scanner$ScanBatches", {
test_that("Scanner$ToRecordBatchReader()", {
ds <- open_dataset(dataset_dir, partitioning = "part")
- scan <- ds %>%
- filter(part == 1) %>%
- select(int, lgl) %>%
- filter(int > 6) %>%
+ scan <- ds |>
+ filter(part == 1) |>
+ select(int, lgl) |>
+ filter(int > 6) |>
Scanner$create()
reader <- scan$ToRecordBatchReader()
expect_r6_class(reader, "RecordBatchReader")
@@ -1028,18 +1028,18 @@ test_that("Scanner$create() filter/projection pushdown", {
ds <- open_dataset(dataset_dir, partitioning = "part")
# the standard to compare all Scanner$create()s against
- scan_one <- ds %>%
- filter(int > 7 & dbl < 57) %>%
- select(int, dbl, lgl) %>%
- mutate(int_plus = int + 1, dbl_minus = dbl - 1) %>%
+ scan_one <- ds |>
+ filter(int > 7 & dbl < 57) |>
+ select(int, dbl, lgl) |>
+ mutate(int_plus = int + 1, dbl_minus = dbl - 1) |>
Scanner$create()
# select a column in projection
- scan_two <- ds %>%
- filter(int > 7 & dbl < 57) %>%
+ scan_two <- ds |>
+ filter(int > 7 & dbl < 57) |>
# select an extra column, since we are going to
- select(int, dbl, lgl, chr) %>%
- mutate(int_plus = int + 1, dbl_minus = dbl - 1) %>%
+ select(int, dbl, lgl, chr) |>
+ mutate(int_plus = int + 1, dbl_minus = dbl - 1) |>
Scanner$create(projection = c("int", "dbl", "lgl", "int_plus", "dbl_minus"))
expect_identical(
as.data.frame(scan_one$ToRecordBatchReader()$read_table()),
@@ -1047,10 +1047,10 @@ test_that("Scanner$create() filter/projection pushdown", {
)
# adding filters to Scanner$create
- scan_three <- ds %>%
- filter(int > 7) %>%
- select(int, dbl, lgl) %>%
- mutate(int_plus = int + 1, dbl_minus = dbl - 1) %>%
+ scan_three <- ds |>
+ filter(int > 7) |>
+ select(int, dbl, lgl) |>
+ mutate(int_plus = int + 1, dbl_minus = dbl - 1) |>
Scanner$create(
filter = Expression$create("less", Expression$field_ref("dbl"), Expression$scalar(57))
)
@@ -1060,8 +1060,8 @@ test_that("Scanner$create() filter/projection pushdown", {
)
expect_error(
- ds %>%
- select(int, dbl, lgl) %>%
+ ds |>
+ select(int, dbl, lgl) |>
Scanner$create(projection = "not_a_col"),
# Full message is "attempting to project with unknown columns" >= 4.0.0, but
# prior versions have a less nice "all(projection %in% names(proj)) is not TRUE"
@@ -1069,8 +1069,8 @@ test_that("Scanner$create() filter/projection pushdown", {
)
expect_error(
- ds %>%
- select(int, dbl, lgl) %>%
+ ds |>
+ select(int, dbl, lgl) |>
Scanner$create(filter = list("foo", "bar")),
"filter expressions must be either an expression or a list of expressions"
)
@@ -1136,7 +1136,7 @@ test_that("Collecting zero columns from a dataset doesn't return entire dataset"
tmp <- tempfile()
write_dataset(mtcars, tmp, format = "parquet")
expect_equal(
- open_dataset(tmp) %>% select() %>% collect() %>% dim(),
+ open_dataset(tmp) |> select() |> collect() |> dim(),
c(32, 0)
)
})
@@ -1151,15 +1151,15 @@ test_that("dataset RecordBatchReader to C-interface to arrow_dplyr_query", {
reader$export_to_c(stream_ptr)
expect_equal(
- RecordBatchStreamReader$import_from_c(stream_ptr) %>%
- filter(int < 8 | int > 55) %>%
- mutate(part_plus = group + 6) %>%
- arrange(dbl) %>%
+ RecordBatchStreamReader$import_from_c(stream_ptr) |>
+ filter(int < 8 | int > 55) |>
+ mutate(part_plus = group + 6) |>
+ arrange(dbl) |>
collect(),
- ds %>%
- filter(int < 8 | int > 55) %>%
- mutate(part_plus = group + 6) %>%
- arrange(dbl) %>%
+ ds |>
+ filter(int < 8 | int > 55) |>
+ mutate(part_plus = group + 6) |>
+ arrange(dbl) |>
collect()
)
@@ -1171,7 +1171,7 @@ test_that("dataset to C-interface to arrow_dplyr_query with proj/filter", {
ds <- open_dataset(hive_dir)
# filter the dataset
- ds <- ds %>%
+ ds <- ds |>
filter(int > 2)
# export the RecordBatchReader via the C-interface
@@ -1191,14 +1191,14 @@ test_that("dataset to C-interface to arrow_dplyr_query with proj/filter", {
reader_adq <- arrow_dplyr_query(circle)
expect_equal(
- reader_adq %>%
- mutate(part_plus = group + 6) %>%
- arrange(dbl) %>%
+ reader_adq |>
+ mutate(part_plus = group + 6) |>
+ arrange(dbl) |>
collect(),
- ds %>%
- filter(int < 8, int > 2) %>%
- mutate(part_plus = group + 6) %>%
- arrange(dbl) %>%
+ ds |>
+ filter(int < 8, int > 2) |>
+ mutate(part_plus = group + 6) |>
+ arrange(dbl) |>
collect()
)
@@ -1214,20 +1214,20 @@ test_that("Filter parquet dataset with is.na ARROW-15312", {
# OK: Collect then filter: returns row 3, as expected
expect_identical(
- open_dataset(ds_path) %>% collect() %>% filter(is.na(y)),
- df %>% collect() %>% filter(is.na(y))
+ open_dataset(ds_path) |> collect() |> filter(is.na(y)),
+ df |> collect() |> filter(is.na(y))
)
# Before the fix: Filter then collect on y returned a 0-row tibble
expect_identical(
- open_dataset(ds_path) %>% filter(is.na(y)) %>% collect(),
- df %>% filter(is.na(y)) %>% collect()
+ open_dataset(ds_path) |> filter(is.na(y)) |> collect(),
+ df |> filter(is.na(y)) |> collect()
)
# OK: Filter then collect (on z) returns row 3, as expected
expect_identical(
- open_dataset(ds_path) %>% filter(is.na(z)) %>% collect(),
- df %>% filter(is.na(z)) %>% collect()
+ open_dataset(ds_path) |> filter(is.na(z)) |> collect(),
+ df |> filter(is.na(z)) |> collect()
)
})
@@ -1243,9 +1243,9 @@ test_that("FileSystemFactoryOptions with DirectoryPartitioning", {
factory_options = list(partition_base_dir = ds_path)
)
expect_equal(
- ds %>%
- arrange(cyl) %>%
- pull(cyl) %>%
+ ds |>
+ arrange(cyl) |>
+ pull(cyl) |>
as.vector(),
sort(mtcars$cyl)
)
@@ -1262,9 +1262,9 @@ test_that("FileSystemFactoryOptions with DirectoryPartitioning", {
)
)
expect_equal(
- ds %>%
- arrange(cyl) %>%
- pull(cyl) %>%
+ ds |>
+ arrange(cyl) |>
+ pull(cyl) |>
as.vector(),
sort(mtcars$cyl)
)
@@ -1279,9 +1279,9 @@ test_that("FileSystemFactoryOptions with DirectoryPartitioning", {
)
)
expect_equal(
- ds %>%
- arrange(cyl) %>%
- pull(cyl) %>%
+ ds |>
+ arrange(cyl) |>
+ pull(cyl) |>
as.vector(),
sort(mtcars$cyl)
)
@@ -1298,9 +1298,9 @@ test_that("FileSystemFactoryOptions with DirectoryPartitioning", {
)
)
expect_equal(
- ds %>%
- arrange(cyl) %>%
- pull(cyl) %>%
+ ds |>
+ arrange(cyl) |>
+ pull(cyl) |>
as.vector(),
sort(mtcars$cyl)
)
@@ -1313,11 +1313,11 @@ test_that("FileSystemFactoryOptions with DirectoryPartitioning", {
)
)
expect_equal(
- ds %>%
- summarize(sum(gear)) %>%
- collect() %>%
+ ds |>
+ summarize(sum(gear)) |>
+ collect() |>
as.data.frame(),
- mtcars %>%
+ mtcars |>
summarize(sum(gear))
)
})
@@ -1333,9 +1333,9 @@ test_that("FileSystemFactoryOptions with HivePartitioning", {
# With Hive partitioning, partition_base_dir isn't needed
expect_setequal(names(ds), names(mtcars))
expect_equal(
- ds %>%
- arrange(cyl) %>%
- pull(cyl) %>%
+ ds |>
+ arrange(cyl) |>
+ pull(cyl) |>
as.vector(),
sort(mtcars$cyl)
)
@@ -1350,9 +1350,9 @@ test_that("FileSystemFactoryOptions with HivePartitioning", {
)
)
expect_equal(
- ds %>%
- arrange(cyl) %>%
- pull(cyl) %>%
+ ds |>
+ arrange(cyl) |>
+ pull(cyl) |>
as.vector(),
sort(mtcars$cyl)
)
@@ -1365,9 +1365,9 @@ test_that("FileSystemFactoryOptions with HivePartitioning", {
)
)
expect_equal(
- ds %>%
- arrange(cyl) %>%
- pull(cyl) %>%
+ ds |>
+ arrange(cyl) |>
+ pull(cyl) |>
as.vector(),
sort(mtcars$cyl)
)
@@ -1382,9 +1382,9 @@ test_that("FileSystemFactoryOptions with HivePartitioning", {
)
)
expect_equal(
- ds %>%
- arrange(cyl) %>%
- pull(cyl) %>%
+ ds |>
+ arrange(cyl) |>
+ pull(cyl) |>
as.vector(),
sort(mtcars$cyl)
)
@@ -1435,8 +1435,8 @@ test_that("FileSystemFactoryOptions input validation", {
test_that("can add in augmented fields", {
ds <- open_dataset(hive_dir)
- observed <- ds %>%
- mutate(file_name = add_filename()) %>%
+ observed <- ds |>
+ mutate(file_name = add_filename()) |>
collect()
expect_named(
@@ -1458,8 +1458,8 @@ test_that("can add in augmented fields", {
# errors appropriately with ArrowTabular objects
expect_error(
- arrow_table(mtcars) %>%
- mutate(file = add_filename()) %>%
+ arrow_table(mtcars) |>
+ mutate(file = add_filename()) |>
collect(),
regexp = error_regex,
fixed = TRUE
@@ -1467,9 +1467,9 @@ test_that("can add in augmented fields", {
# errors appropriately with aggregation
expect_error(
- ds %>%
- summarise(max_int = max(int)) %>%
- mutate(file_name = add_filename()) %>%
+ ds |>
+ summarise(max_int = max(int)) |>
+ mutate(file_name = add_filename()) |>
collect(),
regexp = error_regex,
fixed = TRUE
@@ -1478,9 +1478,9 @@ test_that("can add in augmented fields", {
# joins to tables
another_table <- select(example_data, int, dbl2)
expect_error(
- ds %>%
- left_join(another_table, by = "int") %>%
- mutate(file = add_filename()) %>%
+ ds |>
+ left_join(another_table, by = "int") |>
+ mutate(file = add_filename()) |>
collect(),
regexp = error_regex,
fixed = TRUE
@@ -1492,18 +1492,18 @@ test_that("can add in augmented fields", {
another_dataset <- write_dataset(another_table, another_dataset_dir)
expect_error(
- ds %>%
- left_join(open_dataset(another_dataset_dir), by = "int") %>%
- mutate(file = add_filename()) %>%
+ ds |>
+ left_join(open_dataset(another_dataset_dir), by = "int") |>
+ mutate(file = add_filename()) |>
collect(),
regexp = error_regex,
fixed = TRUE
)
# this hits the implicit_schema path by joining afterwards
- join_after <- ds %>%
- mutate(file = add_filename()) %>%
- left_join(open_dataset(another_dataset_dir), by = "int") %>%
+ join_after <- ds |>
+ mutate(file = add_filename()) |>
+ left_join(open_dataset(another_dataset_dir), by = "int") |>
collect()
expect_named(
@@ -1517,10 +1517,10 @@ test_that("can add in augmented fields", {
)
# another test on the explicit_schema path
- summarise_after <- ds %>%
- mutate(file = add_filename()) %>%
- group_by(file) %>%
- summarise(max_int = max(int)) %>%
+ summarise_after <- ds |>
+ mutate(file = add_filename()) |>
+ group_by(file) |>
+ summarise(max_int = max(int)) |>
collect()
expect_equal(
diff --git a/r/tests/testthat/test-dplyr-across.R b/r/tests/testthat/test-dplyr-across.R
index 5396dcbe79..707660cdd9 100644
--- a/r/tests/testthat/test-dplyr-across.R
+++ b/r/tests/testthat/test-dplyr-across.R
@@ -102,7 +102,7 @@ test_that("expand_across correctly expands quosures", {
dbl = round(dbl),
dbl2 = round(dbl2)
),
- example_data %>% select(int, dbl, dbl2)
+ example_data |> select(int, dbl, dbl2)
)
# column selection via dynamic variable name
@@ -227,7 +227,7 @@ test_that("expand_across correctly expands quosures", {
# ellipses (...) are a deprecated argument
# abandon_ship message offers multiple suggestions
expect_snapshot(
- InMemoryDataset$create(example_data) %>%
+ InMemoryDataset$create(example_data) |>
mutate(across(c(dbl, dbl2), round, digits = -1)),
error = TRUE
)
@@ -279,8 +279,8 @@ test_that("purrr-style lambda functions are supported", {
test_that("ARROW-14071 - R functions from a user's environment", {
makeWhole <- function(x) round(x, digits = 0)
compare_dplyr_binding(
- .input %>%
- mutate(across(c(int, dbl), makeWhole)) %>%
+ .input |>
+ mutate(across(c(int, dbl), makeWhole)) |>
collect(),
example_data
)
diff --git a/r/tests/testthat/test-dplyr-arrange.R b/r/tests/testthat/test-dplyr-arrange.R
index 85c71fb7c9..c0e2b859c1 100644
--- a/r/tests/testthat/test-dplyr-arrange.R
+++ b/r/tests/testthat/test-dplyr-arrange.R
@@ -24,138 +24,138 @@ tbl <- slice_sample(example_data_for_sorting, prop = 1L)
test_that("arrange() on integer, double, and character columns", {
compare_dplyr_binding(
- .input %>%
- arrange(int, chr) %>%
+ .input |>
+ arrange(int, chr) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- arrange(int, desc(dbl)) %>%
+ .input |>
+ arrange(int, desc(dbl)) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- arrange(int, dplyr::desc(dbl)) %>%
+ .input |>
+ arrange(int, dplyr::desc(dbl)) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- arrange(int, desc(desc(dbl))) %>%
+ .input |>
+ arrange(int, desc(desc(dbl))) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- arrange(int, dplyr::desc(dplyr::desc(dbl))) %>%
+ .input |>
+ arrange(int, dplyr::desc(dplyr::desc(dbl))) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- arrange(int) %>%
- arrange(desc(dbl)) %>%
+ .input |>
+ arrange(int) |>
+ arrange(desc(dbl)) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- arrange(int) %>%
- arrange(dplyr::desc(dbl)) %>%
+ .input |>
+ arrange(int) |>
+ arrange(dplyr::desc(dbl)) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- arrange(int + dbl, chr) %>%
+ .input |>
+ arrange(int + dbl, chr) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- mutate(zzz = int + dbl, ) %>%
- arrange(zzz, chr) %>%
+ .input |>
+ mutate(zzz = int + dbl, ) |>
+ arrange(zzz, chr) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- mutate(zzz = int + dbl) %>%
- arrange(int + dbl, chr) %>%
+ .input |>
+ mutate(zzz = int + dbl) |>
+ arrange(int + dbl, chr) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- mutate(int + dbl) %>%
- arrange(int + dbl, chr) %>%
+ .input |>
+ mutate(int + dbl) |>
+ arrange(int + dbl, chr) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- group_by(grp) %>%
- arrange(int, dbl) %>%
+ .input |>
+ group_by(grp) |>
+ arrange(int, dbl) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- group_by(grp) %>%
- arrange(int, dbl, .by_group = TRUE) %>%
+ .input |>
+ group_by(grp) |>
+ arrange(int, dbl, .by_group = TRUE) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- group_by(grp, grp2) %>%
- arrange(int, dbl, .by_group = TRUE) %>%
+ .input |>
+ group_by(grp, grp2) |>
+ arrange(int, dbl, .by_group = TRUE) |>
collect(),
- tbl %>%
+ tbl |>
mutate(grp2 = ifelse(is.na(lgl), 1L, as.integer(lgl)))
)
compare_dplyr_binding(
- .input %>%
- group_by(grp) %>%
- arrange(.by_group = TRUE) %>%
- pull(grp) %>%
+ .input |>
+ group_by(grp) |>
+ arrange(.by_group = TRUE) |>
+ pull(grp) |>
as.vector(),
tbl
)
compare_dplyr_binding(
- .input %>%
- arrange() %>%
+ .input |>
+ arrange() |>
collect(),
- tbl %>%
+ tbl |>
group_by(grp)
)
compare_dplyr_binding(
- .input %>%
- group_by(grp) %>%
- arrange() %>%
+ .input |>
+ group_by(grp) |>
+ arrange() |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- arrange() %>%
+ .input |>
+ arrange() |>
collect(),
tbl
)
test_sort_col <- "chr"
compare_dplyr_binding(
- .input %>%
- arrange(!!sym(test_sort_col)) %>%
+ .input |>
+ arrange(!!sym(test_sort_col)) |>
collect(),
- tbl %>%
+ tbl |>
select(chr, lgl)
)
test_sort_cols <- c("int", "dbl")
compare_dplyr_binding(
- .input %>%
- arrange(!!!syms(test_sort_cols)) %>%
+ .input |>
+ arrange(!!!syms(test_sort_cols)) |>
collect(),
tbl
)
@@ -163,24 +163,24 @@ test_that("arrange() on integer, double, and character columns", {
test_that("arrange() on datetime columns", {
compare_dplyr_binding(
- .input %>%
- arrange(dttm, int) %>%
+ .input |>
+ arrange(dttm, int) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- arrange(dttm) %>%
+ .input |>
+ arrange(dttm) |>
collect(),
- tbl %>%
+ tbl |>
select(dttm, grp)
)
})
test_that("arrange() on logical columns", {
compare_dplyr_binding(
- .input %>%
- arrange(lgl, int) %>%
+ .input |>
+ arrange(lgl, int) |>
collect(),
tbl
)
@@ -188,43 +188,43 @@ test_that("arrange() on logical columns", {
test_that("arrange() with bad inputs", {
expect_error(
- tbl %>%
- Table$create() %>%
+ tbl |>
+ Table$create() |>
arrange(1),
"does not contain any field names",
fixed = TRUE
)
expect_error(
- tbl %>%
- Table$create() %>%
+ tbl |>
+ Table$create() |>
arrange(2 + 2),
"does not contain any field names",
fixed = TRUE
)
expect_error(
- tbl %>%
- Table$create() %>%
+ tbl |>
+ Table$create() |>
arrange(aertidjfgjksertyj),
"not found",
fixed = TRUE
)
expect_error(
- tbl %>%
- Table$create() %>%
+ tbl |>
+ Table$create() |>
arrange(desc(aertidjfgjksertyj + iaermxiwerksxsdqq)),
"not found",
fixed = TRUE
)
expect_error(
- tbl %>%
- Table$create() %>%
+ tbl |>
+ Table$create() |>
arrange(desc(int, chr)),
"expects only one argument",
fixed = TRUE
)
expect_error(
- tbl %>%
- Table$create() %>%
+ tbl |>
+ Table$create() |>
arrange(dplyr::desc(int, chr)),
"expects only one argument",
fixed = TRUE
@@ -233,14 +233,14 @@ test_that("arrange() with bad inputs", {
test_that("Can use across() within arrange()", {
compare_dplyr_binding(
- .input %>%
- arrange(across(starts_with("d"))) %>%
+ .input |>
+ arrange(across(starts_with("d"))) |>
collect(),
example_data
)
compare_dplyr_binding(
- .input %>%
- arrange(across(starts_with("d"), desc)) %>%
+ .input |>
+ arrange(across(starts_with("d"), desc)) |>
collect(),
example_data
)
diff --git a/r/tests/testthat/test-dplyr-collapse.R b/r/tests/testthat/test-dplyr-collapse.R
index 51e56278f9..306b22a284 100644
--- a/r/tests/testthat/test-dplyr-collapse.R
+++ b/r/tests/testthat/test-dplyr-collapse.R
@@ -35,8 +35,8 @@ tab <- Table$create(tbl)
test_that("implicit_schema with select", {
expect_equal(
- tab %>%
- select(int, lgl) %>%
+ tab |>
+ select(int, lgl) |>
implicit_schema(),
schema(int = int32(), lgl = bool())
)
@@ -44,8 +44,8 @@ test_that("implicit_schema with select", {
test_that("implicit_schema with rename", {
expect_equal(
- tab %>%
- select(numbers = int, lgl) %>%
+ tab |>
+ select(numbers = int, lgl) |>
implicit_schema(),
schema(numbers = int32(), lgl = bool())
)
@@ -53,11 +53,11 @@ test_that("implicit_schema with rename", {
test_that("implicit_schema with mutate", {
expect_equal(
- tab %>%
+ tab |>
transmute(
numbers = int * 4,
words = as.character(int)
- ) %>%
+ ) |>
implicit_schema(),
schema(numbers = int32(), words = utf8())
)
@@ -65,10 +65,10 @@ test_that("implicit_schema with mutate", {
test_that("implicit_schema with summarize", {
expect_equal(
- tab %>%
+ tab |>
summarize(
avg = mean(int)
- ) %>%
+ ) |>
implicit_schema(),
schema(avg = float64())
)
@@ -76,70 +76,70 @@ test_that("implicit_schema with summarize", {
test_that("implicit_schema with group_by summarize", {
expect_equal(
- tab %>%
- group_by(some_grouping) %>%
+ tab |>
+ group_by(some_grouping) |>
summarize(
avg = mean(int * 5L)
- ) %>%
+ ) |>
implicit_schema(),
schema(some_grouping = float64(), avg = float64())
)
})
test_that("collapse", {
- q <- tab %>%
- filter(dbl > 2, chr == "d" | chr == "f") %>%
- select(chr, int, lgl) %>%
+ q <- tab |>
+ filter(dbl > 2, chr == "d" | chr == "f") |>
+ select(chr, int, lgl) |>
mutate(twice = int * 2L)
expect_false(is_collapsed(q))
expect_true(is_collapsed(collapse(q)))
expect_false(is_collapsed(collapse(q)$.data))
compare_dplyr_binding(
- .input %>%
- filter(dbl > 2, chr == "d" | chr == "f") %>%
- select(chr, int, lgl) %>%
- mutate(twice = int * 2L) %>%
- collapse() %>%
- filter(int < 5) %>%
- select(int, twice) %>%
+ .input |>
+ filter(dbl > 2, chr == "d" | chr == "f") |>
+ select(chr, int, lgl) |>
+ mutate(twice = int * 2L) |>
+ collapse() |>
+ filter(int < 5) |>
+ select(int, twice) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(dbl > 2, chr == "d" | chr == "f") %>%
- collapse() %>%
- select(chr, int, lgl) %>%
- collapse() %>%
- filter(int < 5) %>%
- select(int, chr) %>%
+ .input |>
+ filter(dbl > 2, chr == "d" | chr == "f") |>
+ collapse() |>
+ select(chr, int, lgl) |>
+ collapse() |>
+ filter(int < 5) |>
+ select(int, chr) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(dbl > 2, chr == "d" | chr == "f") %>%
- collapse() %>%
- group_by(chr) %>%
- select(chr, int, lgl) %>%
- collapse() %>%
- filter(int < 5) %>%
- select(int, chr) %>%
+ .input |>
+ filter(dbl > 2, chr == "d" | chr == "f") |>
+ collapse() |>
+ group_by(chr) |>
+ select(chr, int, lgl) |>
+ collapse() |>
+ filter(int < 5) |>
+ select(int, chr) |>
collect(),
tbl
)
})
test_that("Properties of collapsed query", {
- q <- tab %>%
- filter(dbl > 2) %>%
- select(chr, int, lgl) %>%
- mutate(twice = int * 2L) %>%
- group_by(lgl) %>%
- summarize(total = sum(int, na.rm = TRUE)) %>%
+ q <- tab |>
+ filter(dbl > 2) |>
+ select(chr, int, lgl) |>
+ mutate(twice = int * 2L) |>
+ group_by(lgl) |>
+ summarize(total = sum(int, na.rm = TRUE)) |>
mutate(extra = total * 5)
# # A tibble: 2 × 3
@@ -164,17 +164,17 @@ See $.data for the source Arrow object",
)
expect_equal(
- q %>%
- arrange(lgl) %>%
- head(1) %>%
+ q |>
+ arrange(lgl) |>
+ head(1) |>
collect(),
tibble::tibble(lgl = FALSE, total = 8L, extra = 40)
)
skip("TODO (ARROW-16630): make sure BottomK can handle NA ordering")
expect_equal(
- q %>%
- arrange(lgl) %>%
- tail(1) %>%
+ q |>
+ arrange(lgl) |>
+ tail(1) |>
collect(),
tibble::tibble(lgl = NA, total = 25L, extra = 125)
)
@@ -182,13 +182,13 @@ See $.data for the source Arrow object",
test_that("query_on_dataset handles collapse()", {
expect_false(query_on_dataset(
- tab %>%
+ tab |>
select(int, chr)
))
expect_false(query_on_dataset(
- tab %>%
- select(int, chr) %>%
- collapse() %>%
+ tab |>
+ select(int, chr) |>
+ collapse() |>
select(int)
))
@@ -201,32 +201,32 @@ test_that("query_on_dataset handles collapse()", {
ds <- open_dataset(ds_dir)
expect_true(query_on_dataset(
- ds %>%
+ ds |>
select(int, chr)
))
expect_true(query_on_dataset(
- ds %>%
- select(int, chr) %>%
- collapse() %>%
+ ds |>
+ select(int, chr) |>
+ collapse() |>
select(int)
))
})
test_that("collapse doesn't unnecessarily add ProjectNodes", {
plan <- capture.output(
- tab %>%
- collapse() %>%
- collapse() %>%
+ tab |>
+ collapse() |>
+ collapse() |>
show_query()
)
# There should be no projections
expect_length(grep("ProjectNode", plan), 0)
plan <- capture.output(
- tab %>%
- select(int, chr) %>%
- collapse() %>%
- collapse() %>%
+ tab |>
+ select(int, chr) |>
+ collapse() |>
+ collapse() |>
show_query()
)
# There should be just one projection
@@ -240,9 +240,9 @@ test_that("collapse doesn't unnecessarily add ProjectNodes", {
ds <- open_dataset(tf)
plan <- capture.output(
- ds %>%
- collapse() %>%
- collapse() %>%
+ ds |>
+ collapse() |>
+ collapse() |>
show_query()
)
expect_length(grep("ProjectNode", plan), 1)
diff --git a/r/tests/testthat/test-dplyr-count.R b/r/tests/testthat/test-dplyr-count.R
index 6c45ded31d..8eee91de8d 100644
--- a/r/tests/testthat/test-dplyr-count.R
+++ b/r/tests/testthat/test-dplyr-count.R
@@ -25,15 +25,15 @@ tbl$another_grouping <- rep(c(1, 2), 5)
test_that("count/tally", {
compare_dplyr_binding(
- .input %>%
- count() %>%
+ .input |>
+ count() |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- tally() %>%
+ .input |>
+ tally() |>
collect(),
tbl
)
@@ -41,17 +41,17 @@ test_that("count/tally", {
test_that("count/tally with wt and grouped data", {
compare_dplyr_binding(
- .input %>%
- group_by(some_grouping) %>%
- count(wt = int) %>%
+ .input |>
+ group_by(some_grouping) |>
+ count(wt = int) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- group_by(some_grouping) %>%
- tally(wt = int) %>%
+ .input |>
+ group_by(some_grouping) |>
+ tally(wt = int) |>
collect(),
tbl
)
@@ -59,17 +59,17 @@ test_that("count/tally with wt and grouped data", {
test_that("count/tally with sort", {
compare_dplyr_binding(
- .input %>%
- group_by(some_grouping) %>%
- count(wt = int, sort = TRUE) %>%
+ .input |>
+ group_by(some_grouping) |>
+ count(wt = int, sort = TRUE) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- group_by(some_grouping) %>%
- tally(wt = int, sort = TRUE) %>%
+ .input |>
+ group_by(some_grouping) |>
+ tally(wt = int, sort = TRUE) |>
collect(),
tbl
)
@@ -77,15 +77,15 @@ test_that("count/tally with sort", {
test_that("count/tally with name arg", {
compare_dplyr_binding(
- .input %>%
- count(name = "new_col") %>%
+ .input |>
+ count(name = "new_col") |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- tally(name = "new_col") %>%
+ .input |>
+ tally(name = "new_col") |>
collect(),
tbl
)
@@ -93,8 +93,8 @@ test_that("count/tally with name arg", {
test_that("count returns an ungrouped tibble", {
compare_dplyr_binding(
- .input %>%
- count(some_grouping, another_grouping, sort = TRUE) %>%
+ .input |>
+ count(some_grouping, another_grouping, sort = TRUE) |>
collect(),
tbl
)
@@ -103,21 +103,21 @@ test_that("count returns an ungrouped tibble", {
test_that("tally raises appropriate error and message for names", {
expect_message(
- tbl %>%
- arrow_table() %>%
- rename(n = some_grouping) %>%
- group_by(n) %>%
- tally() %>%
+ tbl |>
+ arrow_table() |>
+ rename(n = some_grouping) |>
+ group_by(n) |>
+ tally() |>
collect(),
regexp = 'Use `name = "new_name"` to pick a new name.',
fixed = TRUE
)
expect_error(
- tbl %>%
- arrow_table() %>%
- group_by(some_grouping) %>%
- tally(wt = int, name = 99) %>%
+ tbl |>
+ arrow_table() |>
+ group_by(some_grouping) |>
+ tally(wt = int, name = 99) |>
collect(),
"`name` must be a string or `NULL`.",
fixed = TRUE
diff --git a/r/tests/testthat/test-dplyr-distinct.R b/r/tests/testthat/test-dplyr-distinct.R
index e4d789e8e9..4b9ec44825 100644
--- a/r/tests/testthat/test-dplyr-distinct.R
+++ b/r/tests/testthat/test-dplyr-distinct.R
@@ -24,9 +24,9 @@ tbl$some_grouping <- rep(c(1, 2), 5)
test_that("distinct()", {
compare_dplyr_binding(
- .input %>%
- distinct(some_grouping, lgl) %>%
- arrange(some_grouping, lgl) %>%
+ .input |>
+ distinct(some_grouping, lgl) |>
+ arrange(some_grouping, lgl) |>
collect(),
tbl
)
@@ -34,19 +34,19 @@ test_that("distinct()", {
test_that("distinct() works without any variables", {
compare_dplyr_binding(
- .input %>%
- distinct() %>%
- arrange(int) %>%
+ .input |>
+ distinct() |>
+ arrange(int) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- group_by(x = int + 1) %>%
- distinct() %>%
+ .input |>
+ group_by(x = int + 1) |>
+ distinct() |>
# Even though we have group_by(x), all cols (including int) are kept
- arrange(int) %>%
+ arrange(int) |>
collect(),
tbl
)
@@ -54,20 +54,20 @@ test_that("distinct() works without any variables", {
test_that("distinct() can retain groups", {
compare_dplyr_binding(
- .input %>%
- group_by(some_grouping, int) %>%
- distinct(lgl) %>%
- arrange(lgl, int) %>%
+ .input |>
+ group_by(some_grouping, int) |>
+ distinct(lgl) |>
+ arrange(lgl, int) |>
collect(),
tbl
)
# With expressions here
compare_dplyr_binding(
- .input %>%
- group_by(y = some_grouping, int) %>%
- distinct(x = lgl) %>%
- arrange(int) %>%
+ .input |>
+ group_by(y = some_grouping, int) |>
+ distinct(x = lgl) |>
+ arrange(int) |>
collect(),
tbl
)
@@ -75,18 +75,18 @@ test_that("distinct() can retain groups", {
test_that("distinct() can contain expressions", {
compare_dplyr_binding(
- .input %>%
- distinct(lgl, x = some_grouping + 1) %>%
- collect() %>%
+ .input |>
+ distinct(lgl, x = some_grouping + 1) |>
+ collect() |>
arrange(lgl, x),
tbl
)
compare_dplyr_binding(
- .input %>%
- group_by(lgl, int) %>%
- distinct(x = some_grouping + 1) %>%
- arrange(int) %>%
+ .input |>
+ group_by(lgl, int) |>
+ distinct(x = some_grouping + 1) |>
+ arrange(int) |>
collect(),
tbl
)
@@ -94,9 +94,9 @@ test_that("distinct() can contain expressions", {
test_that("across() works in distinct()", {
compare_dplyr_binding(
- .input %>%
- distinct(across(starts_with("d"))) %>%
- collect() %>%
+ .input |>
+ distinct(across(starts_with("d"))) |>
+ collect() |>
arrange(dbl, dbl2),
tbl
)
@@ -105,35 +105,35 @@ test_that("across() works in distinct()", {
test_that("distinct() can return all columns", {
# hash_one prefers to keep non-null values, which is different from .keep_all in dplyr
# so we can't compare the result directly
- expected <- tbl %>%
+ expected <- tbl |>
# Drop factor because of #44661:
# NotImplemented: Function 'hash_one' has no kernel matching input types
# (dictionary<values=string, indices=int8, ordered=0>, uint8)
- select(-fct) %>%
- distinct(lgl, .keep_all = TRUE) %>%
+ select(-fct) |>
+ distinct(lgl, .keep_all = TRUE) |>
arrange(int)
- with_table <- tbl %>%
- arrow_table() %>%
- select(-fct) %>%
- distinct(lgl, .keep_all = TRUE) %>%
- arrange(int) %>%
+ with_table <- tbl |>
+ arrow_table() |>
+ select(-fct) |>
+ distinct(lgl, .keep_all = TRUE) |>
+ arrange(int) |>
collect()
expect_identical(dim(with_table), dim(expected))
expect_identical(names(with_table), names(expected))
# Test with some mutation in there
- expected <- tbl %>%
- select(-fct) %>%
- distinct(lgl, bigger = int * 10L, .keep_all = TRUE) %>%
+ expected <- tbl |>
+ select(-fct) |>
+ distinct(lgl, bigger = int * 10L, .keep_all = TRUE) |>
arrange(int)
- with_table <- tbl %>%
- arrow_table() %>%
- select(-fct) %>%
- distinct(lgl, bigger = int * 10, .keep_all = TRUE) %>%
- arrange(int) %>%
+ with_table <- tbl |>
+ arrow_table() |>
+ select(-fct) |>
+ distinct(lgl, bigger = int * 10, .keep_all = TRUE) |>
+ arrange(int) |>
collect()
expect_identical(dim(with_table), dim(expected))
@@ -141,16 +141,16 @@ test_that("distinct() can return all columns", {
expect_identical(with_table$bigger, expected$bigger)
# Mutation that overwrites
- expected <- tbl %>%
- select(-fct) %>%
- distinct(lgl, int = int * 10L, .keep_all = TRUE) %>%
+ expected <- tbl |>
+ select(-fct) |>
+ distinct(lgl, int = int * 10L, .keep_all = TRUE) |>
arrange(int)
- with_table <- tbl %>%
- arrow_table() %>%
- select(-fct) %>%
- distinct(lgl, int = int * 10, .keep_all = TRUE) %>%
- arrange(int) %>%
+ with_table <- tbl |>
+ arrow_table() |>
+ select(-fct) |>
+ distinct(lgl, int = int * 10, .keep_all = TRUE) |>
+ arrange(int) |>
collect()
expect_identical(dim(with_table), dim(expected))
diff --git a/r/tests/testthat/test-dplyr-filter.R b/r/tests/testthat/test-dplyr-filter.R
index ae3ce29edf..23d49feb3b 100644
--- a/r/tests/testthat/test-dplyr-filter.R
+++ b/r/tests/testthat/test-dplyr-filter.R
@@ -30,9 +30,9 @@ tbl$some_negative <- tbl$int * (-1)^(1:nrow(tbl)) # nolint
test_that("filter() on is.na()", {
compare_dplyr_binding(
- .input %>%
- filter(is.na(lgl)) %>%
- select(chr, int, lgl) %>%
+ .input |>
+ filter(is.na(lgl)) |>
+ select(chr, int, lgl) |>
collect(),
tbl
)
@@ -40,9 +40,9 @@ test_that("filter() on is.na()", {
test_that("filter() with NAs in selection", {
compare_dplyr_binding(
- .input %>%
- filter(lgl) %>%
- select(chr, int, lgl) %>%
+ .input |>
+ filter(lgl) |>
+ select(chr, int, lgl) |>
collect(),
tbl
)
@@ -50,9 +50,9 @@ test_that("filter() with NAs in selection", {
test_that("Filter returning an empty Table should not segfault (ARROW-8354)", {
compare_dplyr_binding(
- .input %>%
- filter(false) %>%
- select(chr, int, lgl) %>%
+ .input |>
+ filter(false) |>
+ select(chr, int, lgl) |>
collect(),
tbl
)
@@ -61,9 +61,9 @@ test_that("Filter returning an empty Table should not segfault (ARROW-8354)", {
test_that("filtering with expression", {
char_sym <- "b"
compare_dplyr_binding(
- .input %>%
- filter(chr == char_sym) %>%
- select(string = chr, int) %>%
+ .input |>
+ filter(chr == char_sym) |>
+ select(string = chr, int) |>
collect(),
tbl
)
@@ -71,57 +71,57 @@ test_that("filtering with expression", {
test_that("filtering with arithmetic", {
compare_dplyr_binding(
- .input %>%
- filter(dbl + 1 > 3) %>%
- select(string = chr, int, dbl) %>%
+ .input |>
+ filter(dbl + 1 > 3) |>
+ select(string = chr, int, dbl) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(dbl / 2 > 3) %>%
- select(string = chr, int, dbl) %>%
+ .input |>
+ filter(dbl / 2 > 3) |>
+ select(string = chr, int, dbl) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(dbl / 2L > 3) %>%
- select(string = chr, int, dbl) %>%
+ .input |>
+ filter(dbl / 2L > 3) |>
+ select(string = chr, int, dbl) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(int / 2 > 3) %>%
- select(string = chr, int, dbl) %>%
+ .input |>
+ filter(int / 2 > 3) |>
+ select(string = chr, int, dbl) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(int / 2L > 3) %>%
- select(string = chr, int, dbl) %>%
+ .input |>
+ filter(int / 2L > 3) |>
+ select(string = chr, int, dbl) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(dbl %/% 2 > 3) %>%
- select(string = chr, int, dbl) %>%
+ .input |>
+ filter(dbl %/% 2 > 3) |>
+ select(string = chr, int, dbl) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(dbl^2 > 3) %>%
- select(string = chr, int, dbl) %>%
+ .input |>
+ filter(dbl^2 > 3) |>
+ select(string = chr, int, dbl) |>
collect(),
tbl
)
@@ -129,25 +129,25 @@ test_that("filtering with arithmetic", {
test_that("filtering with expression + autocasting", {
compare_dplyr_binding(
- .input %>%
- filter(dbl + 1 > 3L) %>% # test autocasting with comparison to 3L
- select(string = chr, int, dbl) %>%
+ .input |>
+ filter(dbl + 1 > 3L) |> # test autocasting with comparison to 3L
+ select(string = chr, int, dbl) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(int + 1 > 3) %>%
- select(string = chr, int, dbl) %>%
+ .input |>
+ filter(int + 1 > 3) |>
+ select(string = chr, int, dbl) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(int^2 > 3) %>%
- select(string = chr, int, dbl) %>%
+ .input |>
+ filter(int^2 > 3) |>
+ select(string = chr, int, dbl) |>
collect(),
tbl
)
@@ -155,11 +155,11 @@ test_that("filtering with expression + autocasting", {
test_that("More complex select/filter", {
compare_dplyr_binding(
- .input %>%
- filter(dbl > 2, chr == "d" | chr == "f") %>%
- select(chr, int, lgl) %>%
- filter(int < 5) %>%
- select(int, chr) %>%
+ .input |>
+ filter(dbl > 2, chr == "d" | chr == "f") |>
+ select(chr, int, lgl) |>
+ filter(int < 5) |>
+ select(int, chr) |>
collect(),
tbl
)
@@ -167,8 +167,8 @@ test_that("More complex select/filter", {
test_that("filter() with %in%", {
compare_dplyr_binding(
- .input %>%
- filter(dbl > 2, chr %in% c("d", "f")) %>%
+ .input |>
+ filter(dbl > 2, chr %in% c("d", "f")) |>
collect(),
tbl
)
@@ -176,20 +176,20 @@ test_that("filter() with %in%", {
test_that("Negative scalar values", {
compare_dplyr_binding(
- .input %>%
- filter(some_negative > -2) %>%
+ .input |>
+ filter(some_negative > -2) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(some_negative %in% -1) %>%
+ .input |>
+ filter(some_negative %in% -1) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(int == -some_negative) %>%
+ .input |>
+ filter(int == -some_negative) |>
collect(),
tbl
)
@@ -197,31 +197,31 @@ test_that("Negative scalar values", {
test_that("filter() with between()", {
compare_dplyr_binding(
- .input %>%
- filter(between(dbl, 1, 2)) %>%
+ .input |>
+ filter(between(dbl, 1, 2)) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(between(dbl, 0.5, 2)) %>%
+ .input |>
+ filter(between(dbl, 0.5, 2)) |>
collect(),
tbl
)
expect_identical(
- tbl %>%
- record_batch() %>%
- filter(between(dbl, int, dbl2)) %>%
+ tbl |>
+ record_batch() |>
+ filter(between(dbl, int, dbl2)) |>
collect(),
- tbl %>%
+ tbl |>
filter(dbl >= int, dbl <= dbl2)
)
compare_dplyr_binding(
- .input %>%
- filter(between(dbl, 1, NA)) %>%
+ .input |>
+ filter(between(dbl, 1, NA)) |>
collect(),
tbl
)
@@ -230,15 +230,15 @@ test_that("filter() with between()", {
test_that("filter() with string ops", {
skip_if_not_available("utf8proc")
compare_dplyr_binding(
- .input %>%
- filter(dbl > 2, str_length(verses) > 25) %>%
+ .input |>
+ filter(dbl > 2, str_length(verses) > 25) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(dbl > 2, str_length(str_trim(padded_strings, "left")) > 5) %>%
+ .input |>
+ filter(dbl > 2, str_length(str_trim(padded_strings, "left")) > 5) |>
collect(),
tbl
)
@@ -246,41 +246,41 @@ test_that("filter() with string ops", {
test_that("filter environment scope", {
# "object 'b_var' not found"
- compare_dplyr_error(.input %>% filter(chr == b_var), tbl)
+ compare_dplyr_error(.input |> filter(chr == b_var), tbl)
b_var <- "b"
compare_dplyr_binding(
- .input %>%
- filter(chr == b_var) %>%
+ .input |>
+ filter(chr == b_var) |>
collect(),
tbl
)
# Also for functions
# 'could not find function "isEqualTo"' because we haven't defined it yet
- compare_dplyr_error(.input %>% filter(isEqualTo(int, 4)), tbl)
+ compare_dplyr_error(.input |> filter(isEqualTo(int, 4)), tbl)
# This works but only because there are S3 methods for those operations
isEqualTo <- function(x, y) x == y & !is.na(x)
compare_dplyr_binding(
- .input %>%
- select(-fct) %>% # factor levels aren't identical
- filter(isEqualTo(int, 4)) %>%
+ .input |>
+ select(-fct) |> # factor levels aren't identical
+ filter(isEqualTo(int, 4)) |>
collect(),
tbl
)
# Try something that needs to call another nse_func
compare_dplyr_binding(
- .input %>%
- select(-fct) %>%
- filter(nchar(padded_strings) < 10) %>%
+ .input |>
+ select(-fct) |>
+ filter(nchar(padded_strings) < 10) |>
collect(),
tbl
)
isShortString <- function(x) nchar(x) < 10
compare_dplyr_binding(
- .input %>%
- select(-fct) %>%
- filter(isShortString(padded_strings)) %>%
+ .input |>
+ select(-fct) |>
+ filter(isShortString(padded_strings)) |>
collect(),
tbl
)
@@ -294,7 +294,7 @@ test_that("Filtering on a column that doesn't exist errors correctly", {
# a user error, not solvable by retrying in R
expect_warning(
expect_error(
- tbl %>% record_batch() %>% filter(not_a_col == 42) %>% collect(),
+ tbl |> record_batch() |> filter(not_a_col == 42) |> collect(),
"objet 'not_a_col' introuvable"
),
NA
@@ -303,7 +303,7 @@ test_that("Filtering on a column that doesn't exist errors correctly", {
with_language("en", {
expect_warning(
expect_error(
- tbl %>% record_batch() %>% filter(not_a_col == 42) %>% collect(),
+ tbl |> record_batch() |> filter(not_a_col == 42) |> collect(),
"object 'not_a_col' not found"
),
NA
@@ -313,8 +313,8 @@ test_that("Filtering on a column that doesn't exist errors correctly", {
test_that("Filtering with unsupported functions", {
compare_dplyr_binding(
- .input %>%
- filter(int > 2, pnorm(dbl) > 0.99) %>%
+ .input |>
+ filter(int > 2, pnorm(dbl) > 0.99) |>
collect(),
tbl,
warning = paste(
@@ -325,12 +325,12 @@ test_that("Filtering with unsupported functions", {
)
)
compare_dplyr_binding(
- .input %>%
+ .input |>
filter(
nchar(chr, type = "bytes", allowNA = TRUE) == 1, # bad, Arrow msg
int > 2, # good
pnorm(dbl) > 0.99 # bad, opaque, but we'll error on the first one before we get here
- ) %>%
+ ) |>
collect(),
tbl,
warning = paste(
@@ -344,43 +344,43 @@ test_that("Filtering with unsupported functions", {
test_that("Calling Arrow compute functions 'directly'", {
expect_equal(
- tbl %>%
- record_batch() %>%
- filter(arrow_add(dbl, 1) > 3L) %>%
- select(string = chr, int, dbl) %>%
+ tbl |>
+ record_batch() |>
+ filter(arrow_add(dbl, 1) > 3L) |>
+ select(string = chr, int, dbl) |>
collect(),
- tbl %>%
- filter(dbl + 1 > 3L) %>%
+ tbl |>
+ filter(dbl + 1 > 3L) |>
select(string = chr, int, dbl)
)
compare_dplyr_binding(
- tbl %>%
- record_batch() %>%
- filter(arrow_greater(arrow_add(dbl, 1), 3L)) %>%
- select(string = chr, int, dbl) %>%
+ tbl |>
+ record_batch() |>
+ filter(arrow_greater(arrow_add(dbl, 1), 3L)) |>
+ select(string = chr, int, dbl) |>
collect(),
- tbl %>%
- filter(dbl + 1 > 3L) %>%
+ tbl |>
+ filter(dbl + 1 > 3L) |>
select(string = chr, int, dbl)
)
})
test_that("filter() with .data pronoun", {
compare_dplyr_binding(
- .input %>%
- filter(.data$dbl > 4) %>%
+ .input |>
+ filter(.data$dbl > 4) |>
# use "quoted" strings instead of .data pronoun where tidyselect is used
# .data pronoun deprecated in select in tidyselect 1.2
- select("chr", "int", "lgl") %>%
+ select("chr", "int", "lgl") |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(is.na(.data$lgl)) %>%
- select("chr", "int", "lgl") %>%
+ .input |>
+ filter(is.na(.data$lgl)) |>
+ select("chr", "int", "lgl") |>
collect(),
tbl
)
@@ -388,9 +388,9 @@ test_that("filter() with .data pronoun", {
# and the .env pronoun too!
chr <- 4
compare_dplyr_binding(
- .input %>%
- filter(.data$dbl > .env$chr) %>%
- select("chr", "int", "lgl") %>%
+ .input |>
+ filter(.data$dbl > .env$chr) |>
+ select("chr", "int", "lgl") |>
collect(),
tbl
)
@@ -398,16 +398,16 @@ test_that("filter() with .data pronoun", {
test_that("filter() with namespaced functions", {
compare_dplyr_binding(
- .input %>%
- filter(dplyr::between(dbl, 1, 2)) %>%
+ .input |>
+ filter(dplyr::between(dbl, 1, 2)) |>
collect(),
tbl
)
skip_if_not_available("utf8proc")
compare_dplyr_binding(
- .input %>%
- filter(dbl > 2, stringr::str_length(verses) > 25) %>%
+ .input |>
+ filter(dbl > 2, stringr::str_length(verses) > 25) |>
collect(),
tbl
)
@@ -415,19 +415,19 @@ test_that("filter() with namespaced functions", {
test_that("filter() with across()", {
compare_dplyr_binding(
- .input %>%
- filter(if_any(ends_with("l"), ~ is.na(.))) %>%
+ .input |>
+ filter(if_any(ends_with("l"), ~ is.na(.))) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
+ .input |>
filter(
false == FALSE,
if_all(everything(), ~ !is.na(.)),
int > 2
- ) %>%
+ ) |>
collect(),
tbl
)
@@ -435,44 +435,44 @@ test_that("filter() with across()", {
test_that(".by argument", {
compare_dplyr_binding(
- .input %>%
- filter(is.na(lgl), .by = chr) %>%
- select(chr, int, lgl) %>%
+ .input |>
+ filter(is.na(lgl), .by = chr) |>
+ select(chr, int, lgl) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(is.na(lgl), .by = starts_with("chr")) %>%
- select(chr, int, lgl) %>%
+ .input |>
+ filter(is.na(lgl), .by = starts_with("chr")) |>
+ select(chr, int, lgl) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(.by = chr) %>%
- select(chr, int, lgl) %>%
+ .input |>
+ filter(.by = chr) |>
+ select(chr, int, lgl) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(.by = c(int, chr)) %>%
- select(chr, int, lgl) %>%
+ .input |>
+ filter(.by = c(int, chr)) |>
+ select(chr, int, lgl) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- filter(.by = c("int", "chr")) %>%
- select(chr, int, lgl) %>%
+ .input |>
+ filter(.by = c("int", "chr")) |>
+ select(chr, int, lgl) |>
collect(),
tbl
)
# filter should pulling not grouped data into R when using the .by argument
compare_dplyr_binding(
- .input %>%
- filter(int > 2, pnorm(dbl) > 0.99, .by = chr) %>%
+ .input |>
+ filter(int > 2, pnorm(dbl) > 0.99, .by = chr) |>
collect(),
tbl,
warning = paste(
@@ -483,9 +483,9 @@ test_that(".by argument", {
)
)
expect_error(
- tbl %>%
- arrow_table() %>%
- group_by(chr) %>%
+ tbl |>
+ arrow_table() |>
+ group_by(chr) |>
filter(is.na(lgl), .by = chr),
"Can't supply `\\.by` when `\\.data` is grouped data"
)
diff --git a/r/tests/testthat/test-dplyr-funcs-conditional.R b/r/tests/testthat/test-dplyr-funcs-conditional.R
index 3ff93c0a87..fc0dfbb7df 100644
--- a/r/tests/testthat/test-dplyr-funcs-conditional.R
+++ b/r/tests/testthat/test-dplyr-funcs-conditional.R
@@ -29,8 +29,8 @@ tbl$another_chr <- tail(letters, 10)
test_that("%in% handles dictionary type", {
df <- tibble::tibble(x = factor(c("a", "b", "c")))
compare_dplyr_binding(
- .input %>%
- filter(x %in% "a") %>%
+ .input |>
+ filter(x %in% "a") |>
collect(),
df
)
@@ -38,103 +38,103 @@ test_that("%in% handles dictionary type", {
test_that("if_else and ifelse", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = if_else(int > 5, 1, 0),
y2 = dplyr::if_else(int > 6, 1, 0)
- ) %>%
+ ) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = if_else(int > 5, int, 0L)
- ) %>%
+ ) |>
collect(),
tbl
)
expect_error(
- Table$create(tbl) %>%
+ Table$create(tbl) |>
mutate(
y = if_else(int > 5, 1, FALSE)
- ) %>%
+ ) |>
collect(),
"NotImplemented: Function 'if_else' has no kernel matching input types"
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = if_else(int > 5, 1, NA_real_)
- ) %>%
+ ) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = ifelse(int > 5, 1, 0),
y2 = base::ifelse(int > 6, 1, 0)
- ) %>%
+ ) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = if_else(dbl > 5, TRUE, FALSE)
- ) %>%
+ ) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = if_else(chr %in% letters[1:3], 1L, 3L)
- ) %>%
+ ) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = if_else(int > 5, "one", "zero")
- ) %>%
+ ) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = if_else(int > 5, chr, another_chr)
- ) %>%
+ ) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = if_else(int > 5, "true", chr, missing = "MISSING")
- ) %>%
+ ) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = if_else(int > 5, fct, factor("a"))
- ) %>%
- collect() %>%
+ ) |>
+ collect() |>
# Arrow if_else() kernel does not preserve unused factor levels,
# so reset the levels of all the factor columns to make the test pass
# (ARROW-14649)
@@ -147,10 +147,10 @@ test_that("if_else and ifelse", {
# detecting NA and NaN works just fine
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = if_else(is.na(dbl), chr, "false", missing = "MISSING")
- ) %>%
+ ) |>
collect(),
example_data_for_sorting
)
@@ -158,18 +158,18 @@ test_that("if_else and ifelse", {
# However, currently comparisons with NaNs return false and not NaNs or NAs
skip("ARROW-13364")
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = if_else(dbl > 5, chr, another_chr, missing = "MISSING")
- ) %>%
+ ) |>
collect(),
example_data_for_sorting
)
skip("TODO: could? should? we support the autocasting in ifelse")
compare_dplyr_binding(
- .input %>%
- mutate(y = ifelse(int > 5, 1, FALSE)) %>%
+ .input |>
+ mutate(y = ifelse(int > 5, 1, FALSE)) |>
collect(),
tbl
)
@@ -177,28 +177,28 @@ test_that("if_else and ifelse", {
test_that("case_when()", {
compare_dplyr_binding(
- .input %>%
- transmute(cw = case_when(lgl ~ dbl, !false ~ dbl + dbl2)) %>%
+ .input |>
+ transmute(cw = case_when(lgl ~ dbl, !false ~ dbl + dbl2)) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- mutate(cw = case_when(int > 5 ~ 1, TRUE ~ 0)) %>%
+ .input |>
+ mutate(cw = case_when(int > 5 ~ 1, TRUE ~ 0)) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- mutate(cw = case_when(int > 5 ~ 1, .default = 0)) %>%
+ .input |>
+ mutate(cw = case_when(int > 5 ~ 1, .default = 0)) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- transmute(cw = case_when(chr %in% letters[1:3] ~ 1L) + 41L) %>%
+ .input |>
+ transmute(cw = case_when(chr %in% letters[1:3] ~ 1L) + 41L) |>
collect(),
tbl
)
@@ -208,8 +208,8 @@ test_that("case_when()", {
withr::with_options(list(arrow.debug = TRUE), {
expect_output(
compare_dplyr_binding(
- .input %>%
- transmute(cw = case_when(isIn(chr, letters[1:3]) ~ 1L) + 41L) %>%
+ .input |>
+ transmute(cw = case_when(isIn(chr, letters[1:3]) ~ 1L) + 41L) |>
collect(),
tbl
),
@@ -218,24 +218,24 @@ test_that("case_when()", {
})
compare_dplyr_binding(
- .input %>%
+ .input |>
filter(case_when(
dbl + int - 1.1 == dbl2 ~ TRUE,
NA ~ NA,
TRUE ~ FALSE
- ) & !is.na(dbl2)) %>%
+ ) & !is.na(dbl2)) |>
collect(),
tbl
)
# with namespacing
compare_dplyr_binding(
- .input %>%
+ .input |>
filter(dplyr::case_when(
dbl + int - 1.1 == dbl2 ~ TRUE,
NA ~ NA,
TRUE ~ FALSE
- ) & !is.na(dbl2)) %>%
+ ) & !is.na(dbl2)) |>
collect(),
tbl
)
@@ -243,16 +243,16 @@ test_that("case_when()", {
# dplyr::case_when() errors if values on right side of formulas do not have
# exactly the same type, but the Arrow case_when kernel allows compatible types
expect_equal(
- tbl %>%
- mutate(i64 = as.integer64(1e10)) %>%
- Table$create() %>%
+ tbl |>
+ mutate(i64 = as.integer64(1e10)) |>
+ Table$create() |>
transmute(cw = case_when(
is.na(fct) ~ int,
is.na(chr) ~ dbl,
TRUE ~ i64
- )) %>%
+ )) |>
collect(),
- tbl %>%
+ tbl |>
transmute(
cw = ifelse(is.na(fct), int, ifelse(is.na(chr), dbl, 1e10))
)
@@ -305,23 +305,23 @@ test_that("case_when()", {
)
compare_dplyr_binding(
- .input %>%
- transmute(cw = case_when(lgl ~ "abc")) %>%
+ .input |>
+ transmute(cw = case_when(lgl ~ "abc")) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- transmute(cw = case_when(lgl ~ verses, !false ~ paste(chr, chr))) %>%
+ .input |>
+ transmute(cw = case_when(lgl ~ verses, !false ~ paste(chr, chr))) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
cw = case_when(!(!(!(lgl))) ~ factor(chr), TRUE ~ fct)
- ) %>%
+ ) |>
collect(),
tbl,
warning = TRUE
@@ -337,45 +337,45 @@ test_that("coalesce()", {
z = c("a", "b", "c")
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
cw = coalesce(w),
cz = coalesce(z),
cwx = coalesce(w, x),
cwxy = coalesce(w, x, y),
cwxyz = coalesce(w, x, y, z)
- ) %>%
+ ) |>
collect(),
df
)
# with namespacing
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
cw = dplyr::coalesce(w),
cz = dplyr::coalesce(z),
cwx = dplyr::coalesce(w, x),
cwxy = dplyr::coalesce(w, x, y),
cwxyz = dplyr::coalesce(w, x, y, z)
- ) %>%
+ ) |>
collect(),
df
)
# factor
- df_fct <- df %>%
+ df_fct <- df |>
transmute(across(everything(), ~ factor(.x, levels = c("a", "b", "c"))))
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
cw = coalesce(w),
cz = coalesce(z),
cwx = coalesce(w, x),
cwxy = coalesce(w, x, y),
cwxyz = coalesce(w, x, y, z)
- ) %>%
- collect() %>%
+ ) |>
+ collect() |>
# Arrow coalesce() kernel does not preserve unused factor levels,
# so reset the levels of all the factor columns to make the test pass
# (ARROW-14649)
@@ -391,14 +391,14 @@ test_that("coalesce()", {
z = 1:3
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
cw = coalesce(w),
cz = coalesce(z),
cwx = coalesce(w, x),
cwxy = coalesce(w, x, y),
cwxyz = coalesce(w, x, y, z)
- ) %>%
+ ) |>
collect(),
df
)
@@ -414,14 +414,14 @@ test_that("coalesce()", {
# we can't use compare_dplyr_binding here as dplyr silently converts NaN to NA in coalesce()
# see https://github.com/tidyverse/dplyr/issues/6833
expect_identical(
- arrow_table(df) %>%
+ arrow_table(df) |>
mutate(
cw = coalesce(w),
cz = coalesce(z),
cwx = coalesce(w, x),
cwxy = coalesce(w, x, y),
cwxyz = coalesce(w, x, y, z)
- ) %>%
+ ) |>
collect(),
mutate(
df,
@@ -436,34 +436,34 @@ test_that("coalesce()", {
# NaNs stay NaN and are not converted to NA in the results
# (testing this requires expect_identical())
expect_identical(
- df %>% Table$create() %>% mutate(cwx = coalesce(w, x)) %>% collect(),
- df %>% mutate(cwx = c(NA, NaN, 3.3))
+ df |> Table$create() |> mutate(cwx = coalesce(w, x)) |> collect(),
+ df |> mutate(cwx = c(NA, NaN, 3.3))
)
expect_identical(
- df %>% Table$create() %>% transmute(cw = coalesce(w)) %>% collect(),
- df %>% transmute(cw = w)
+ df |> Table$create() |> transmute(cw = coalesce(w)) |> collect(),
+ df |> transmute(cw = w)
)
expect_identical(
- df %>% Table$create() %>% transmute(cn = coalesce(NaN)) %>% collect(),
- df %>% transmute(cn = NaN)
+ df |> Table$create() |> transmute(cn = coalesce(NaN)) |> collect(),
+ df |> transmute(cn = NaN)
)
# singles stay single
expect_equal(
- (df %>%
+ (df |>
Table$create(schema = schema(
w = float32(),
x = float32(),
y = float32(),
z = float32()
- )) %>%
- transmute(c = coalesce(w, x, y, z)) %>%
+ )) |>
+ transmute(c = coalesce(w, x, y, z)) |>
compute()
)$schema[[1]]$type,
float32()
)
# with R literal values
expect_identical(
- arrow_table(df) %>%
+ arrow_table(df) |>
mutate(
c1 = coalesce(4.4),
c2 = coalesce(NA_real_),
@@ -471,7 +471,7 @@ test_that("coalesce()", {
c4 = coalesce(w, x, y, 5.5),
c5 = coalesce(w, x, y, NA_real_),
c6 = coalesce(w, x, y, NaN)
- ) %>%
+ ) |>
collect(),
mutate(
df,
@@ -496,14 +496,14 @@ test_that("external objects are found when they're not in the global environment
dat <- arrow_table(x = c("a", "b"))
pattern <- "a"
expect_identical(
- dat %>%
- mutate(x2 = case_when(x == pattern ~ "foo")) %>%
+ dat |>
+ mutate(x2 = case_when(x == pattern ~ "foo")) |>
collect(),
tibble(x = c("a", "b"), x2 = c("foo", NA))
)
expect_identical(
- dat %>%
- mutate(x2 = if_else(x == pattern, "foo", NA_character_)) %>%
+ dat |>
+ mutate(x2 = if_else(x == pattern, "foo", NA_character_)) |>
collect(),
tibble(x = c("a", "b"), x2 = c("foo", NA))
)
diff --git a/r/tests/testthat/test-dplyr-funcs-datetime.R b/r/tests/testthat/test-dplyr-funcs-datetime.R
index 27bfdcde9e..c904e0aa44 100644
--- a/r/tests/testthat/test-dplyr-funcs-datetime.R
+++ b/r/tests/testthat/test-dplyr-funcs-datetime.R
@@ -90,21 +90,21 @@ test_that("strptime", {
# as the current timezone. we test here if the strptime binding picks up
# correctly the current timezone (similarly to the base R version)
expect_equal(
- t_string %>%
- record_batch() %>%
+ t_string |>
+ record_batch() |>
mutate(
x = strptime(x, format = "%Y-%m-%d %H:%M:%S")
- ) %>%
+ ) |>
collect(),
t_stamp_with_pm_tz
)
expect_equal(
- t_string %>%
- record_batch() %>%
+ t_string |>
+ record_batch() |>
mutate(
x = base::strptime(x, format = "%Y-%m-%d %H:%M:%S")
- ) %>%
+ ) |>
collect(),
t_stamp_with_pm_tz
)
@@ -115,51 +115,51 @@ test_that("strptime", {
# this also tests that assigning a TZ different from the current session one
# works as expected
expect_equal(
- t_string %>%
- arrow_table() %>%
+ t_string |>
+ arrow_table() |>
mutate(
x = strptime(x, format = "%Y-%m-%d %H:%M:%S", tz = "Pacific/Marquesas")
- ) %>%
+ ) |>
collect(),
t_stamp_with_pm_tz
)
expect_equal(
- t_string %>%
- Table$create() %>%
+ t_string |>
+ Table$create() |>
mutate(
x = strptime(x, tz = "UTC")
- ) %>%
+ ) |>
collect(),
t_stamp_with_utc_tz
)
expect_equal(
- t_string %>%
- Table$create() %>%
+ t_string |>
+ Table$create() |>
mutate(
x = strptime(x, format = "%Y-%m-%d %H:%M:%S", tz = "UTC")
- ) %>%
+ ) |>
collect(),
t_stamp_with_utc_tz
)
expect_equal(
- t_string %>%
- Table$create() %>%
+ t_string |>
+ Table$create() |>
mutate(
x = strptime(x, format = "%Y-%m-%d %H:%M:%S", unit = "ns", tz = "UTC")
- ) %>%
+ ) |>
collect(),
t_stamp_with_utc_tz
)
expect_equal(
- t_string %>%
- Table$create() %>%
+ t_string |>
+ Table$create() |>
mutate(
x = strptime(x, format = "%Y-%m-%d %H:%M:%S", unit = "s", tz = "UTC")
- ) %>%
+ ) |>
collect(),
t_stamp_with_utc_tz
)
@@ -168,12 +168,12 @@ test_that("strptime", {
tstamp <- strptime(c("08-05-2008", NA), format = "%m-%d-%Y")
expect_equal(
- tstring %>%
- Table$create() %>%
+ tstring |>
+ Table$create() |>
mutate(
x = strptime(x, format = "%m-%d-%Y")
- ) %>%
- pull() %>%
+ ) |>
+ pull() |>
as.vector(),
# R's strptime returns POSIXlt (list type)
as.POSIXct(tstamp),
@@ -185,10 +185,10 @@ test_that("strptime", {
skip_if_not_available("re2")
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
parsed_date_ymd = parse_date_time(string_1, orders = "Y-%m-d-%T")
- ) %>%
+ ) |>
collect(),
tibble::tibble(string_1 = c("2022-02-11-12:23:45", NA))
)
@@ -203,8 +203,8 @@ test_that("strptime works for individual formats", {
skip_if_not_available("re2")
expect_equal(
- strptime_test_df %>%
- arrow_table() %>%
+ strptime_test_df |>
+ arrow_table() |>
mutate(
parsed_H = strptime(string_H, format = "%Y-%m-%d-%H"),
parsed_I = strptime(string_I, format = "%Y-%m-%d-%I"),
@@ -218,9 +218,9 @@ test_that("strptime works for individual formats", {
parsed_Y = strptime(string_Y, format = "%Y-%m-%d"),
parsed_R = strptime(string_R, format = "%Y-%m-%d-%R"),
parsed_T = strptime(string_T, format = "%Y-%m-%d-%T")
- ) %>%
+ ) |>
collect(),
- strptime_test_df %>%
+ strptime_test_df |>
mutate(
parsed_H = as.POSIXct(strptime(string_H, format = "%Y-%m-%d-%H")),
parsed_I = as.POSIXct(strptime(string_I, format = "%Y-%m-%d-%I")),
@@ -234,15 +234,15 @@ test_that("strptime works for individual formats", {
parsed_Y = as.POSIXct(strptime(string_Y, format = "%Y-%m-%d")),
parsed_R = as.POSIXct(strptime(string_R, format = "%Y-%m-%d-%R")),
parsed_T = as.POSIXct(strptime(string_T, format = "%Y-%m-%d-%T"))
- ) %>%
+ ) |>
collect()
)
# Some formats are not supported on Windows
skip_on_os("windows")
expect_equal(
- strptime_test_df %>%
- arrow_table() %>%
+ strptime_test_df |>
+ arrow_table() |>
mutate(
parsed_a = strptime(string_a, format = "%Y-%m-%d-%a"),
parsed_A = strptime(string_A, format = "%Y-%m-%d-%A"),
@@ -250,9 +250,9 @@ test_that("strptime works for individual formats", {
parsed_B = strptime(string_B, format = "%Y-%m-%d-%B"),
parsed_p = strptime(string_p, format = "%Y-%m-%d-%p"),
parsed_r = strptime(string_r, format = "%Y-%m-%d-%r")
- ) %>%
+ ) |>
collect(),
- strptime_test_df %>%
+ strptime_test_df |>
mutate(
parsed_a = as.POSIXct(strptime(string_a, format = "%Y-%m-%d-%a")),
parsed_A = as.POSIXct(strptime(string_A, format = "%Y-%m-%d-%A")),
@@ -260,7 +260,7 @@ test_that("strptime works for individual formats", {
parsed_B = as.POSIXct(strptime(string_B, format = "%Y-%m-%d-%B")),
parsed_p = as.POSIXct(strptime(string_p, format = "%Y-%m-%d-%p")),
parsed_r = as.POSIXct(strptime(string_r, format = "%Y-%m-%d-%r"))
- ) %>%
+ ) |>
collect()
)
})
@@ -301,12 +301,12 @@ test_that("timestamp round trip correctly via strftime and strptime", {
fmt <- paste(base_format, fmt)
test_df <- tibble::tibble(x = strftime(times, format = fmt))
expect_equal(
- test_df %>%
- arrow_table() %>%
- mutate(!!fmt := strptime(x, format = fmt)) %>%
+ test_df |>
+ arrow_table() |>
+ mutate(!!fmt := strptime(x, format = fmt)) |>
collect(),
- test_df %>%
- mutate(!!fmt := as.POSIXct(strptime(x, format = fmt))) %>%
+ test_df |>
+ mutate(!!fmt := as.POSIXct(strptime(x, format = fmt))) |>
collect()
)
}
@@ -316,12 +316,12 @@ test_that("timestamp round trip correctly via strftime and strptime", {
fmt <- paste(base_format, paste0("%", fmt))
test_df <- tibble::tibble(x = strftime(times, format = fmt))
expect_equal_data_frame(
- test_df %>%
- arrow_table() %>%
- mutate(!!fmt := strptime(x, format = fmt2)) %>%
+ test_df |>
+ arrow_table() |>
+ mutate(!!fmt := strptime(x, format = fmt2)) |>
collect(),
- test_df %>%
- mutate(!!fmt := as.POSIXct(strptime(x, format = fmt2))) %>%
+ test_df |>
+ mutate(!!fmt := as.POSIXct(strptime(x, format = fmt2))) |>
collect()
)
}
@@ -335,14 +335,14 @@ test_that("strptime returns NA when format doesn't match the data", {
# base::strptime() returns a POSIXlt object (a list), while the Arrow binding
# returns a POSIXct (double) vector => we cannot use compare_dplyr_binding()
expect_equal(
- df %>%
- arrow_table() %>%
+ df |>
+ arrow_table() |>
mutate(
r_obj_parsed_date = strptime("03-27/2022", format = "%m-%d/%Y"),
r_obj_parsed_na = strptime("03-27/2022", format = "Y%-%m-%d")
- ) %>%
+ ) |>
collect(),
- df %>%
+ df |>
mutate(
r_obj_parsed_date = as.POSIXct(strptime("03-27/2022", format = "%m-%d/%Y")),
r_obj_parsed_na = as.POSIXct(strptime("03-27/2022", format = "Y%-%m-%d"))
@@ -351,21 +351,21 @@ test_that("strptime returns NA when format doesn't match the data", {
)
expect_equal(
- df %>%
- record_batch() %>%
- mutate(parsed_date = strptime(str_date, format = "%Y-%m-%d")) %>%
+ df |>
+ record_batch() |>
+ mutate(parsed_date = strptime(str_date, format = "%Y-%m-%d")) |>
collect(),
- df %>%
+ df |>
mutate(parsed_date = as.POSIXct(strptime(str_date, format = "%Y-%m-%d"))),
ignore_attr = "tzone"
)
expect_equal(
- df %>%
- arrow_table() %>%
- mutate(parsed_date = strptime(str_date, format = "%Y/%m-%d")) %>%
+ df |>
+ arrow_table() |>
+ mutate(parsed_date = strptime(str_date, format = "%Y/%m-%d")) |>
collect(),
- df %>%
+ df |>
mutate(parsed_date = as.POSIXct(strptime(str_date, format = "%Y/%m-%d"))),
ignore_attr = "tzone"
)
@@ -380,32 +380,32 @@ test_that("strftime", {
formats_date <- "%a %A %w %d %b %B %m %y %Y %H %I %p %M %j %U %W %x %X %% %G %V %u"
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = strftime(datetime, format = formats),
x2 = base::strftime(datetime, format = formats)
- ) %>%
+ ) |>
collect(),
times
)
compare_dplyr_binding(
- .input %>%
- mutate(x = strftime(date, format = formats_date)) %>%
+ .input |>
+ mutate(x = strftime(date, format = formats_date)) |>
collect(),
times
)
compare_dplyr_binding(
- .input %>%
- mutate(x = strftime(datetime, format = formats, tz = "Pacific/Marquesas")) %>%
+ .input |>
+ mutate(x = strftime(datetime, format = formats, tz = "Pacific/Marquesas")) |>
collect(),
times
)
compare_dplyr_binding(
- .input %>%
- mutate(x = strftime(datetime, format = formats, tz = "EST", usetz = TRUE)) %>%
+ .input |>
+ mutate(x = strftime(datetime, format = formats, tz = "EST", usetz = TRUE)) |>
collect(),
times
)
@@ -414,21 +414,21 @@ test_that("strftime", {
"Pacific/Marquesas",
{
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = strftime(datetime, format = formats, tz = "EST"),
x_date = strftime(date, format = formats_date, tz = "EST")
- ) %>%
+ ) |>
collect(),
times
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = strftime(datetime, format = formats),
x_date = strftime(date, format = formats_date)
- ) %>%
+ ) |>
collect(),
times
)
@@ -439,9 +439,9 @@ test_that("strftime", {
# We can revisit after https://github.com/HowardHinnant/date/issues/704 is resolved.
if (Sys.getlocale("LC_TIME") != "C") {
expect_error(
- times %>%
- Table$create() %>%
- mutate(x = strftime(datetime, format = "%c")) %>%
+ times |>
+ Table$create() |>
+ mutate(x = strftime(datetime, format = "%c")) |>
collect(),
"%c flag is not supported in non-C locales."
)
@@ -452,9 +452,9 @@ test_that("strftime", {
# milliseconds, microsecond and nanoseconds are represented as fixed floating
# point numbers with 3, 6 and 9 decimal places respectively.
compare_dplyr_binding(
- .input %>%
- mutate(x = strftime(datetime, format = "%S")) %>%
- transmute(as.double(substr(x, 1, 2))) %>%
+ .input |>
+ mutate(x = strftime(datetime, format = "%S")) |>
+ transmute(as.double(substr(x, 1, 2))) |>
collect(),
times,
tolerance = 1e-6
@@ -473,11 +473,11 @@ test_that("format_ISO8601", {
times <- tibble(x = c(lubridate::ymd_hms("2018-10-07 19:04:05", tz = "Etc/GMT+6"), NA))
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
a = format_ISO8601(x, precision = "ymd", usetz = FALSE),
a2 = lubridate::format_ISO8601(x, precision = "ymd", usetz = FALSE)
- ) %>%
+ ) |>
collect(),
times
)
@@ -486,35 +486,35 @@ test_that("format_ISO8601", {
# before 3.5, times$x will have no timezone attribute, so Arrow faithfully
# errors that there is no timezone to format:
expect_error(
- times %>%
- Table$create() %>%
- mutate(x = format_ISO8601(x, precision = "ymd", usetz = TRUE)) %>%
+ times |>
+ Table$create() |>
+ mutate(x = format_ISO8601(x, precision = "ymd", usetz = TRUE)) |>
collect(),
"Timezone not present, cannot convert to string with timezone: %Y-%m-%d%z"
)
# See comment regarding %S flag in strftime tests
expect_error(
- times %>%
- Table$create() %>%
- mutate(x = format_ISO8601(x, precision = "ymdhms", usetz = TRUE)) %>%
- mutate(x = gsub("\\.0*", "", x)) %>%
+ times |>
+ Table$create() |>
+ mutate(x = format_ISO8601(x, precision = "ymdhms", usetz = TRUE)) |>
+ mutate(x = gsub("\\.0*", "", x)) |>
collect(),
"Timezone not present, cannot convert to string with timezone: %Y-%m-%dT%H:%M:%S%z"
)
} else {
compare_dplyr_binding(
- .input %>%
- mutate(x = format_ISO8601(x, precision = "ymd", usetz = TRUE)) %>%
+ .input |>
+ mutate(x = format_ISO8601(x, precision = "ymd", usetz = TRUE)) |>
collect(),
times
)
# See comment regarding %S flag in strftime tests
compare_dplyr_binding(
- .input %>%
- mutate(x = format_ISO8601(x, precision = "ymdhms", usetz = TRUE)) %>%
- mutate(x = gsub("\\.0*", "", x)) %>%
+ .input |>
+ mutate(x = format_ISO8601(x, precision = "ymdhms", usetz = TRUE)) |>
+ mutate(x = gsub("\\.0*", "", x)) |>
collect(),
times
)
@@ -523,9 +523,9 @@ test_that("format_ISO8601", {
# See comment regarding %S flag in strftime tests
compare_dplyr_binding(
- .input %>%
- mutate(x = format_ISO8601(x, precision = "ymdhms", usetz = FALSE)) %>%
- mutate(x = gsub("\\.0*", "", x)) %>%
+ .input |>
+ mutate(x = format_ISO8601(x, precision = "ymdhms", usetz = FALSE)) |>
+ mutate(x = gsub("\\.0*", "", x)) |>
collect(),
times
)
@@ -536,40 +536,40 @@ test_that("format_ISO8601", {
test_that("is.* functions from lubridate", {
# make sure all true and at least one false value is considered
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = is.POSIXct(datetime),
y = is.POSIXct(integer),
x2 = lubridate::is.POSIXct(datetime)
- ) %>%
+ ) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = is.Date(date),
y = is.Date(integer),
x2 = lubridate::is.Date(date)
- ) %>%
+ ) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = is.instant(datetime),
y = is.instant(date),
z = is.instant(integer)
- ) %>%
+ ) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = is.timepoint(datetime),
y = is.instant(date),
@@ -577,7 +577,7 @@ test_that("is.* functions from lubridate", {
x2 = lubridate::is.timepoint(datetime),
y2 = lubridate::is.instant(date),
z2 = lubridate::is.timepoint(integer)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -587,8 +587,8 @@ test_that("is.* functions from lubridate", {
test_that("extract year from timestamp", {
compare_dplyr_binding(
- .input %>%
- mutate(x = year(datetime)) %>%
+ .input |>
+ mutate(x = year(datetime)) |>
collect(),
test_df
)
@@ -596,8 +596,8 @@ test_that("extract year from timestamp", {
test_that("extract isoyear from timestamp", {
compare_dplyr_binding(
- .input %>%
- mutate(x = isoyear(datetime)) %>%
+ .input |>
+ mutate(x = isoyear(datetime)) |>
collect(),
test_df
)
@@ -605,11 +605,11 @@ test_that("extract isoyear from timestamp", {
test_that("extract epiyear from timestamp", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = epiyear(datetime),
x2 = lubridate::epiyear(datetime)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -617,8 +617,8 @@ test_that("extract epiyear from timestamp", {
test_that("extract quarter from timestamp", {
compare_dplyr_binding(
- .input %>%
- mutate(x = quarter(datetime)) %>%
+ .input |>
+ mutate(x = quarter(datetime)) |>
collect(),
test_df
)
@@ -626,27 +626,27 @@ test_that("extract quarter from timestamp", {
test_that("extract month from timestamp", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = month(datetime),
x2 = lubridate::month(datetime)
- ) %>%
+ ) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
# R returns ordered factor whereas Arrow returns character
- mutate(x = as.character(month(datetime, label = TRUE))) %>%
+ mutate(x = as.character(month(datetime, label = TRUE))) |>
collect(),
test_df,
ignore_attr = TRUE
)
compare_dplyr_binding(
- .input %>%
- mutate(x = as.character(month(datetime, label = TRUE, abbr = TRUE))) %>%
+ .input |>
+ mutate(x = as.character(month(datetime, label = TRUE, abbr = TRUE))) |>
collect(),
test_df,
ignore_attr = TRUE
@@ -655,11 +655,11 @@ test_that("extract month from timestamp", {
test_that("extract isoweek from timestamp", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = isoweek(datetime),
x2 = lubridate::isoweek(datetime)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -667,8 +667,8 @@ test_that("extract isoweek from timestamp", {
test_that("extract epiweek from timestamp", {
compare_dplyr_binding(
- .input %>%
- mutate(x = epiweek(datetime)) %>%
+ .input |>
+ mutate(x = epiweek(datetime)) |>
collect(),
test_df
)
@@ -676,11 +676,11 @@ test_that("extract epiweek from timestamp", {
test_that("extract week from timestamp", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = week(datetime),
x2 = lubridate::week(datetime)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -688,8 +688,8 @@ test_that("extract week from timestamp", {
test_that("extract day from timestamp", {
compare_dplyr_binding(
- .input %>%
- mutate(x = day(datetime)) %>%
+ .input |>
+ mutate(x = day(datetime)) |>
collect(),
test_df
)
@@ -697,38 +697,38 @@ test_that("extract day from timestamp", {
test_that("extract wday from timestamp", {
compare_dplyr_binding(
- .input %>%
- mutate(x = wday(datetime)) %>%
+ .input |>
+ mutate(x = wday(datetime)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = wday(date, week_start = 3)) %>%
+ .input |>
+ mutate(x = wday(date, week_start = 3)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = wday(date, week_start = 1)) %>%
+ .input |>
+ mutate(x = wday(date, week_start = 1)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = wday(date, label = TRUE)) %>%
- mutate(x = as.character(x)) %>%
+ .input |>
+ mutate(x = wday(date, label = TRUE)) |>
+ mutate(x = as.character(x)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = wday(datetime, label = TRUE, abbr = TRUE)) %>%
- mutate(x = as.character(x)) %>%
+ .input |>
+ mutate(x = wday(datetime, label = TRUE, abbr = TRUE)) |>
+ mutate(x = as.character(x)) |>
collect(),
test_df
)
@@ -736,8 +736,8 @@ test_that("extract wday from timestamp", {
test_that("extract mday from timestamp", {
compare_dplyr_binding(
- .input %>%
- mutate(x = mday(datetime)) %>%
+ .input |>
+ mutate(x = mday(datetime)) |>
collect(),
test_df
)
@@ -745,11 +745,11 @@ test_that("extract mday from timestamp", {
test_that("extract yday from timestamp", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = yday(datetime),
x2 = lubridate::yday(datetime)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -761,15 +761,15 @@ test_that("extract qday from timestamp", {
)
compare_dplyr_binding(
- .input %>%
- transmute(x = qday(time)) %>%
+ .input |>
+ transmute(x = qday(time)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- transmute(x = qday(as.POSIXct("2022-06-29 12:35"))) %>%
+ .input |>
+ transmute(x = qday(as.POSIXct("2022-06-29 12:35"))) |>
collect(),
test_df
)
@@ -777,11 +777,11 @@ test_that("extract qday from timestamp", {
test_that("extract hour from timestamp", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = hour(datetime),
x2 = lubridate::hour(datetime)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -789,11 +789,11 @@ test_that("extract hour from timestamp", {
test_that("extract minute from timestamp", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = minute(datetime),
x2 = lubridate::minute(datetime)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -801,11 +801,11 @@ test_that("extract minute from timestamp", {
test_that("extract second from timestamp", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = second(datetime),
x2 = lubridate::second(datetime)
- ) %>%
+ ) |>
collect(),
test_df,
# arrow supports nanosecond resolution but lubridate does not
@@ -817,11 +817,11 @@ test_that("extract second from timestamp", {
test_that("extract year from date", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = year(date),
x2 = lubridate::year(date)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -829,11 +829,11 @@ test_that("extract year from date", {
test_that("extract isoyear from date", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = isoyear(date),
x2 = lubridate::isoyear(date)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -841,8 +841,8 @@ test_that("extract isoyear from date", {
test_that("extract epiyear from date", {
compare_dplyr_binding(
- .input %>%
- mutate(x = epiyear(date)) %>%
+ .input |>
+ mutate(x = epiyear(date)) |>
collect(),
test_df
)
@@ -850,11 +850,11 @@ test_that("extract epiyear from date", {
test_that("extract quarter from date", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = quarter(date),
x2 = lubridate::quarter(date)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -862,8 +862,8 @@ test_that("extract quarter from date", {
test_that("extract isoweek from date", {
compare_dplyr_binding(
- .input %>%
- mutate(x = isoweek(date)) %>%
+ .input |>
+ mutate(x = isoweek(date)) |>
collect(),
test_df
)
@@ -871,11 +871,11 @@ test_that("extract isoweek from date", {
test_that("extract epiweek from date", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = epiweek(date),
x2 = lubridate::epiweek(date)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -883,8 +883,8 @@ test_that("extract epiweek from date", {
test_that("extract week from date", {
compare_dplyr_binding(
- .input %>%
- mutate(x = week(date)) %>%
+ .input |>
+ mutate(x = week(date)) |>
collect(),
test_df
)
@@ -892,24 +892,24 @@ test_that("extract week from date", {
test_that("extract month from date", {
compare_dplyr_binding(
- .input %>%
- mutate(x = month(date)) %>%
+ .input |>
+ mutate(x = month(date)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
# R returns ordered factor whereas Arrow returns character
- mutate(x = as.character(month(date, label = TRUE))) %>%
+ mutate(x = as.character(month(date, label = TRUE))) |>
collect(),
test_df,
ignore_attr = TRUE
)
compare_dplyr_binding(
- .input %>%
- mutate(x = as.character(month(date, label = TRUE, abbr = TRUE))) %>%
+ .input |>
+ mutate(x = as.character(month(date, label = TRUE, abbr = TRUE))) |>
collect(),
test_df,
ignore_attr = TRUE
@@ -918,11 +918,11 @@ test_that("extract month from date", {
test_that("extract day from date", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = day(date),
x2 = lubridate::day(date)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -930,41 +930,41 @@ test_that("extract day from date", {
test_that("extract wday from date", {
compare_dplyr_binding(
- .input %>%
- mutate(x = wday(date)) %>%
+ .input |>
+ mutate(x = wday(date)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = wday(date, week_start = 3),
x2 = lubridate::wday(date, week_start = 3)
- ) %>%
+ ) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = wday(date, week_start = 1)) %>%
+ .input |>
+ mutate(x = wday(date, week_start = 1)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = wday(date, label = TRUE, abbr = TRUE)) %>%
- mutate(x = as.character(x)) %>%
+ .input |>
+ mutate(x = wday(date, label = TRUE, abbr = TRUE)) |>
+ mutate(x = as.character(x)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = wday(date, label = TRUE)) %>%
- mutate(x = as.character(x)) %>%
+ .input |>
+ mutate(x = wday(date, label = TRUE)) |>
+ mutate(x = as.character(x)) |>
collect(),
test_df
)
@@ -972,11 +972,11 @@ test_that("extract wday from date", {
test_that("extract mday from date", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = mday(date),
x2 = lubridate::mday(date)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -984,8 +984,8 @@ test_that("extract mday from date", {
test_that("extract yday from date", {
compare_dplyr_binding(
- .input %>%
- mutate(x = yday(date)) %>%
+ .input |>
+ mutate(x = yday(date)) |>
collect(),
test_df
)
@@ -997,15 +997,15 @@ test_that("extract qday from date", {
)
compare_dplyr_binding(
- .input %>%
- mutate(x = qday(date)) %>%
+ .input |>
+ mutate(x = qday(date)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = qday(as.Date("2022-06-29"))) %>%
+ .input |>
+ mutate(y = qday(as.Date("2022-06-29"))) |>
collect(),
test_df
)
@@ -1013,25 +1013,25 @@ test_that("extract qday from date", {
test_that("leap_year mirror lubridate", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = leap_year(date),
x2 = lubridate::leap_year(date)
- ) %>%
+ ) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = leap_year(datetime)) %>%
+ .input |>
+ mutate(x = leap_year(datetime)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = leap_year(test_year)) %>%
+ .input |>
+ mutate(x = leap_year(test_year)) |>
collect(),
tibble::tibble(
test_year = as.Date(c(
@@ -1046,13 +1046,13 @@ test_that("leap_year mirror lubridate", {
test_that("am/pm mirror lubridate", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
am = am(test_time),
pm = pm(test_time),
am2 = lubridate::am(test_time),
pm2 = lubridate::pm(test_time)
- ) %>%
+ ) |>
# can't use collect() here due to how tibbles store datetimes
# TODO: add better explanation above
as.data.frame(),
@@ -1075,11 +1075,11 @@ test_that("extract tz", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
timezone_posixct_date = tz(posixct_date),
timezone_posixct_date2 = lubridate::tz(posixct_date)
- ) %>%
+ ) |>
collect(),
df
)
@@ -1119,27 +1119,27 @@ test_that("semester works with temporal types and integers", {
# semester extraction from dates
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
sem_wo_year = semester(dates),
sem_wo_year2 = lubridate::semester(dates),
sem_w_year = semester(dates, with_year = TRUE)
- ) %>%
+ ) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(sem_month_as_int = semester(month_as_int)) %>%
+ .input |>
+ mutate(sem_month_as_int = semester(month_as_int)) |>
collect(),
test_df
)
expect_error(
- test_df %>%
- arrow_table() %>%
- mutate(sem_month_as_char_pad = semester(month_as_char_pad)) %>%
+ test_df |>
+ arrow_table() |>
+ mutate(sem_month_as_char_pad = semester(month_as_char_pad)) |>
collect(),
regexp = "NotImplemented: Function 'month' has no kernel matching input types (string)",
fixed = TRUE
@@ -1152,11 +1152,11 @@ test_that("dst extracts daylight savings time correctly", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
dst = dst(dates),
dst2 = lubridate::dst(dates)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -1168,30 +1168,30 @@ test_that("month() supports integer input", {
)
compare_dplyr_binding(
- .input %>%
- mutate(month_int_input = month(month_as_int)) %>%
+ .input |>
+ mutate(month_int_input = month(month_as_int)) |>
collect(),
test_df_month
)
compare_dplyr_binding(
- .input %>%
+ .input |>
# R returns ordered factor whereas Arrow returns character
mutate(
month_int_input = as.character(month(month_as_int, label = TRUE))
- ) %>%
+ ) |>
collect(),
test_df_month
)
compare_dplyr_binding(
- .input %>%
+ .input |>
# R returns ordered factor whereas Arrow returns character
mutate(
month_int_input = as.character(
month(month_as_int, label = TRUE, abbr = FALSE)
)
- ) %>%
+ ) |>
collect(),
test_df_month
)
@@ -1204,10 +1204,10 @@ test_that("month() errors with double input and returns NA with int outside 1:12
)
expect_equal(
- test_df_month %>%
- arrow_table() %>%
- select(month_as_int) %>%
- mutate(month_int_input = month(month_as_int)) %>%
+ test_df_month |>
+ arrow_table() |>
+ select(month_as_int) |>
+ mutate(month_int_input = month(month_as_int)) |>
collect(),
tibble(
month_as_int = c(-1L, 1L, 13L, NA),
@@ -1216,18 +1216,18 @@ test_that("month() errors with double input and returns NA with int outside 1:12
)
expect_error(
- test_df_month %>%
- arrow_table() %>%
- mutate(month_dbl_input = month(month_as_double)) %>%
+ test_df_month |>
+ arrow_table() |>
+ mutate(month_dbl_input = month(month_as_double)) |>
collect(),
regexp = "Function 'month' has no kernel matching input types (double)",
fixed = TRUE
)
expect_error(
- test_df_month %>%
- record_batch() %>%
- mutate(month_dbl_input = month(month_as_double)) %>%
+ test_df_month |>
+ record_batch() |>
+ mutate(month_dbl_input = month(month_as_double)) |>
collect(),
regexp = "Function 'month' has no kernel matching input types (double)",
fixed = TRUE
@@ -1246,36 +1246,36 @@ test_that("date works in arrow", {
r_date_object <- lubridate::ymd_hms("2012-03-26 23:12:13")
compare_dplyr_binding(
- .input %>%
- mutate(a_date = lubridate::date(posixct_date)) %>%
+ .input |>
+ mutate(a_date = lubridate::date(posixct_date)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(a_date_base = as.Date(posixct_date)) %>%
+ .input |>
+ mutate(a_date_base = as.Date(posixct_date)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(a_date_base = as.Date(posixct_fractional_second)) %>%
+ .input |>
+ mutate(a_date_base = as.Date(posixct_fractional_second)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(date_from_r_object = lubridate::date(r_date_object)) %>%
+ .input |>
+ mutate(date_from_r_object = lubridate::date(r_date_object)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(as_date_from_r_object = as.Date(r_date_object)) %>%
+ .input |>
+ mutate(as_date_from_r_object = as.Date(r_date_object)) |>
collect(),
test_df
)
@@ -1284,10 +1284,10 @@ test_that("date works in arrow", {
# Arrow it assumes a fixed origin "1970-01-01". However this is not supported
# by lubridate. lubridate::date(integer_var) errors without an `origin`
expect_equal(
- test_df %>%
- arrow_table() %>%
- select(integer_var) %>%
- mutate(date_int = date(integer_var)) %>%
+ test_df |>
+ arrow_table() |>
+ select(integer_var) |>
+ mutate(date_int = date(integer_var)) |>
collect(),
tibble(
integer_var = c(32L, NA),
@@ -1301,9 +1301,9 @@ test_that("date() errors with unsupported inputs", {
# The lubridate version errors too.
skip_if_not_available("dataset")
expect_error(
- example_data %>%
- InMemoryDataset$create() %>%
- mutate(date_bool = lubridate::date(TRUE)) %>%
+ example_data |>
+ InMemoryDataset$create() |>
+ mutate(date_bool = lubridate::date(TRUE)) |>
collect(),
regexp = "Unsupported cast from bool to date32 using function cast_date32"
)
@@ -1317,32 +1317,32 @@ test_that("make_date & make_datetime", {
hour = c(0, 7, 23, NA),
min = c(0, 59, NA),
sec = c(0, 59, NA)
- ) %>%
+ ) |>
tibble()
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
composed_date = make_date(year, month, day),
composed_date2 = lubridate::make_date(year, month, day)
- ) %>%
+ ) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(composed_date_r_obj = make_date(1999, 12, 31)) %>%
+ .input |>
+ mutate(composed_date_r_obj = make_date(1999, 12, 31)) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
composed_datetime = make_datetime(year, month, day, hour, min, sec),
composed_datetime2 = lubridate::make_datetime(year, month, day, hour, min, sec)
- ) %>%
+ ) |>
collect(),
test_df,
# the make_datetime binding uses strptime which does not support tz, hence
@@ -1351,10 +1351,10 @@ test_that("make_date & make_datetime", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
composed_datetime_r_obj = make_datetime(1999, 12, 31, 14, 15, 16)
- ) %>%
+ ) |>
collect(),
test_df,
# the make_datetime binding uses strptime which does not support tz, hence
@@ -1371,15 +1371,15 @@ test_that("ISO_datetime & ISOdate", {
hour = c(0, 7, 23, NA),
min = c(0, 59, NA),
sec = c(0, 59, NA)
- ) %>%
+ ) |>
tibble()
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
composed_date = ISOdate(year, month, day),
composed_date2 = base::ISOdate(year, month, day)
- ) %>%
+ ) |>
collect(),
test_df,
# the make_datetime binding uses strptime which does not support tz, hence
@@ -1388,8 +1388,8 @@ test_that("ISO_datetime & ISOdate", {
)
compare_dplyr_binding(
- .input %>%
- mutate(composed_date_r_obj = ISOdate(1999, 12, 31)) %>%
+ .input |>
+ mutate(composed_date_r_obj = ISOdate(1999, 12, 31)) |>
collect(),
test_df,
# the make_datetime binding uses strptime which does not support tz, hence
@@ -1399,11 +1399,11 @@ test_that("ISO_datetime & ISOdate", {
# the default `tz` for base::ISOdatetime is "", but in Arrow it's "UTC"
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
composed_datetime = ISOdatetime(year, month, day, hour, min, sec, tz = "UTC"),
composed_datetime2 = base::ISOdatetime(year, month, day, hour, min, sec, tz = "UTC")
- ) %>%
+ ) |>
collect(),
test_df,
# the make_datetime binding uses strptime which does not support tz, hence
@@ -1412,10 +1412,10 @@ test_that("ISO_datetime & ISOdate", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
composed_datetime_r_obj = ISOdatetime(1999, 12, 31, 14, 15, 16)
- ) %>%
+ ) |>
collect(),
test_df,
# the make_datetime binding uses strptime which does not support tz, hence
@@ -1436,11 +1436,11 @@ test_that("difftime()", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
secs = difftime(time1, time2, units = "secs"),
secs2 = base::difftime(time1, time2, units = "secs")
- ) %>%
+ ) |>
collect(),
test_df,
ignore_attr = TRUE
@@ -1448,10 +1448,10 @@ test_that("difftime()", {
# units other than "secs" not supported in arrow
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
mins = difftime(time1, time2, units = "mins")
- ) %>%
+ ) |>
collect(),
test_df,
warning = TRUE,
@@ -1471,29 +1471,29 @@ test_that("difftime()", {
)
compare_dplyr_binding(
- .input %>%
- mutate(secs2 = difftime(time2, time1, units = "secs")) %>%
+ .input |>
+ mutate(secs2 = difftime(time2, time1, units = "secs")) |>
collect(),
test_df_with_tz
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
secs2 = difftime(
as.POSIXct("2022-03-07", tz = "Pacific/Marquesas"),
time1,
units = "secs"
)
- ) %>%
+ ) |>
collect(),
test_df_with_tz
)
# `tz` is effectively ignored both in R (used only if inputs are POSIXlt) and Arrow
compare_dplyr_binding(
- .input %>%
- mutate(secs2 = difftime(time2, time1, units = "secs", tz = "Pacific/Marquesas")) %>%
+ .input |>
+ mutate(secs2 = difftime(time2, time1, units = "secs", tz = "Pacific/Marquesas")) |>
collect(),
test_df_with_tz,
warning = "`tz` argument is not supported in Arrow, so it will be ignored"
@@ -1510,11 +1510,11 @@ test_that("as.difftime()", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
hms_difftime = as.difftime(hms_string, units = "secs"),
hms_difftime2 = base::as.difftime(hms_string, units = "secs")
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -1523,30 +1523,30 @@ test_that("as.difftime()", {
# https://issues.apache.org/jira/browse/ARROW-15659 is solved
# for example: as.difftime("07:", format = "%H:%M") should return NA
compare_dplyr_binding(
- .input %>%
- mutate(hm_difftime = as.difftime(hm_string, units = "secs", format = "%H:%M")) %>%
+ .input |>
+ mutate(hm_difftime = as.difftime(hm_string, units = "secs", format = "%H:%M")) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(int_difftime = as.difftime(int, units = "secs")) %>%
+ .input |>
+ mutate(int_difftime = as.difftime(int, units = "secs")) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
- mutate(integerish_dbl_difftime = as.difftime(integerish_dbl, units = "secs")) %>%
+ .input |>
+ mutate(integerish_dbl_difftime = as.difftime(integerish_dbl, units = "secs")) |>
collect(),
test_df
)
# "mins" or other values for units cannot be handled in Arrow
compare_dplyr_binding(
- .input %>%
- mutate(int_difftime = as.difftime(int, units = "mins")) %>%
+ .input |>
+ mutate(int_difftime = as.difftime(int, units = "mins")) |>
collect(),
test_df,
warning = TRUE
@@ -1557,9 +1557,9 @@ test_that("as.difftime()", {
# error message as it is being generated in the C++ code and it might change,
# but we want to make sure that this error is raised in our binding implementation
expect_error(
- test_df %>%
- arrow_table() %>%
- mutate(dbl_difftime = as.difftime(dbl, units = "secs")) %>%
+ test_df |>
+ arrow_table() |>
+ mutate(dbl_difftime = as.difftime(dbl, units = "secs")) |>
collect()
)
})
@@ -1582,7 +1582,7 @@ test_that("`decimal_date()` and `date_decimal()`", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
decimal_date_from_POSIXct = decimal_date(b),
decimal_date_from_POSIXct2 = lubridate::decimal_date(b),
@@ -1592,7 +1592,7 @@ test_that("`decimal_date()` and `date_decimal()`", {
date_from_decimal = date_decimal(a),
date_from_decimal2 = lubridate::date_decimal(a),
date_from_decimal_r_obj = date_decimal(2022.178)
- ) %>%
+ ) |>
collect(),
test_df,
ignore_attr = "tzone"
@@ -1609,7 +1609,7 @@ test_that("dminutes, dhours, ddays, dweeks, dmonths, dyears", {
# attribute 'units' (character vector ('secs') vs. absent)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
dminutes = dminutes(x),
dhours = dhours(x),
@@ -1617,28 +1617,28 @@ test_that("dminutes, dhours, ddays, dweeks, dmonths, dyears", {
dweeks = dweeks(x),
dmonths = dmonths(x),
dyears = dyears(x)
- ) %>%
+ ) |>
collect(),
example_d,
ignore_attr = TRUE
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
dhours = dhours(x),
ddays = ddays(x),
new_date_1 = date_to_add + ddays,
new_date_2 = date_to_add + ddays - dhours(3),
new_duration = dhours - ddays
- ) %>%
+ ) |>
collect(),
example_d,
ignore_attr = TRUE
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
r_obj_dminutes = dminutes(1),
r_obj_dhours = dhours(2),
@@ -1652,7 +1652,7 @@ test_that("dminutes, dhours, ddays, dweeks, dmonths, dyears", {
r_obj_dweeks2 = lubridate::dweeks(4),
r_obj_dmonths2 = lubridate::dmonths(5),
r_obj_dyears2 = lubridate::dyears(6)
- ) %>%
+ ) |>
collect(),
tibble(),
ignore_attr = TRUE
@@ -1661,16 +1661,16 @@ test_that("dminutes, dhours, ddays, dweeks, dmonths, dyears", {
# double -> duration not supported in Arrow.
# With a scalar, cast to int64 error in mutate() -> abandon_ship warning
expect_warning(
- test_df %>%
- arrow_table() %>%
+ test_df |>
+ arrow_table() |>
mutate(r_obj_dminutes = dminutes(1.12345)),
"not supported in Arrow"
)
# When operating on a column, it doesn't happen until collect()
expect_error(
- arrow_table(dbl = 1.948230) %>%
- mutate(r_obj_dminutes = dminutes(dbl)) %>%
+ arrow_table(dbl = 1.948230) |>
+ mutate(r_obj_dminutes = dminutes(dbl)) |>
collect(),
"truncated converting to int64"
)
@@ -1686,7 +1686,7 @@ test_that("dseconds, dmilliseconds, dmicroseconds, dnanoseconds, dpicoseconds",
# attribute 'units' (character vector ('secs') vs. absent)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
dseconds = dseconds(x),
dmilliseconds = dmilliseconds(x),
@@ -1696,34 +1696,34 @@ test_that("dseconds, dmilliseconds, dmicroseconds, dnanoseconds, dpicoseconds",
dmilliseconds2 = lubridate::dmilliseconds(x),
dmicroseconds2 = lubridate::dmicroseconds(x),
dnanoseconds2 = lubridate::dnanoseconds(x),
- ) %>%
+ ) |>
collect(),
example_d,
ignore_attr = TRUE
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
dseconds = dseconds(x),
dmicroseconds = dmicroseconds(x),
new_date_1 = date_to_add + dseconds,
new_date_2 = date_to_add + dseconds - dmicroseconds,
new_duration = dseconds - dmicroseconds
- ) %>%
+ ) |>
collect(),
example_d,
ignore_attr = TRUE
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
r_obj_dseconds = dseconds(1),
r_obj_dmilliseconds = dmilliseconds(2),
r_obj_dmicroseconds = dmicroseconds(3),
r_obj_dnanoseconds = dnanoseconds(4)
- ) %>%
+ ) |>
collect(),
tibble(),
ignore_attr = TRUE
@@ -1751,7 +1751,7 @@ test_that("make_difftime()", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
duration_from_parts = make_difftime(
second = seconds,
@@ -1783,7 +1783,7 @@ test_that("make_difftime()", {
week = weeks,
units = "secs"
)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -1792,11 +1792,11 @@ test_that("make_difftime()", {
# are not supported
expect_error(
expect_warning(
- test_df %>%
- arrow_table() %>%
+ test_df |>
+ arrow_table() |>
mutate(
err_difftime = make_difftime(month = 2)
- ) %>%
+ ) |>
collect(),
paste0(
"named `difftime` units other than: `second`, `minute`, `hour`,",
@@ -1808,8 +1808,8 @@ test_that("make_difftime()", {
# units other than "secs" not supported since they are the only ones in common
# between R and Arrow
compare_dplyr_binding(
- .input %>%
- mutate(error_difftime = make_difftime(num = number, units = "mins")) %>%
+ .input |>
+ mutate(error_difftime = make_difftime(num = number, units = "mins")) |>
collect(),
test_df,
warning = TRUE
@@ -1820,8 +1820,8 @@ test_that("make_difftime()", {
# resulting objects), it errors in a dplyr context
expect_error(
expect_warning(
- test_df %>%
- arrow_table() %>%
+ test_df |>
+ arrow_table() |>
mutate(
duration_from_num_and_parts = make_difftime(
num = number,
@@ -1832,7 +1832,7 @@ test_that("make_difftime()", {
week = weeks,
units = "secs"
)
- ) %>%
+ ) |>
collect(),
"with both `num` and `...` not supported in Arrow"
)
@@ -1857,7 +1857,7 @@ test_that("`as.Date()` and `as_date()`", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
date_dv1 = as.Date(date_var),
date_dv1_nmspc = base::as.Date(date_var),
@@ -1881,7 +1881,7 @@ test_that("`as.Date()` and `as_date()`", {
date_int2 = as_date(integer_var, origin = "1970-01-01"),
date_int_origin2 = as_date(integer_var, origin = "1970-01-03"),
date_integerish2 = as_date(integerish_var, origin = "1970-01-01")
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -1891,12 +1891,12 @@ test_that("`as.Date()` and `as_date()`", {
# TODO: revisit after ARROW-15813
expect_error(
expect_equal(
- test_df %>%
- arrow_table() %>%
- mutate(date_char_ymd_hms = as_date(character_ymd_hms_var)) %>%
+ test_df |>
+ arrow_table() |>
+ mutate(date_char_ymd_hms = as_date(character_ymd_hms_var)) |>
collect(),
- test_df %>%
- mutate(date_char_ymd_hms = as_date(character_ymd_hms_var)) %>%
+ test_df |>
+ mutate(date_char_ymd_hms = as_date(character_ymd_hms_var)) |>
collect()
)
)
@@ -1904,12 +1904,12 @@ test_that("`as.Date()` and `as_date()`", {
# same as above
expect_error(
expect_equal(
- test_df %>%
- arrow_table() %>%
- mutate(date_char_ymd_hms = as.Date(character_ymd_hms_var)) %>%
+ test_df |>
+ arrow_table() |>
+ mutate(date_char_ymd_hms = as.Date(character_ymd_hms_var)) |>
collect(),
- test_df %>%
- mutate(date_char_ymd_hms = as.Date(character_ymd_hms_var)) %>%
+ test_df |>
+ mutate(date_char_ymd_hms = as.Date(character_ymd_hms_var)) |>
collect()
)
)
@@ -1917,15 +1917,15 @@ test_that("`as.Date()` and `as_date()`", {
# we do not support as.Date() with double/ float (error surfaced from C++)
# TODO: revisit after ARROW-15798
expect_error(
- test_df %>%
- arrow_table() %>%
- mutate(date_double = as.Date(double_var, origin = "1970-01-01")) %>%
+ test_df |>
+ arrow_table() |>
+ mutate(date_double = as.Date(double_var, origin = "1970-01-01")) |>
collect()
)
expect_error(
- test_df %>%
- arrow_table() %>%
- mutate(date_double = as_date(double_var, origin = "1970-01-01")) %>%
+ test_df |>
+ arrow_table() |>
+ mutate(date_double = as_date(double_var, origin = "1970-01-01")) |>
collect()
)
@@ -1935,11 +1935,11 @@ test_that("`as.Date()` and `as_date()`", {
# `as_date()` does the opposite: uses the tzone attribute of the POSIXct object
# passed if`tz` is NULL
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
date_diff_lubridate = as_date(difference_date),
date_diff_base = as.Date(difference_date)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -1948,14 +1948,14 @@ test_that("`as.Date()` and `as_date()`", {
# we do not support multiple tryFormats
# Use a dataset to test the alternative suggestion message
expect_snapshot(
- test_df %>%
- InMemoryDataset$create() %>%
+ test_df |>
+ InMemoryDataset$create() |>
transmute(
date_char_ymd = as.Date(
character_ymd_var,
tryFormats = c("%Y-%m-%d", "%Y/%m/%d")
)
- ) %>%
+ ) |>
collect(),
error = TRUE
)
@@ -1963,7 +1963,7 @@ test_that("`as.Date()` and `as_date()`", {
test_that("`as_date()` and `as.Date()` work with R objects", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
date1 = as.Date("2022-05-10"),
date2 = as.Date(12, origin = "2022-05-01"),
@@ -1971,7 +1971,7 @@ test_that("`as_date()` and `as.Date()` work with R objects", {
date4 = as_date("2022-05-10"),
date5 = as_date(12, origin = "2022-05-01"),
date6 = as_date("2022-10-03")
- ) %>%
+ ) |>
collect(),
tibble(
a = 1
@@ -1991,7 +1991,7 @@ test_that("`as_datetime()`", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
ddate = as_datetime(date),
ddate2 = lubridate::as_datetime(date),
@@ -2003,20 +2003,20 @@ test_that("`as_datetime()`", {
dintegerish_date = as_datetime(integerish_date, origin = "1970-01-02"),
dintegerish_date2 = as_datetime(integerish_date, origin = "1970-01-01"),
ddouble_date = as_datetime(double_date)
- ) %>%
+ ) |>
collect(),
test_df
)
expect_identical(
- test_df %>%
- arrow_table() %>%
+ test_df |>
+ arrow_table() |>
mutate(
x = cast(as_datetime(double_date, unit = "ns"), int64()),
y = cast(as_datetime(double_date, unit = "us"), int64()),
z = cast(as_datetime(double_date, unit = "ms"), int64()),
.keep = "none"
- ) %>%
+ ) |>
collect(),
tibble(
x = bit64::as.integer64(c(10100000000, 25200000000, NA)),
@@ -2032,36 +2032,36 @@ test_that("as_datetime() works with other functions", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
ddchar_date = as_datetime(char_date),
ddchar_date_date32_1 = as.Date(ddchar_date),
ddchar_date_date32_2 = as_date(ddchar_date),
ddchar_date_floored = floor_date(ddchar_date, unit = "days")
- ) %>%
+ ) |>
collect(),
test_df
)
# ARROW-17428 - Arrow does not support conversion of timestamp to int32
expect_error(
- test_df %>%
- arrow_table() %>%
+ test_df |>
+ arrow_table() |>
mutate(
dchar_date = as_datetime(char_date),
dchar_date_int = as.integer(dchar_date)
- ) %>%
+ ) |>
collect()
)
# ARROW-17428 - Arrow does not support conversion of timestamp to double
expect_error(
- test_df %>%
- arrow_table() %>%
+ test_df |>
+ arrow_table() |>
mutate(
dchar_date = as_datetime(char_date),
dchar_date_num = as.numeric(dchar_date)
- ) %>%
+ ) |>
collect()
)
})
@@ -2071,13 +2071,13 @@ test_that("parse_date_time() works with year, month, and date components", {
# RE2 library
skip_if_not_available("re2")
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
parsed_date_ymd = parse_date_time(string_ymd, orders = "ymd"),
parsed_date_ymd2 = lubridate::parse_date_time(string_ymd, orders = "ymd"),
parsed_date_dmy = parse_date_time(string_dmy, orders = "dmy"),
parsed_date_mdy = parse_date_time(string_mdy, orders = "mdy")
- ) %>%
+ ) |>
collect(),
tibble::tibble(
string_ymd = c(
@@ -2101,12 +2101,12 @@ test_that("parse_date_time() works with year, month, and date components", {
# TODO(ARROW-16443): locale (affecting "%b% and "%B") does not work on Windows
skip_on_os("windows")
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
parsed_date_ymd = parse_date_time(string_ymd, orders = "ymd"),
parsed_date_dmy = parse_date_time(string_dmy, orders = "dmy"),
parsed_date_mdy = parse_date_time(string_mdy, orders = "mdy")
- ) %>%
+ ) |>
collect(),
tibble::tibble(
string_ymd = c(
@@ -2134,13 +2134,13 @@ test_that("parse_date_time() works with a mix of formats and orders", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
date_from_string = parse_date_time(
string_combi,
orders = c("ymd", "%d/%m//%Y", "%m.%d.%Y")
)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -2160,7 +2160,7 @@ test_that("year, month, day date/time parsers", {
# RE2 library
skip_if_not_available("re2")
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
ymd_date = ymd(ymd_string),
ydm_date = ydm(ydm_string),
@@ -2174,13 +2174,13 @@ test_that("year, month, day date/time parsers", {
myd_date2 = lubridate::myd(myd_string),
dmy_date2 = lubridate::dmy(dmy_string),
dym_date2 = lubridate::dym(dym_string)
- ) %>%
+ ) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
ymd_date = ymd(ymd_string, tz = "Pacific/Marquesas"),
ydm_date = ydm(ydm_string, tz = "Pacific/Marquesas"),
@@ -2188,7 +2188,7 @@ test_that("year, month, day date/time parsers", {
myd_date = myd(myd_string, tz = "Pacific/Marquesas"),
dmy_date = dmy(dmy_string, tz = "Pacific/Marquesas"),
dym_date = dym(dym_string, tz = "Pacific/Marquesas")
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -2212,7 +2212,7 @@ test_that("ym, my & yq parsers", {
# RE2 library
skip_if_not_available("re2")
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
ym_date = ym(ym_string),
ym_date2 = lubridate::ym(ym_string),
@@ -2250,7 +2250,7 @@ test_that("ym, my & yq parsers", {
qy_date_from_string2 = parse_date_time(qy_string, orders = "qY"),
qy_date_from_numeric2 = parse_date_time(qy_numeric, orders = "qY"),
qy_date_from_string_with_space2 = parse_date_time(qy_space, orders = "qY")
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -2262,7 +2262,7 @@ test_that("parse_date_time's other formats", {
skip_if_not_available("re2")
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
parsed_H = parse_date_time(string_H, orders = "%Y-%m-%d-%H"),
parsed_I = parse_date_time(string_I, orders = "%Y-%m-%d-%I"),
@@ -2276,13 +2276,13 @@ test_that("parse_date_time's other formats", {
parsed_Y = parse_date_time(string_Y, orders = "%Y-%m-%d"),
parsed_R = parse_date_time(string_R, orders = "%Y-%m-%d-%R"),
parsed_T = parse_date_time(string_T, orders = "%Y-%m-%d-%T")
- ) %>%
+ ) |>
collect(),
strptime_test_df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
parsed_H = parse_date_time(string_H, orders = "ymdH"),
parsed_I = parse_date_time(string_I, orders = "ymdI"),
@@ -2296,7 +2296,7 @@ test_that("parse_date_time's other formats", {
parsed_Y = parse_date_time(string_Y, orders = "Ymd"),
parsed_R = parse_date_time(string_R, orders = "ymdR"),
parsed_T = parse_date_time(string_T, orders = "ymdT")
- ) %>%
+ ) |>
collect(),
strptime_test_df
)
@@ -2304,7 +2304,7 @@ test_that("parse_date_time's other formats", {
# Some formats are not supported on Windows
if (!tolower(Sys.info()[["sysname"]]) == "windows") {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
parsed_a = parse_date_time(string_a, orders = "%Y-%m-%d-%a"),
parsed_A = parse_date_time(string_A, orders = "%Y-%m-%d-%A"),
@@ -2312,13 +2312,13 @@ test_that("parse_date_time's other formats", {
parsed_B = parse_date_time(string_B, orders = "%Y-%m-%d-%B"),
parsed_p = parse_date_time(string_p, orders = "%Y-%m-%d-%p"),
parsed_r = parse_date_time(string_r, orders = "%Y-%m-%d-%r")
- ) %>%
+ ) |>
collect(),
strptime_test_df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
parsed_a = parse_date_time(string_a, orders = "ymda"),
parsed_A = parse_date_time(string_A, orders = "ymdA"),
@@ -2326,16 +2326,16 @@ test_that("parse_date_time's other formats", {
parsed_B = parse_date_time(string_B, orders = "ymdB"),
parsed_p = parse_date_time(string_p, orders = "ymdp"),
parsed_r = parse_date_time(string_r, orders = "ymdr")
- ) %>%
+ ) |>
collect(),
strptime_test_df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
parsed_date_ymd = parse_date_time(string_1, orders = "Y-%b-d-%T")
- ) %>%
+ ) |>
collect(),
tibble::tibble(string_1 = c("2022-Feb-11-12:23:45", NA))
)
@@ -2344,11 +2344,11 @@ test_that("parse_date_time's other formats", {
test_that("lubridate's fast_strptime", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = fast_strptime(x, format = "%Y-%m-%d %H:%M:%S", lt = FALSE),
y2 = lubridate::fast_strptime(x, format = "%Y-%m-%d %H:%M:%S", lt = FALSE)
- ) %>%
+ ) |>
collect(),
tibble(
x = c("2018-10-07 19:04:05", "2022-05-17 21:23:45", NA)
@@ -2357,7 +2357,7 @@ test_that("lubridate's fast_strptime", {
# R object
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y =
fast_strptime(
@@ -2365,7 +2365,7 @@ test_that("lubridate's fast_strptime", {
format = "%y-%m-%d %H:%M:%S",
lt = FALSE
)
- ) %>%
+ ) |>
collect(),
tibble(
x = c("2018-10-07 19:04:05", NA)
@@ -2373,7 +2373,7 @@ test_that("lubridate's fast_strptime", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
date_multi_formats =
fast_strptime(
@@ -2381,7 +2381,7 @@ test_that("lubridate's fast_strptime", {
format = c("%Y-%m-%d %H:%M:%S", "%m-%d-%Y %H:%M:%S"),
lt = FALSE
)
- ) %>%
+ ) |>
collect(),
tibble(
x = c("2018-10-07 19:04:05", "10-07-1968 19:04:05")
@@ -2393,7 +2393,7 @@ test_that("lubridate's fast_strptime", {
skip_if_not_available("re2")
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
dttm_with_tz = fast_strptime(
dttm_as_string,
@@ -2401,7 +2401,7 @@ test_that("lubridate's fast_strptime", {
tz = "Pacific/Marquesas",
lt = FALSE
)
- ) %>%
+ ) |>
collect(),
tibble(
dttm_as_string =
@@ -2412,7 +2412,7 @@ test_that("lubridate's fast_strptime", {
# fast_strptime()'s `cutoff_2000` argument is not supported, but its value is
# implicitly set to 68L both in lubridate and in Arrow
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
date_short_year =
fast_strptime(
@@ -2420,7 +2420,7 @@ test_that("lubridate's fast_strptime", {
format = "%y-%m-%d %H:%M:%S",
lt = FALSE
)
- ) %>%
+ ) |>
collect(),
tibble(
x =
@@ -2430,7 +2430,7 @@ test_that("lubridate's fast_strptime", {
# the arrow binding errors for a value different from 68L for `cutoff_2000`
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
date_short_year =
fast_strptime(
@@ -2439,7 +2439,7 @@ test_that("lubridate's fast_strptime", {
lt = FALSE,
cutoff_2000 = 69L
)
- ) %>%
+ ) |>
collect(),
tibble(
x = c("68-10-07 19:04:05", "69-10-07 19:04:05", NA)
@@ -2452,8 +2452,8 @@ test_that("lubridate's fast_strptime", {
expect_warning(
tibble(
x = c("68-10-07 19:04:05", "69-10-07 19:04:05", NA)
- ) %>%
- arrow_table() %>%
+ ) |>
+ arrow_table() |>
mutate(
date_short_year =
fast_strptime(
@@ -2461,7 +2461,7 @@ test_that("lubridate's fast_strptime", {
format = "%y-%m-%d %H:%M:%S",
lt = TRUE
)
- ) %>%
+ ) |>
collect()
)
})
@@ -2500,7 +2500,7 @@ test_that("parse_date_time with hours, minutes and seconds components", {
skip_if_not_available("re2")
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
ymd_hms_dttm = parse_date_time(ymd_hms_string, orders = "ymd_HMS"),
ymd_hm_dttm = parse_date_time(ymd_hm_string, orders = "ymd_HM"),
@@ -2514,13 +2514,13 @@ test_that("parse_date_time with hours, minutes and seconds components", {
ydm_hms_dttm = parse_date_time(ydm_hms_string, orders = "ydm_HMS"),
ydm_hm_dttm = parse_date_time(ydm_hm_string, orders = "ydmHM"),
ydm_h_dttm = parse_date_time(ydm_h_string, orders = "ydmH")
- ) %>%
+ ) |>
collect(),
test_dates_times
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
ymd_hms_dttm = ymd_hms(ymd_hms_string),
ymd_hm_dttm = ymd_hm(ymd_hm_string),
@@ -2534,7 +2534,7 @@ test_that("parse_date_time with hours, minutes and seconds components", {
ydm_hms_dttm = ydm_hms(ydm_hms_string),
ydm_hm_dttm = ydm_hm(ydm_hm_string),
ydm_h_dttm = ydm_h(ydm_h_string)
- ) %>%
+ ) |>
collect(),
test_dates_times
)
@@ -2542,7 +2542,7 @@ test_that("parse_date_time with hours, minutes and seconds components", {
# parse_date_time with timezone
pm_tz <- "Pacific/Marquesas"
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
ymd_hms_dttm = parse_date_time(ymd_hms_string, orders = "ymd_HMS", tz = pm_tz),
ymd_hm_dttm = parse_date_time(ymd_hm_string, orders = "ymd_HM", tz = pm_tz),
@@ -2556,13 +2556,13 @@ test_that("parse_date_time with hours, minutes and seconds components", {
ydm_hms_dttm = parse_date_time(ydm_hms_string, orders = "ydm_HMS", tz = pm_tz),
ydm_hm_dttm = parse_date_time(ydm_hm_string, orders = "ydm_HM", tz = pm_tz),
ydm_h_dttm = parse_date_time(ydm_h_string, orders = "ydm_H", tz = pm_tz)
- ) %>%
+ ) |>
collect(),
test_dates_times
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
ymd_hms_dttm = ymd_hms(ymd_hms_string, tz = pm_tz),
ymd_hm_dttm = ymd_hm(ymd_hm_string, tz = pm_tz),
@@ -2576,13 +2576,13 @@ test_that("parse_date_time with hours, minutes and seconds components", {
ydm_hms_dttm = ydm_hms(ydm_hms_string, tz = pm_tz),
ydm_hm_dttm = ydm_hm(ydm_hm_string, tz = pm_tz),
ydm_h_dttm = ydm_h(ydm_h_string, tz = pm_tz),
- ) %>%
+ ) |>
collect(),
test_dates_times
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
ymd_hms_dttm = ymd_hms("2022-07-19 20:24:43"),
ymd_hm_dttm = ymd_hm("2022-07-19 20:24"),
@@ -2596,14 +2596,14 @@ test_that("parse_date_time with hours, minutes and seconds components", {
ydm_hms_dttm = ydm_hms("2022-19-07 20:24:43"),
ydm_hm_dttm = ydm_hm("2022-19-07 20:24"),
ydm_h_dttm = ydm_h("2022-19-07 20")
- ) %>%
+ ) |>
collect(),
test_dates_times
)
# test ymd_ims
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
ymd_ims_dttm =
parse_date_time(
@@ -2612,7 +2612,7 @@ test_that("parse_date_time with hours, minutes and seconds components", {
# lubridate is chatty and will warn 1 format failed to parse
quiet = TRUE
)
- ) %>%
+ ) |>
collect(),
tibble(
ymd_ims_string =
@@ -2658,7 +2658,7 @@ test_that("parse_date_time with month names and HMS", {
# the un-separated strings are versions of "1987-08-22 20:13:59" (with %y)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
ymd_hms_dttm = parse_date_time(ymd_hms_string, orders = "ymd_HMS"),
ymd_hm_dttm = parse_date_time(ymd_hm_string, orders = "ymdHM"),
@@ -2672,13 +2672,13 @@ test_that("parse_date_time with month names and HMS", {
ydm_hms_dttm = parse_date_time(ydm_hms_string, orders = "ydm_HMS"),
ydm_hm_dttm = parse_date_time(ydm_hm_string, orders = "ydmHM"),
ydm_h_dttm = parse_date_time(ydm_h_string, orders = "ydm_H")
- ) %>%
+ ) |>
collect(),
test_dates_times2
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
ymd_hms_dttm = ymd_hms(ymd_hms_string),
ymd_hm_dttm = ymd_hm(ymd_hm_string),
@@ -2692,13 +2692,13 @@ test_that("parse_date_time with month names and HMS", {
ydm_hms_dttm = ydm_hms(ydm_hms_string),
ydm_hm_dttm = ydm_hm(ydm_hm_string),
ydm_h_dttm = ydm_h(ydm_h_string)
- ) %>%
+ ) |>
collect(),
test_dates_times2
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
ymd_hms_dttm = ymd_hms("2022-June-19 20:24:43"),
ymd_hm_dttm = ymd_hm("2022-June-19 20:24"),
@@ -2712,7 +2712,7 @@ test_that("parse_date_time with month names and HMS", {
ydm_hms_dttm = ydm_hms("2022-19-June 20:24:43"),
ydm_hm_dttm = ydm_hm("2022-19-June 20:24"),
ydm_h_dttm = ydm_h("2022-19-June 20")
- ) %>%
+ ) |>
collect(),
test_dates_times2
)
@@ -2730,11 +2730,11 @@ test_that("parse_date_time with `quiet = FALSE` not supported", {
expect_warning(
expect_warning(
- tibble(x = c("2022-05-19 13:46:51")) %>%
- arrow_table() %>%
+ tibble(x = c("2022-05-19 13:46:51")) |>
+ arrow_table() |>
mutate(
x_dttm = parse_date_time(x, orders = "dmy_HMS", quiet = FALSE)
- ) %>%
+ ) |>
collect(),
"`quiet = FALSE` not supported in Arrow"
),
@@ -2742,11 +2742,11 @@ test_that("parse_date_time with `quiet = FALSE` not supported", {
)
expect_warning(
- tibble(x = c("2022-05-19 13:46:51")) %>%
- arrow_table() %>%
+ tibble(x = c("2022-05-19 13:46:51")) |>
+ arrow_table() |>
mutate(
x_dttm = ymd_hms(x, quiet = FALSE)
- ) %>%
+ ) |>
collect(),
"`quiet = FALSE` not supported in Arrow"
)
@@ -2768,7 +2768,7 @@ test_that("parse_date_time with truncated formats", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
dttm =
parse_date_time(
@@ -2781,14 +2781,14 @@ test_that("parse_date_time with truncated formats", {
truncated_ymd_string,
truncated = 3
)
- ) %>%
+ ) |>
collect(),
test_truncation_df
)
# values for truncated greater than nchar(orders) - 3 not supported in Arrow
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
dttm =
parse_date_time(
@@ -2796,7 +2796,7 @@ test_that("parse_date_time with truncated formats", {
orders = "ymd_HMS",
truncated = 5
)
- ) %>%
+ ) |>
collect(),
test_truncation_df,
warning = "a value for `truncated` > 4 not supported in Arrow"
@@ -2804,14 +2804,14 @@ test_that("parse_date_time with truncated formats", {
# values for truncated greater than nchar(orders) - 3 not supported in Arrow
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
dttm =
ymd_hms(
truncated_ymd_string,
truncated = 5
)
- ) %>%
+ ) |>
collect(),
test_truncation_df,
warning = "a value for `truncated` > 4 not supported in Arrow"
@@ -2824,11 +2824,11 @@ test_that("parse_date_time with `locale != NULL` not supported", {
skip_if_not_available("re2")
expect_warning(
- tibble(x = c("2022-05-19 13:46:51")) %>%
- arrow_table() %>%
+ tibble(x = c("2022-05-19 13:46:51")) |>
+ arrow_table() |>
mutate(
x_dttm = ymd_hms(x, locale = "C")
- ) %>%
+ ) |>
collect(),
"`locale` not supported in Arrow"
)
@@ -2844,7 +2844,7 @@ test_that("parse_date_time with `exact = TRUE`, and with regular R objects", {
# RE2 library
skip_if_not_available("re2")
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
parsed_x =
parse_date_time(
@@ -2858,15 +2858,15 @@ test_that("parse_date_time with `exact = TRUE`, and with regular R objects", {
c("%m/%d/%Y %I:%M:%S", "%m/%d/%Y %H%M", "%m/%d/%Y %H"),
exact = TRUE
)
- ) %>%
+ ) |>
collect(),
test_df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
b = parse_date_time("2022-12-31 12:59:59", orders = "ymd_HMS")
- ) %>%
+ ) |>
collect(),
tibble(
a = 1
@@ -3100,12 +3100,12 @@ tz_times <- tibble::tibble(
test_that("timestamp round/floor/ceiling works for a minimal test", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
round_datetime = round_date(datetime),
floor_datetime = floor_date(datetime),
ceiling_datetime = ceiling_date(datetime, change_on_boundary = FALSE)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -3117,8 +3117,8 @@ test_that("timestamp round/floor/ceiling accepts period unit abbreviation", {
check_period_abbreviation <- function(unit, synonyms) {
# check arrow against lubridate
compare_dplyr_binding(
- .input %>%
- mutate(out_1 = round_date(datetime, unit)) %>%
+ .input |>
+ mutate(out_1 = round_date(datetime, unit)) |>
collect(),
easy_df
)
@@ -3142,12 +3142,12 @@ test_that("temporal round/floor/ceiling accepts periods with multiple units", {
check_multiple_unit_period <- function(unit, multiplier) {
unit_string <- paste(multiplier, unit)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
round_datetime = round_date(datetime, unit_string),
floor_datetime = floor_date(datetime, unit_string),
ceiling_datetime = ceiling_date(datetime, unit_string)
- ) %>%
+ ) |>
collect(),
easy_df
)
@@ -3168,15 +3168,15 @@ test_that("temporal round/floor/ceiling accepts periods with multiple units", {
check_date_rounding <- function(data, unit, lubridate_unit = unit, ...) {
expect_equal(
- data %>%
- arrow_table() %>%
+ data |>
+ arrow_table() |>
mutate(
date_rounded = round_date(date, unit),
date_floored = floor_date(date, unit),
date_ceiling = ceiling_date(date, unit)
- ) %>%
+ ) |>
collect(),
- data %>%
+ data |>
mutate(
date_rounded = as.Date(round_date(date, lubridate_unit)),
date_floored = as.Date(floor_date(date, lubridate_unit)),
@@ -3188,15 +3188,15 @@ check_date_rounding <- function(data, unit, lubridate_unit = unit, ...) {
check_timestamp_rounding <- function(data, unit, lubridate_unit = unit, ...) {
expect_equal(
- data %>%
- arrow_table() %>%
+ data |>
+ arrow_table() |>
mutate(
datetime_rounded = round_date(datetime, unit),
datetime_floored = floor_date(datetime, unit),
datetime_ceiling = ceiling_date(datetime, unit)
- ) %>%
+ ) |>
collect(),
- data %>%
+ data |>
mutate(
datetime_rounded = round_date(datetime, lubridate_unit),
datetime_floored = floor_date(datetime, lubridate_unit),
@@ -3207,45 +3207,45 @@ check_timestamp_rounding <- function(data, unit, lubridate_unit = unit, ...) {
}
test_that("date round/floor/ceil works for units of 1 day or less", {
- test_df %>% check_date_rounding("1 millisecond", lubridate_unit = ".001 second")
- test_df %>% check_date_rounding("1 second")
- test_df %>% check_date_rounding("1 hour")
+ test_df |> check_date_rounding("1 millisecond", lubridate_unit = ".001 second")
+ test_df |> check_date_rounding("1 second")
+ test_df |> check_date_rounding("1 hour")
skip("floor_date(as.Date(NA), '1 day') is no longer NA on latest R-devel")
# Possibly https://github.com/wch/r-source/commit/4f70ce0d79eeda7464cf97448e515275cbef754b
- test_df %>% check_date_rounding("1 day")
+ test_df |> check_date_rounding("1 day")
})
test_that("timestamp round/floor/ceil works for units of 1 day or less", {
- test_df %>% check_timestamp_rounding("second")
- test_df %>% check_timestamp_rounding("minute")
- test_df %>% check_timestamp_rounding("hour")
- test_df %>% check_timestamp_rounding("day")
+ test_df |> check_timestamp_rounding("second")
+ test_df |> check_timestamp_rounding("minute")
+ test_df |> check_timestamp_rounding("hour")
+ test_df |> check_timestamp_rounding("day")
- test_df %>% check_timestamp_rounding(".01 second")
- test_df %>% check_timestamp_rounding(".001 second")
- test_df %>% check_timestamp_rounding(".00001 second")
+ test_df |> check_timestamp_rounding(".01 second")
+ test_df |> check_timestamp_rounding(".001 second")
+ test_df |> check_timestamp_rounding(".00001 second")
- test_df %>% check_timestamp_rounding("1 millisecond", lubridate_unit = ".001 second")
- test_df %>% check_timestamp_rounding("1 microsecond", lubridate_unit = ".000001 second")
- test_df %>% check_timestamp_rounding("1 nanosecond", lubridate_unit = ".000000001 second")
+ test_df |> check_timestamp_rounding("1 millisecond", lubridate_unit = ".001 second")
+ test_df |> check_timestamp_rounding("1 microsecond", lubridate_unit = ".000001 second")
+ test_df |> check_timestamp_rounding("1 nanosecond", lubridate_unit = ".000000001 second")
})
test_that("timestamp round/floor/ceil works for units: month/quarter/year", {
- year_of_dates %>% check_timestamp_rounding("month", ignore_attr = TRUE)
- year_of_dates %>% check_timestamp_rounding("quarter", ignore_attr = TRUE)
- year_of_dates %>% check_timestamp_rounding("year", ignore_attr = TRUE)
+ year_of_dates |> check_timestamp_rounding("month", ignore_attr = TRUE)
+ year_of_dates |> check_timestamp_rounding("quarter", ignore_attr = TRUE)
+ year_of_dates |> check_timestamp_rounding("year", ignore_attr = TRUE)
})
# check helper invoked when we need to avoid the lubridate rounding bug
check_date_rounding_1051_bypass <- function(data, unit, ignore_attr = TRUE, ...) {
# directly compare arrow to lubridate for floor and ceiling
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
date_floored = floor_date(date, unit),
date_ceiling = ceiling_date(date, unit)
- ) %>%
+ ) |>
collect(),
data,
ignore_attr = ignore_attr,
@@ -3256,12 +3256,12 @@ check_date_rounding_1051_bypass <- function(data, unit, ignore_attr = TRUE, ...)
# because of a lubridate bug specific to Date objects with week and
# higher-unit rounding (see lubridate issue 1051)
# https://github.com/tidyverse/lubridate/issues/1051
- out <- data %>%
- arrow_table() %>%
+ out <- data |>
+ arrow_table() |>
mutate(
- out_date = date %>% round_date(unit), # Date
- out_time = datetime %>% round_date(unit) # POSIXct
- ) %>%
+ out_date = date |> round_date(unit), # Date
+ out_time = datetime |> round_date(unit) # POSIXct
+ ) |>
collect()
expect_equal(
@@ -3282,15 +3282,15 @@ test_that("date round/floor/ceil works for units: month/quarter/year", {
check_date_week_rounding <- function(data, week_start, ignore_attr = TRUE, ...) {
expect_equal(
- data %>%
- arrow_table() %>%
+ data |>
+ arrow_table() |>
mutate(
date_rounded = round_date(date, unit),
date_floored = floor_date(date, unit),
date_ceiling = ceiling_date(date, unit)
- ) %>%
+ ) |>
collect(),
- data %>%
+ data |>
mutate(
date_rounded = as.Date(round_date(date, lubridate_unit)),
date_floored = as.Date(floor_date(date, lubridate_unit)),
@@ -3303,12 +3303,12 @@ check_date_week_rounding <- function(data, week_start, ignore_attr = TRUE, ...)
check_timestamp_week_rounding <- function(data, week_start, ignore_attr = TRUE, ...) {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
datetime_rounded = round_date(datetime, "week", week_start = week_start),
datetime_floored = floor_date(datetime, "week", week_start = week_start),
datetime_ceiling = ceiling_date(datetime, "week", week_start = week_start)
- ) %>%
+ ) |>
collect(),
data,
ignore_attr = ignore_attr,
@@ -3317,26 +3317,26 @@ check_timestamp_week_rounding <- function(data, week_start, ignore_attr = TRUE,
}
test_that("timestamp round/floor/ceil works for week units (standard week_start)", {
- fortnight %>% check_timestamp_week_rounding(week_start = 1) # Monday
- fortnight %>% check_timestamp_week_rounding(week_start = 7) # Sunday
+ fortnight |> check_timestamp_week_rounding(week_start = 1) # Monday
+ fortnight |> check_timestamp_week_rounding(week_start = 7) # Sunday
})
test_that("timestamp round/floor/ceil works for week units (non-standard week_start)", {
- fortnight %>% check_timestamp_week_rounding(week_start = 2) # Tuesday
- fortnight %>% check_timestamp_week_rounding(week_start = 3) # Wednesday
- fortnight %>% check_timestamp_week_rounding(week_start = 4) # Thursday
- fortnight %>% check_timestamp_week_rounding(week_start = 5) # Friday
- fortnight %>% check_timestamp_week_rounding(week_start = 6) # Saturday
+ fortnight |> check_timestamp_week_rounding(week_start = 2) # Tuesday
+ fortnight |> check_timestamp_week_rounding(week_start = 3) # Wednesday
+ fortnight |> check_timestamp_week_rounding(week_start = 4) # Thursday
+ fortnight |> check_timestamp_week_rounding(week_start = 5) # Friday
+ fortnight |> check_timestamp_week_rounding(week_start = 6) # Saturday
})
check_date_week_rounding <- function(data, week_start, ignore_attr = TRUE, ...) {
# directly compare arrow to lubridate for floor and ceiling
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
date_floored = floor_date(date, "week", week_start = week_start),
date_ceiling = ceiling_date(date, "week", week_start = week_start)
- ) %>%
+ ) |>
collect(),
data,
ignore_attr = ignore_attr,
@@ -3345,12 +3345,12 @@ check_date_week_rounding <- function(data, week_start, ignore_attr = TRUE, ...)
# use the bypass method to avoid the lubridate-1051 bug for week units
# https://github.com/tidyverse/lubridate/issues/1051
- out <- data %>%
- arrow_table() %>%
+ out <- data |>
+ arrow_table() |>
mutate(
- out_date = date %>% round_date("week", week_start = week_start), # Date
- out_time = datetime %>% round_date("week", week_start = week_start) # POSIXct
- ) %>%
+ out_date = date |> round_date("week", week_start = week_start), # Date
+ out_time = datetime |> round_date("week", week_start = week_start) # POSIXct
+ ) |>
collect()
expect_equal(
@@ -3378,12 +3378,12 @@ test_that("date round/floor/ceil works for week units (non-standard week_start)"
check_boundary_with_unit <- function(unit, ...) {
# timestamps
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
cob_null = ceiling_date(datetime, unit, change_on_boundary = NULL),
cob_true = ceiling_date(datetime, unit, change_on_boundary = TRUE),
cob_false = ceiling_date(datetime, unit, change_on_boundary = FALSE)
- ) %>%
+ ) |>
collect(),
boundary_times,
...
@@ -3391,15 +3391,15 @@ check_boundary_with_unit <- function(unit, ...) {
# dates
expect_equal(
- boundary_times %>%
- arrow_table() %>%
+ boundary_times |>
+ arrow_table() |>
mutate(
cob_null = ceiling_date(date, unit, change_on_boundary = NULL),
cob_true = ceiling_date(date, unit, change_on_boundary = TRUE),
cob_false = ceiling_date(date, unit, change_on_boundary = FALSE)
- ) %>%
+ ) |>
collect(),
- boundary_times %>%
+ boundary_times |>
mutate(
cob_null = as.Date(ceiling_date(date, unit, change_on_boundary = NULL)),
cob_true = as.Date(ceiling_date(date, unit, change_on_boundary = TRUE)),
@@ -3456,7 +3456,7 @@ check_timezone_rounding_vs_lubridate <- function(data, unit) {
# external validity check: compare lubridate to arrow
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
utc_floored = floor_date(utc_time, unit = unit),
utc_rounded = round_date(utc_time, unit = unit),
@@ -3473,7 +3473,7 @@ check_timezone_rounding_vs_lubridate <- function(data, unit) {
kat_floored = floor_date(kat_time, unit = unit),
kat_rounded = round_date(kat_time, unit = unit),
kat_ceiling = ceiling_date(kat_time, unit = unit)
- ) %>%
+ ) |>
collect(),
data
)
@@ -3486,8 +3486,8 @@ check_timezone_rounding_vs_lubridate <- function(data, unit) {
# for UTC test. this test isn't useful for subsecond resolution but avoids
# dependency on lubridate
check_timezone_rounding_for_consistency <- function(data, unit) {
- shifted_times <- data %>%
- arrow_table() %>%
+ shifted_times <- data |>
+ arrow_table() |>
mutate(
utc_floored = floor_date(utc_time, unit = unit),
utc_rounded = round_date(utc_time, unit = unit),
@@ -3504,7 +3504,7 @@ check_timezone_rounding_for_consistency <- function(data, unit) {
kat_floored = floor_date(kat_time, unit = unit),
kat_rounded = round_date(kat_time, unit = unit),
kat_ceiling = ceiling_date(kat_time, unit = unit)
- ) %>%
+ ) |>
collect()
compare_local_times <- function(time1, time2) {
@@ -3536,36 +3536,36 @@ check_timezone_rounding_for_consistency <- function(data, unit) {
}
test_that("timestamp rounding takes place in local time", {
- tz_times %>% check_timezone_rounding_vs_lubridate(".001 second")
- tz_times %>% check_timezone_rounding_vs_lubridate("second")
- tz_times %>% check_timezone_rounding_vs_lubridate("minute")
- tz_times %>% check_timezone_rounding_vs_lubridate("hour")
- tz_times %>% check_timezone_rounding_vs_lubridate("day")
- tz_times %>% check_timezone_rounding_vs_lubridate("week")
- tz_times %>% check_timezone_rounding_vs_lubridate("month")
- tz_times %>% check_timezone_rounding_vs_lubridate("quarter")
- tz_times %>% check_timezone_rounding_vs_lubridate("year")
-
- tz_times %>% check_timezone_rounding_for_consistency("second")
- tz_times %>% check_timezone_rounding_for_consistency("minute")
- tz_times %>% check_timezone_rounding_for_consistency("hour")
- tz_times %>% check_timezone_rounding_for_consistency("day")
- tz_times %>% check_timezone_rounding_for_consistency("week")
- tz_times %>% check_timezone_rounding_for_consistency("month")
- tz_times %>% check_timezone_rounding_for_consistency("quarter")
- tz_times %>% check_timezone_rounding_for_consistency("year")
-
- tz_times %>% check_timezone_rounding_for_consistency("7 seconds")
- tz_times %>% check_timezone_rounding_for_consistency("7 minutes")
- tz_times %>% check_timezone_rounding_for_consistency("7 hours")
- tz_times %>% check_timezone_rounding_for_consistency("7 months")
- tz_times %>% check_timezone_rounding_for_consistency("7 years")
-
- tz_times %>% check_timezone_rounding_for_consistency("13 seconds")
- tz_times %>% check_timezone_rounding_for_consistency("13 minutes")
- tz_times %>% check_timezone_rounding_for_consistency("13 hours")
- tz_times %>% check_timezone_rounding_for_consistency("13 months")
- tz_times %>% check_timezone_rounding_for_consistency("13 years")
+ tz_times |> check_timezone_rounding_vs_lubridate(".001 second")
+ tz_times |> check_timezone_rounding_vs_lubridate("second")
+ tz_times |> check_timezone_rounding_vs_lubridate("minute")
+ tz_times |> check_timezone_rounding_vs_lubridate("hour")
+ tz_times |> check_timezone_rounding_vs_lubridate("day")
+ tz_times |> check_timezone_rounding_vs_lubridate("week")
+ tz_times |> check_timezone_rounding_vs_lubridate("month")
+ tz_times |> check_timezone_rounding_vs_lubridate("quarter")
+ tz_times |> check_timezone_rounding_vs_lubridate("year")
+
+ tz_times |> check_timezone_rounding_for_consistency("second")
+ tz_times |> check_timezone_rounding_for_consistency("minute")
+ tz_times |> check_timezone_rounding_for_consistency("hour")
+ tz_times |> check_timezone_rounding_for_consistency("day")
+ tz_times |> check_timezone_rounding_for_consistency("week")
+ tz_times |> check_timezone_rounding_for_consistency("month")
+ tz_times |> check_timezone_rounding_for_consistency("quarter")
+ tz_times |> check_timezone_rounding_for_consistency("year")
+
+ tz_times |> check_timezone_rounding_for_consistency("7 seconds")
+ tz_times |> check_timezone_rounding_for_consistency("7 minutes")
+ tz_times |> check_timezone_rounding_for_consistency("7 hours")
+ tz_times |> check_timezone_rounding_for_consistency("7 months")
+ tz_times |> check_timezone_rounding_for_consistency("7 years")
+
+ tz_times |> check_timezone_rounding_for_consistency("13 seconds")
+ tz_times |> check_timezone_rounding_for_consistency("13 minutes")
+ tz_times |> check_timezone_rounding_for_consistency("13 hours")
+ tz_times |> check_timezone_rounding_for_consistency("13 months")
+ tz_times |> check_timezone_rounding_for_consistency("13 years")
})
test_that("with_tz() and force_tz() works", {
@@ -3600,7 +3600,7 @@ test_that("with_tz() and force_tz() works", {
), tz = "UTC")
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
timestamps_with_tz_1 = with_tz(timestamps, "UTC"),
timestamps_with_tz_2 = with_tz(timestamps, "America/Chicago"),
@@ -3608,39 +3608,39 @@ test_that("with_tz() and force_tz() works", {
timestamps_force_tz_1 = force_tz(timestamps, "UTC"),
timestamps_force_tz_2 = force_tz(timestamps, "America/Chicago"),
timestamps_force_tz_3 = force_tz(timestamps, "Asia/Kolkata")
- ) %>%
+ ) |>
collect(),
tibble::tibble(timestamps = timestamps)
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
timestamps_with_tz_1 = with_tz(timestamps, "UTC"),
timestamps_with_tz_2 = with_tz(timestamps, "America/Chicago"),
timestamps_with_tz_3 = with_tz(timestamps, "Asia/Kolkata")
- ) %>%
+ ) |>
collect(),
tibble::tibble(timestamps = timestamps_non_utc)
)
# We can match some roll_dst behaviour for nonexistent times
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
timestamps_with_tz_1 = force_tz(
timestamps,
"Europe/Brussels",
roll_dst = c("boundary", "post")
)
- ) %>%
+ ) |>
collect(),
tibble::tibble(timestamps = nonexistent)
)
# We can match all roll_dst behaviour for ambiguous times
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
# The difference is easier to see if we transform back to UTC
# because both pre and post will display as 02:30 otherwise
@@ -3660,49 +3660,49 @@ test_that("with_tz() and force_tz() works", {
),
"UTC"
)
- ) %>%
+ ) |>
collect(),
tibble::tibble(timestamps = ambiguous)
)
# non-UTC timezone to other timezone is not supported in arrow's force_tz()
expect_warning(
- tibble::tibble(timestamps = timestamps_non_utc) %>%
- arrow_table() %>%
- mutate(timestamps = force_tz(timestamps, "UTC")) %>%
+ tibble::tibble(timestamps = timestamps_non_utc) |>
+ arrow_table() |>
+ mutate(timestamps = force_tz(timestamps, "UTC")) |>
collect(),
"`time` with a non-UTC timezone not supported in Arrow"
)
# We only support some roll_dst values
expect_warning(
- tibble::tibble(timestamps = nonexistent) %>%
- arrow_table() %>%
+ tibble::tibble(timestamps = nonexistent) |>
+ arrow_table() |>
mutate(timestamps = force_tz(
timestamps,
"Europe/Brussels",
roll_dst = "post"
- )) %>%
+ )) |>
collect(),
"roll_dst` value must be 'error' or 'boundary' for nonexistent times"
)
expect_warning(
- tibble::tibble(timestamps = nonexistent) %>%
- arrow_table() %>%
+ tibble::tibble(timestamps = nonexistent) |>
+ arrow_table() |>
mutate(timestamps = force_tz(
timestamps,
"Europe/Brussels",
roll_dst = c("boundary", "NA")
- )) %>%
+ )) |>
collect(),
"`roll_dst` value must be 'error', 'pre', or 'post' for nonexistent times"
)
# Raise error when the timezone falls into the DST-break
expect_error(
- record_batch(timestamps = nonexistent) %>%
- mutate(nonexistent_roll_false = force_tz(timestamps, "Europe/Brussels")) %>%
+ record_batch(timestamps = nonexistent) |>
+ mutate(nonexistent_roll_false = force_tz(timestamps, "Europe/Brussels")) |>
collect(),
"Timestamp doesn't exist in timezone 'Europe/Brussels'"
)
@@ -3712,15 +3712,15 @@ test_that("with_tz() and force_tz() can add timezone to timestamp without timezo
timestamps <- Array$create(1L:10L, int64())$cast(timestamp("s"))
expect_equal(
- arrow_table(timestamps = timestamps) %>%
- mutate(timestamps = with_tz(timestamps, "America/Chicago")) %>%
+ arrow_table(timestamps = timestamps) |>
+ mutate(timestamps = with_tz(timestamps, "America/Chicago")) |>
compute(),
arrow_table(timestamps = timestamps$cast(timestamp("s", "America/Chicago")))
)
expect_equal(
- arrow_table(timestamps = timestamps) %>%
- mutate(timestamps = force_tz(timestamps, "America/Chicago")) %>%
+ arrow_table(timestamps = timestamps) |>
+ mutate(timestamps = force_tz(timestamps, "America/Chicago")) |>
compute(),
arrow_table(
timestamps = call_function("assume_timezone", timestamps, options = list(timezone = "America/Chicago"))
@@ -3737,14 +3737,14 @@ test_that("hms::hms", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
time = hms::hms(s),
time2 = hms::hms(s, m),
time3 = hms::hms(s, m, h),
time4 = hms::hms(s, m, h, d),
time5 = hms::hms(days = d)
- ) %>%
+ ) |>
collect(),
test_df
)
@@ -3778,36 +3778,36 @@ test_that("hms::as_hms", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x1 = hms::as_hms(int),
x2 = hms::as_hms(integerish_dbl),
x3 = hms::as_hms(dbl),
x4 = hms::as_hms(datetime)
- ) %>%
+ ) |>
collect(),
test_df
)
# can only do millisecond precision
expect_error(
- arrow_table(test_df) %>% mutate(y = hms::as_hms(nanosecs)) %>% collect(),
+ arrow_table(test_df) |> mutate(y = hms::as_hms(nanosecs)) |> collect(),
"was truncated converting to int32"
)
# no subsecond precision with character strings
expect_error(
- arrow_table(test_df) %>% mutate(y = hms::as_hms(hms_subsec_string)) %>% collect(),
+ arrow_table(test_df) |> mutate(y = hms::as_hms(hms_subsec_string)) |> collect(),
"Failed to parse string"
)
skip_if_not_available("utf8proc")
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
x = hms::as_hms(hms_string),
- ) %>%
+ ) |>
collect(),
test_df
)
diff --git a/r/tests/testthat/test-dplyr-funcs-math.R b/r/tests/testthat/test-dplyr-funcs-math.R
index e2b622cdb6..0627b21d1f 100644
--- a/r/tests/testthat/test-dplyr-funcs-math.R
+++ b/r/tests/testthat/test-dplyr-funcs-math.R
@@ -25,11 +25,11 @@ test_that("abs()", {
df <- tibble(x = c(-127, -10, -1, -0, 0, 1, 10, 127, NA))
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
abs = abs(x),
abs2 = base::abs(x)
- ) %>%
+ ) |>
collect(),
df
)
@@ -39,11 +39,11 @@ test_that("sign()", {
df <- tibble(x = c(-127, -10, -1, -0, 0, 1, 10, 127, NA))
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
sign = sign(x),
sign2 = base::sign(x)
- ) %>%
+ ) |>
collect(),
df
)
@@ -53,7 +53,7 @@ test_that("ceiling(), floor(), trunc(), round()", {
df <- tibble(x = c(-1, -0.55, -0.5, -0.1, 0, 0.1, 0.5, 0.55, 1, NA, NaN))
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
c = ceiling(x),
f = floor(x),
@@ -63,39 +63,39 @@ test_that("ceiling(), floor(), trunc(), round()", {
f2 = base::floor(x),
t2 = base::trunc(x),
r2 = base::round(x)
- ) %>%
+ ) |>
collect(),
df
)
# with digits set to 1
compare_dplyr_binding(
- .input %>%
- filter(x %% 0.5 == 0) %>% # filter out indeterminate cases (see below)
- mutate(r = round(x, 1)) %>%
+ .input |>
+ filter(x %% 0.5 == 0) |> # filter out indeterminate cases (see below)
+ mutate(r = round(x, 1)) |>
collect(),
df
)
# with digits set to -1
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
rd = round(floor(x * 111), -1), # double
y = ifelse(is.nan(x), NA_integer_, x),
ri = round(as.integer(y * 111), -1) # integer (with the NaN removed)
- ) %>%
+ ) |>
collect(),
df
)
# round(x, -2) is equivalent to round_to_multiple(x, 100)
expect_equal(
- Table$create(x = 1111.1) %>%
- mutate(r = round(x, -2)) %>%
+ Table$create(x = 1111.1) |>
+ mutate(r = round(x, -2)) |>
collect(),
- Table$create(x = 1111.1) %>%
- mutate(r = arrow_round_to_multiple(x, options = list(multiple = 100))) %>%
+ Table$create(x = 1111.1) |>
+ mutate(r = arrow_round_to_multiple(x, options = list(multiple = 100))) |>
collect()
)
@@ -112,8 +112,8 @@ test_that("ceiling(), floor(), trunc(), round()", {
skip_on_os("windows")
compare_dplyr_binding(
- .input %>%
- mutate(r = round(x, 1)) %>%
+ .input |>
+ mutate(r = round(x, 1)) |>
collect(),
df
)
@@ -151,40 +151,40 @@ test_that("log functions", {
df <- tibble(x = c(1:10, NA, NA))
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = log(x),
y2 = base::log(x)
- ) %>%
+ ) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = log(x, base = exp(1))) %>%
+ .input |>
+ mutate(y = log(x, base = exp(1))) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = log(x, base = 2)) %>%
+ .input |>
+ mutate(y = log(x, base = 2)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = log(x, base = 10)) %>%
+ .input |>
+ mutate(y = log(x, base = 10)) |>
collect(),
df
)
# test log(, base = (length == 1))
compare_dplyr_binding(
- .input %>%
- mutate(y = log(x, base = 5)) %>%
+ .input |>
+ mutate(y = log(x, base = 5)) |>
collect(),
df
)
@@ -205,13 +205,13 @@ test_that("log functions", {
# test log(, base = Expression)
compare_dplyr_binding(
- .input %>%
+ .input |>
# test cases where base = 1 below
- filter(x != 1) %>%
+ filter(x != 1) |>
mutate(
y = log(x, base = x),
z = log(2, base = x)
- ) %>%
+ ) |>
collect(),
df
)
@@ -220,8 +220,8 @@ test_that("log functions", {
# suppress the R warning because R warns but Arrow does not
suppressWarnings(
compare_dplyr_binding(
- .input %>%
- mutate(y = log(x, base = y)) %>%
+ .input |>
+ mutate(y = log(x, base = y)) |>
collect(),
tibble(x = 1, y = 1)
)
@@ -229,49 +229,49 @@ test_that("log functions", {
# log(n != 1, base = 1) is Inf in R and Arrow
compare_dplyr_binding(
- .input %>%
- mutate(y = log(x, base = y)) %>%
+ .input |>
+ mutate(y = log(x, base = y)) |>
collect(),
tibble(x = 10, y = 1)
)
compare_dplyr_binding(
- .input %>%
- mutate(y = logb(x)) %>%
+ .input |>
+ mutate(y = logb(x)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = log1p(x)) %>%
+ .input |>
+ mutate(y = log1p(x)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = log2(x)) %>%
+ .input |>
+ mutate(y = log2(x)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = log10(x)) %>%
+ .input |>
+ mutate(y = log10(x)) |>
collect(),
df
)
# with namespacing
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
a = base::logb(x),
b = base::log1p(x),
c = base::log2(x),
d = base::log10(x)
- ) %>%
+ ) |>
collect(),
df
)
@@ -281,50 +281,50 @@ test_that("trig functions", {
df <- tibble(x = c(seq(from = 0, to = 1, by = 0.1), NA))
compare_dplyr_binding(
- .input %>%
- mutate(y = sin(x)) %>%
+ .input |>
+ mutate(y = sin(x)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = cos(x)) %>%
+ .input |>
+ mutate(y = cos(x)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = tan(x)) %>%
+ .input |>
+ mutate(y = tan(x)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = asin(x)) %>%
+ .input |>
+ mutate(y = asin(x)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = acos(x)) %>%
+ .input |>
+ mutate(y = acos(x)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = atan(x)) %>%
+ .input |>
+ mutate(y = atan(x)) |>
collect(),
df
)
# with namespacing
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
a = base::sin(x),
b = base::cos(x),
@@ -332,7 +332,7 @@ test_that("trig functions", {
d = base::asin(x),
e = base::acos(x),
f = base::atan(x)
- ) %>%
+ ) |>
collect(),
df
)
@@ -343,42 +343,42 @@ test_that("hyperbolic trig functions", {
df <- tibble(x = c(seq(from = 0, to = 1, by = 0.1), NA))
compare_dplyr_binding(
- .input %>%
- mutate(y = sinh(x)) %>%
+ .input |>
+ mutate(y = sinh(x)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = cosh(x)) %>%
+ .input |>
+ mutate(y = cosh(x)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = tanh(x)) %>%
+ .input |>
+ mutate(y = tanh(x)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = asinh(x)) %>%
+ .input |>
+ mutate(y = asinh(x)) |>
collect(),
df
)
# with namespacing
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
a = base::sinh(x),
b = base::cosh(x),
c = base::tanh(x),
d = base::asinh(x),
- ) %>%
+ ) |>
collect(),
df
)
@@ -386,18 +386,18 @@ test_that("hyperbolic trig functions", {
df <- tibble(x = c(seq(from = 1, to = 2, by = 0.1)))
compare_dplyr_binding(
- .input %>%
- mutate(y = acosh(x)) %>%
+ .input |>
+ mutate(y = acosh(x)) |>
collect(),
df
)
# with namespacing
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
a = base::acosh(x),
- ) %>%
+ ) |>
collect(),
df
)
@@ -405,18 +405,18 @@ test_that("hyperbolic trig functions", {
df <- tibble(x = c(seq(from = -0.5, to = 0.5, by = 0.1)))
compare_dplyr_binding(
- .input %>%
- mutate(y = atanh(x)) %>%
+ .input |>
+ mutate(y = atanh(x)) |>
collect(),
df
)
# with namespacing
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
a = base::atanh(x)
- ) %>%
+ ) |>
collect(),
df
)
@@ -426,7 +426,7 @@ test_that("arith functions ", {
df <- tibble(x = c(1:5, NA))
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
int_div = x %/% 2,
addition = x + 1,
@@ -435,7 +435,7 @@ test_that("arith functions ", {
division = x / 2,
power = x^3,
modulo = x %% 3
- ) %>%
+ ) |>
collect(),
df
)
@@ -448,7 +448,7 @@ test_that("floor division maintains type consistency with R", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
int_div_dbl = integers %/% 2,
int_div_int = integers %/% 2L,
@@ -458,7 +458,7 @@ test_that("floor division maintains type consistency with R", {
dbl_div_int = doubles %/% 2L,
dbl_div_zero_int = doubles %/% 0L,
dbl_div_zero_dbl = doubles %/% 0
- ) %>%
+ ) |>
collect(),
df
)
@@ -468,11 +468,11 @@ test_that("exp()", {
df <- tibble(x = c(1:5, NA))
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = exp(x),
y2 = base::exp(x)
- ) %>%
+ ) |>
collect(),
df
)
@@ -482,11 +482,11 @@ test_that("sqrt()", {
df <- tibble(x = c(1:5, NA))
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = sqrt(x),
y2 = base::sqrt(x)
- ) %>%
+ ) |>
collect(),
df
)
@@ -496,11 +496,11 @@ test_that("expm1()", {
df <- tibble(x = c(1:5))
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = expm1(x),
y2 = base::expm1(x)
- ) %>%
+ ) |>
collect(),
df
)
diff --git a/r/tests/testthat/test-dplyr-funcs-string.R b/r/tests/testthat/test-dplyr-funcs-string.R
index 82313ff16d..14ebb00fb7 100644
--- a/r/tests/testthat/test-dplyr-funcs-string.R
+++ b/r/tests/testthat/test-dplyr-funcs-string.R
@@ -46,93 +46,93 @@ test_that("paste, paste0, and str_c", {
# no NAs in data
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
a = paste(v, w),
a2 = base::paste(v, w)
- ) %>%
+ ) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(paste(v, w, sep = "-")) %>%
+ .input |>
+ transmute(paste(v, w, sep = "-")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
a = paste0(v, w),
a2 = base::paste0(v, w)
- ) %>%
+ ) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
a = str_c(v, w),
a2 = stringr::str_c(v, w)
- ) %>%
+ ) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(str_c(v, w, sep = "+")) %>%
+ .input |>
+ transmute(str_c(v, w, sep = "+")) |>
collect(),
df
)
# NAs in data
compare_dplyr_binding(
- .input %>%
- transmute(paste(x, y)) %>%
+ .input |>
+ transmute(paste(x, y)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(paste(x, y, sep = "-")) %>%
+ .input |>
+ transmute(paste(x, y, sep = "-")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(str_c(x, y)) %>%
+ .input |>
+ transmute(str_c(x, y)) |>
collect(),
df
)
# non-character column in dots
compare_dplyr_binding(
- .input %>%
- transmute(paste0(x, y, z)) %>%
+ .input |>
+ transmute(paste0(x, y, z)) |>
collect(),
df
)
# literal string in dots
compare_dplyr_binding(
- .input %>%
- transmute(paste(x, "foo", y)) %>%
+ .input |>
+ transmute(paste(x, "foo", y)) |>
collect(),
df
)
# literal NA in dots
compare_dplyr_binding(
- .input %>%
- transmute(paste(x, NA, y)) %>%
+ .input |>
+ transmute(paste(x, NA, y)) |>
collect(),
df
)
# expressions in dots
compare_dplyr_binding(
- .input %>%
- transmute(paste0(x, toupper(y), as.character(z))) %>%
+ .input |>
+ transmute(paste0(x, toupper(y), as.character(z))) |>
collect(),
df
)
@@ -151,8 +151,8 @@ test_that("paste, paste0, and str_c", {
# sep passed in dots to paste0 (which doesn't take a sep argument)
compare_dplyr_binding(
- .input %>%
- transmute(paste0(x, y, sep = "-")) %>%
+ .input |>
+ transmute(paste0(x, y, sep = "-")) |>
collect(),
df
)
@@ -161,11 +161,11 @@ test_that("paste, paste0, and str_c", {
# arrow allows the separator to be an array
expect_equal(
- df %>%
- Table$create() %>%
- transmute(result = paste(x, y, sep = w)) %>%
+ df |>
+ Table$create() |>
+ transmute(result = paste(x, y, sep = w)) |>
collect(),
- df %>%
+ df |>
transmute(result = paste(x, w, y, sep = ""))
)
@@ -203,14 +203,14 @@ test_that("paste, paste0, and str_c", {
test_that("grepl with ignore.case = FALSE and fixed = TRUE", {
df <- tibble(x = c("Foo", "bar", NA_character_))
compare_dplyr_binding(
- .input %>%
- filter(grepl("o", x, fixed = TRUE)) %>%
+ .input |>
+ filter(grepl("o", x, fixed = TRUE)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = grepl("o", x, fixed = TRUE)) %>%
+ .input |>
+ mutate(x = grepl("o", x, fixed = TRUE)) |>
collect(),
df
)
@@ -219,14 +219,14 @@ test_that("grepl with ignore.case = FALSE and fixed = TRUE", {
test_that("sub and gsub with ignore.case = FALSE and fixed = TRUE", {
df <- tibble(x = c("Foo", "bar"))
compare_dplyr_binding(
- .input %>%
- transmute(x = sub("Foo", "baz", x, fixed = TRUE)) %>%
+ .input |>
+ transmute(x = sub("Foo", "baz", x, fixed = TRUE)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(x = gsub("o", "u", x, fixed = TRUE)) %>%
+ .input |>
+ transmute(x = gsub("o", "u", x, fixed = TRUE)) |>
collect(),
df
)
@@ -240,27 +240,27 @@ test_that("grepl", {
for (fixed in c(TRUE, FALSE)) {
compare_dplyr_binding(
- .input %>%
- filter(grepl("Foo", x, fixed = fixed)) %>%
+ .input |>
+ filter(grepl("Foo", x, fixed = fixed)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(x = grepl("^B.+", x, ignore.case = FALSE, fixed = fixed)) %>%
+ .input |>
+ transmute(x = grepl("^B.+", x, ignore.case = FALSE, fixed = fixed)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(grepl("Foo", x, ignore.case = FALSE, fixed = fixed)) %>%
+ .input |>
+ filter(grepl("Foo", x, ignore.case = FALSE, fixed = fixed)) |>
collect(),
df
)
# with namespacing
compare_dplyr_binding(
- .input %>%
- filter(base::grepl("Foo", x, fixed = fixed)) %>%
+ .input |>
+ filter(base::grepl("Foo", x, fixed = fixed)) |>
collect(),
df
)
@@ -273,25 +273,25 @@ test_that("grepl with ignore.case = TRUE and fixed = TRUE", {
# base::grepl() ignores ignore.case = TRUE with a warning when fixed = TRUE,
# so we can't use compare_dplyr_binding() for these tests
expect_equal(
- df %>%
- Table$create() %>%
- filter(grepl("O", x, ignore.case = TRUE, fixed = TRUE)) %>%
+ df |>
+ Table$create() |>
+ filter(grepl("O", x, ignore.case = TRUE, fixed = TRUE)) |>
collect(),
tibble(x = "Foo")
)
expect_equal(
- df %>%
- Table$create() %>%
- filter(grepl("^B.+", x, ignore.case = TRUE, fixed = TRUE)) %>%
+ df |>
+ Table$create() |>
+ filter(grepl("^B.+", x, ignore.case = TRUE, fixed = TRUE)) |>
collect(),
tibble(x = character(0))
)
expect_equal(
- df %>%
- Table$create() %>%
+ df |>
+ Table$create() |>
mutate(
a = grepl("O", x, ignore.case = TRUE, fixed = TRUE)
- ) %>%
+ ) |>
collect(),
tibble(
x = c("Foo", "bar", NA_character_),
@@ -304,56 +304,56 @@ test_that("str_detect", {
df <- tibble(x = c("Foo", "bar", NA_character_))
compare_dplyr_binding(
- .input %>%
- filter(str_detect(x, regex("^F"))) %>%
+ .input |>
+ filter(str_detect(x, regex("^F"))) |>
collect(),
df
)
string <- "^F"
compare_dplyr_binding(
- .input %>%
- filter(str_detect(x, regex(string))) %>%
+ .input |>
+ filter(str_detect(x, regex(string))) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
a = str_detect(x, regex("^f[A-Z]{2}", ignore_case = TRUE)),
a2 = stringr::str_detect(x, regex("^f[A-Z]{2}", ignore_case = TRUE))
- ) %>%
+ ) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(x = str_detect(x, regex("^f[A-Z]{2}", ignore_case = TRUE), negate = TRUE)) %>%
+ .input |>
+ transmute(x = str_detect(x, regex("^f[A-Z]{2}", ignore_case = TRUE), negate = TRUE)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(str_detect(x, fixed("o"))) %>%
+ .input |>
+ filter(str_detect(x, fixed("o"))) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(str_detect(x, fixed("O"))) %>%
+ .input |>
+ filter(str_detect(x, fixed("O"))) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(str_detect(x, fixed("O", ignore_case = TRUE))) %>%
+ .input |>
+ filter(str_detect(x, fixed("O", ignore_case = TRUE))) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(str_detect(x, fixed("O", ignore_case = TRUE), negate = TRUE)) %>%
+ .input |>
+ filter(str_detect(x, fixed("O", ignore_case = TRUE), negate = TRUE)) |>
collect(),
df
)
@@ -364,20 +364,20 @@ test_that("sub and gsub", {
for (fixed in c(TRUE, FALSE)) {
compare_dplyr_binding(
- .input %>%
- transmute(x = sub("Foo", "baz", x, fixed = fixed)) %>%
+ .input |>
+ transmute(x = sub("Foo", "baz", x, fixed = fixed)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(x = sub("^B.+", "baz", x, ignore.case = FALSE, fixed = fixed)) %>%
+ .input |>
+ transmute(x = sub("^B.+", "baz", x, ignore.case = FALSE, fixed = fixed)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(x = sub("Foo", "baz", x, ignore.case = FALSE, fixed = fixed)) %>%
+ .input |>
+ transmute(x = sub("Foo", "baz", x, ignore.case = FALSE, fixed = fixed)) |>
collect(),
df
)
@@ -390,23 +390,23 @@ test_that("sub and gsub with ignore.case = TRUE and fixed = TRUE", {
# base::sub() and base::gsub() ignore ignore.case = TRUE with a warning when
# fixed = TRUE, so we can't use compare_dplyr_binding() for these tests
expect_equal(
- df %>%
- Table$create() %>%
- transmute(x = sub("O", "u", x, ignore.case = TRUE, fixed = TRUE)) %>%
+ df |>
+ Table$create() |>
+ transmute(x = sub("O", "u", x, ignore.case = TRUE, fixed = TRUE)) |>
collect(),
tibble(x = c("Fuo", "bar"))
)
expect_equal(
- df %>%
- Table$create() %>%
- transmute(x = gsub("o", "u", x, ignore.case = TRUE, fixed = TRUE)) %>%
+ df |>
+ Table$create() |>
+ transmute(x = gsub("o", "u", x, ignore.case = TRUE, fixed = TRUE)) |>
collect(),
tibble(x = c("Fuu", "bar"))
)
expect_equal(
- df %>%
- Table$create() %>%
- transmute(x = sub("^B.+", "baz", x, ignore.case = TRUE, fixed = TRUE)) %>%
+ df |>
+ Table$create() |>
+ transmute(x = sub("^B.+", "baz", x, ignore.case = TRUE, fixed = TRUE)) |>
collect(),
df # unchanged
)
@@ -414,15 +414,15 @@ test_that("sub and gsub with ignore.case = TRUE and fixed = TRUE", {
test_that("sub and gsub with namespacing", {
compare_dplyr_binding(
- .input %>%
- mutate(verses_new = base::gsub("o", "u", verses, fixed = TRUE)) %>%
+ .input |>
+ mutate(verses_new = base::gsub("o", "u", verses, fixed = TRUE)) |>
collect(),
tbl
)
compare_dplyr_binding(
- .input %>%
- mutate(verses_new = base::sub("o", "u", verses, fixed = TRUE)) %>%
+ .input |>
+ mutate(verses_new = base::sub("o", "u", verses, fixed = TRUE)) |>
collect(),
tbl
)
@@ -449,53 +449,53 @@ test_that("str_replace and str_replace_all", {
df <- tibble(x = c("Foo", "bar"))
compare_dplyr_binding(
- .input %>%
- transmute(x = str_replace_all(x, "^F", "baz")) %>%
+ .input |>
+ transmute(x = str_replace_all(x, "^F", "baz")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(x = str_replace_all(x, regex("^F"), "baz")) %>%
+ .input |>
+ transmute(x = str_replace_all(x, regex("^F"), "baz")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = str_replace(x, "^F[a-z]{2}", "baz")) %>%
+ .input |>
+ mutate(x = str_replace(x, "^F[a-z]{2}", "baz")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(x = str_replace(x, regex("^f[A-Z]{2}", ignore_case = TRUE), "baz")) %>%
+ .input |>
+ transmute(x = str_replace(x, regex("^f[A-Z]{2}", ignore_case = TRUE), "baz")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
x = str_replace_all(x, fixed("o"), "u"),
x2 = stringr::str_replace_all(x, fixed("o"), "u")
- ) %>%
+ ) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
x = str_replace(x, fixed("O"), "u"),
x2 = stringr::str_replace(x, fixed("O"), "u")
- ) %>%
+ ) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(x = str_replace(x, fixed("O", ignore_case = TRUE), "u")) %>%
+ .input |>
+ transmute(x = str_replace(x, fixed("O", ignore_case = TRUE), "u")) |>
collect(),
df
)
@@ -505,8 +505,8 @@ test_that("strsplit and str_split", {
df <- tibble(x = c("Foo and bar", "baz and qux and quux"))
compare_dplyr_binding(
- .input %>%
- mutate(x = strsplit(x, "and")) %>%
+ .input |>
+ mutate(x = strsplit(x, "and")) |>
collect(),
df,
# `ignore_attr = TRUE` because the vctr coming back from arrow (ListArray)
@@ -514,56 +514,56 @@ test_that("strsplit and str_split", {
ignore_attr = TRUE
)
compare_dplyr_binding(
- .input %>%
- mutate(x = strsplit(x, "and.*", fixed = TRUE)) %>%
+ .input |>
+ mutate(x = strsplit(x, "and.*", fixed = TRUE)) |>
collect(),
df,
ignore_attr = TRUE
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
a = strsplit(x, " +and +"),
a2 = base::strsplit(x, " +and +")
- ) %>%
+ ) |>
collect(),
df,
ignore_attr = TRUE
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
a = str_split(x, "and"),
a2 = stringr::str_split(x, "and")
- ) %>%
+ ) |>
collect(),
df,
ignore_attr = TRUE
)
compare_dplyr_binding(
- .input %>%
- mutate(x = str_split(x, "and", n = 2)) %>%
+ .input |>
+ mutate(x = str_split(x, "and", n = 2)) |>
collect(),
df,
ignore_attr = TRUE
)
compare_dplyr_binding(
- .input %>%
- mutate(x = str_split(x, fixed("and"), n = 2)) %>%
+ .input |>
+ mutate(x = str_split(x, fixed("and"), n = 2)) |>
collect(),
df,
ignore_attr = TRUE
)
compare_dplyr_binding(
- .input %>%
- mutate(x = str_split(x, regex("and"), n = 2)) %>%
+ .input |>
+ mutate(x = str_split(x, regex("and"), n = 2)) |>
collect(),
df,
ignore_attr = TRUE
)
compare_dplyr_binding(
- .input %>%
- mutate(x = str_split(x, "Foo|bar", n = 2)) %>%
+ .input |>
+ mutate(x = str_split(x, "Foo|bar", n = 2)) |>
collect(),
df,
ignore_attr = TRUE
@@ -574,15 +574,15 @@ test_that("strrep and str_dup", {
df <- tibble(x = c("foo1", " \tB a R\n", "!apACHe aRroW!"))
for (times in 0:8) {
compare_dplyr_binding(
- .input %>%
- mutate(x = strrep(x, times)) %>%
+ .input |>
+ mutate(x = strrep(x, times)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = str_dup(x, times)) %>%
+ .input |>
+ mutate(x = str_dup(x, times)) |>
collect(),
df
)
@@ -592,7 +592,7 @@ test_that("strrep and str_dup", {
test_that("str_to_lower, str_to_upper, and str_to_title", {
df <- tibble(x = c("foo1", " \tB a R\n", "!apACHe aRroW!"))
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
x_lower = str_to_lower(x),
x_upper = str_to_upper(x),
@@ -600,7 +600,7 @@ test_that("str_to_lower, str_to_upper, and str_to_title", {
x_lower_nmspc = stringr::str_to_lower(x),
x_upper_nmspc = stringr::str_to_upper(x),
x_title_nmspc = stringr::str_to_title(x)
- ) %>%
+ ) |>
collect(),
df
)
@@ -629,17 +629,17 @@ test_that("arrow_*_split_whitespace functions", {
# use default option values
expect_equal(
- df_ascii %>%
- Table$create() %>%
- mutate(x = arrow_ascii_split_whitespace(x)) %>%
+ df_ascii |>
+ Table$create() |>
+ mutate(x = arrow_ascii_split_whitespace(x)) |>
collect(),
df_split,
ignore_attr = TRUE
)
expect_equal(
- df_utf8 %>%
- Table$create() %>%
- mutate(x = arrow_utf8_split_whitespace(x)) %>%
+ df_utf8 |>
+ Table$create() |>
+ mutate(x = arrow_utf8_split_whitespace(x)) |>
collect(),
df_split,
ignore_attr = TRUE
@@ -647,21 +647,21 @@ test_that("arrow_*_split_whitespace functions", {
# specify non-default option values
expect_equal(
- df_ascii %>%
- Table$create() %>%
+ df_ascii |>
+ Table$create() |>
mutate(
x = arrow_ascii_split_whitespace(x, options = list(max_splits = 1, reverse = TRUE))
- ) %>%
+ ) |>
collect(),
tibble(x = list(c("Foo\nand", "bar"), c("baz\tand qux and", "quux"))),
ignore_attr = TRUE
)
expect_equal(
- df_utf8 %>%
- Table$create() %>%
+ df_utf8 |>
+ Table$create() |>
mutate(
x = arrow_utf8_split_whitespace(x, options = list(max_splits = 1, reverse = TRUE))
- ) %>%
+ ) |>
collect(),
tibble(x = list(c("Foo\u00A0and", "bar"), c("baz\u2006and\u1680qux\u3000and", "quux"))),
ignore_attr = TRUE
@@ -727,8 +727,8 @@ test_that("backreferences in pattern in string detection", {
df <- tibble(x = c("Foo", "bar"))
compare_dplyr_binding(
- .input %>%
- filter(str_detect(x, regex("F([aeiou])\\1"))) %>%
+ .input |>
+ filter(str_detect(x, regex("F([aeiou])\\1"))) |>
collect(),
df
)
@@ -738,30 +738,30 @@ test_that("backreferences (substitutions) in string replacement", {
df <- tibble(x = c("Foo", "bar"))
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(desc = sub(
"(?:https?|ftp)://([^/\r\n]+)(/[^\r\n]*)?",
"path `\\2` on server `\\1`",
url
- )) %>%
+ )) |>
collect(),
tibble(url = "https://arrow.apache.org/docs/r/")
)
compare_dplyr_binding(
- .input %>%
- transmute(x = str_replace(x, "^(\\w)o(.*)", "\\1\\2p")) %>%
+ .input |>
+ transmute(x = str_replace(x, "^(\\w)o(.*)", "\\1\\2p")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(x = str_replace(x, regex("^(\\w)o(.*)", ignore_case = TRUE), "\\1\\2p")) %>%
+ .input |>
+ transmute(x = str_replace(x, regex("^(\\w)o(.*)", ignore_case = TRUE), "\\1\\2p")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- transmute(x = str_replace(x, regex("^(\\w)o(.*)", ignore_case = TRUE), "\\1\\2p")) %>%
+ .input |>
+ transmute(x = str_replace(x, regex("^(\\w)o(.*)", ignore_case = TRUE), "\\1\\2p")) |>
collect(),
df
)
@@ -773,16 +773,16 @@ test_that("edge cases in string detection and replacement", {
# this test does not use compare_dplyr_binding() because base::sub() and
# base::grepl() do not support ignore.case = TRUE when fixed = TRUE.
expect_equal(
- tibble(x = c("\\Q\\e\\D")) %>%
- Table$create() %>%
- filter(grepl("\\E", x, ignore.case = TRUE, fixed = TRUE)) %>%
+ tibble(x = c("\\Q\\e\\D")) |>
+ Table$create() |>
+ filter(grepl("\\E", x, ignore.case = TRUE, fixed = TRUE)) |>
collect(),
tibble(x = c("\\Q\\e\\D"))
)
expect_equal(
- tibble(x = c("\\Q\\e\\D")) %>%
- Table$create() %>%
- transmute(x = sub("\\E", "\\L", x, ignore.case = TRUE, fixed = TRUE)) %>%
+ tibble(x = c("\\Q\\e\\D")) |>
+ Table$create() |>
+ transmute(x = sub("\\E", "\\L", x, ignore.case = TRUE, fixed = TRUE)) |>
collect(),
tibble(x = c("\\Q\\L\\D"))
)
@@ -790,14 +790,14 @@ test_that("edge cases in string detection and replacement", {
# test that a user's "(?i)" prefix does not break the "(?i)" prefix that's
# added in case-insensitive regex match/replace
compare_dplyr_binding(
- .input %>%
- filter(grepl("(?i)^[abc]{3}$", x, ignore.case = TRUE, fixed = FALSE)) %>%
+ .input |>
+ filter(grepl("(?i)^[abc]{3}$", x, ignore.case = TRUE, fixed = FALSE)) |>
collect(),
tibble(x = c("ABC"))
)
compare_dplyr_binding(
- .input %>%
- transmute(x = sub("(?i)^[abc]{3}$", "123", x, ignore.case = TRUE, fixed = FALSE)) %>%
+ .input |>
+ transmute(x = sub("(?i)^[abc]{3}$", "123", x, ignore.case = TRUE, fixed = FALSE)) |>
collect(),
tibble(x = c("ABC"))
)
@@ -807,39 +807,39 @@ test_that("arrow_find_substring and arrow_find_substring_regex", {
df <- tibble(x = c("Foo and Bar", "baz and qux and quux"))
expect_equal(
- df %>%
- Table$create() %>%
- mutate(x = arrow_find_substring(x, options = list(pattern = "b"))) %>%
+ df |>
+ Table$create() |>
+ mutate(x = arrow_find_substring(x, options = list(pattern = "b"))) |>
collect(),
tibble(x = c(-1, 0))
)
expect_equal(
- df %>%
- Table$create() %>%
+ df |>
+ Table$create() |>
mutate(x = arrow_find_substring(
x,
options = list(pattern = "b", ignore_case = TRUE)
- )) %>%
+ )) |>
collect(),
tibble(x = c(8, 0))
)
expect_equal(
- df %>%
- Table$create() %>%
+ df |>
+ Table$create() |>
mutate(x = arrow_find_substring_regex(
x,
options = list(pattern = "^[fb]")
- )) %>%
+ )) |>
collect(),
tibble(x = c(-1, 0))
)
expect_equal(
- df %>%
- Table$create() %>%
+ df |>
+ Table$create() |>
mutate(x = arrow_find_substring_regex(
x,
options = list(pattern = "[AEIOU]", ignore_case = TRUE)
- )) %>%
+ )) |>
collect(),
tibble(x = c(1, 1))
)
@@ -851,31 +851,31 @@ test_that("stri_reverse and arrow_ascii_reverse functions", {
df_utf8 <- tibble(x = c("Foo\u00A0\u0061nd\u00A0bar", "\u0062az\u00A0and\u00A0qux\u3000and\u00A0quux"))
compare_dplyr_binding(
- .input %>%
- mutate(x = stri_reverse(x)) %>%
+ .input |>
+ mutate(x = stri_reverse(x)) |>
collect(),
df_utf8
)
compare_dplyr_binding(
- .input %>%
- mutate(x = stri_reverse(x)) %>%
+ .input |>
+ mutate(x = stri_reverse(x)) |>
collect(),
df_ascii
)
expect_equal(
- df_ascii %>%
- Table$create() %>%
- mutate(x = arrow_ascii_reverse(x)) %>%
+ df_ascii |>
+ Table$create() |>
+ mutate(x = arrow_ascii_reverse(x)) |>
collect(),
tibble(x = c("rab dna\nooF", "xuuq dna xuq dna\tzab"))
)
expect_error(
- df_utf8 %>%
- Table$create() %>%
- mutate(x = arrow_ascii_reverse(x)) %>%
+ df_utf8 |>
+ Table$create() |>
+ mutate(x = arrow_ascii_reverse(x)) |>
collect(),
"Invalid: Non-ASCII sequence in input"
)
@@ -886,54 +886,54 @@ test_that("str_like", {
# No match - entire string
compare_dplyr_binding(
- .input %>%
- mutate(x = str_like(x, "baz")) %>%
+ .input |>
+ mutate(x = str_like(x, "baz")) |>
collect(),
df
)
# with namespacing
compare_dplyr_binding(
- .input %>%
- mutate(x = stringr::str_like(x, "baz")) %>%
+ .input |>
+ mutate(x = stringr::str_like(x, "baz")) |>
collect(),
df
)
# Match - entire string
compare_dplyr_binding(
- .input %>%
- mutate(x = str_like(x, "Foo and bar")) %>%
+ .input |>
+ mutate(x = str_like(x, "Foo and bar")) |>
collect(),
df
)
# Wildcard
compare_dplyr_binding(
- .input %>%
- mutate(x = str_like(x, "f%", ignore_case = TRUE)) %>%
+ .input |>
+ mutate(x = str_like(x, "f%", ignore_case = TRUE)) |>
collect(),
df
)
# Ignore case
compare_dplyr_binding(
- .input %>%
- mutate(x = str_like(x, "f%", ignore_case = FALSE)) %>%
+ .input |>
+ mutate(x = str_like(x, "f%", ignore_case = FALSE)) |>
collect(),
df
)
# Single character
compare_dplyr_binding(
- .input %>%
- mutate(x = str_like(x, "_a%")) %>%
+ .input |>
+ mutate(x = str_like(x, "_a%")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = str_like(x, "%baz%")) %>%
+ .input |>
+ mutate(x = str_like(x, "%baz%")) |>
collect(),
df
)
@@ -943,39 +943,39 @@ test_that("str_pad", {
df <- tibble(x = c("Foo and bar", "baz and qux and quux"))
compare_dplyr_binding(
- .input %>%
- mutate(x = str_pad(x, width = 31)) %>%
+ .input |>
+ mutate(x = str_pad(x, width = 31)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = str_pad(x, width = 30, side = "right")) %>%
+ .input |>
+ mutate(x = str_pad(x, width = 30, side = "right")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = str_pad(x, width = 31, side = "left", pad = "+")) %>%
+ .input |>
+ mutate(x = str_pad(x, width = 31, side = "left", pad = "+")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = str_pad(x, width = 10, side = "left", pad = "+")) %>%
+ .input |>
+ mutate(x = str_pad(x, width = 10, side = "left", pad = "+")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
a = str_pad(x, width = 31, side = "both"),
a2 = stringr::str_pad(x, width = 31, side = "both")
- ) %>%
+ ) |>
collect(),
df
)
@@ -985,67 +985,67 @@ test_that("substr with string()", {
df <- tibble(x = "Apache Arrow")
compare_dplyr_binding(
- .input %>%
- mutate(y = substr(x, 1, 6)) %>%
+ .input |>
+ mutate(y = substr(x, 1, 6)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = substr(x, 0, 6)) %>%
+ .input |>
+ mutate(y = substr(x, 0, 6)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = substr(x, -1, 6)) %>%
+ .input |>
+ mutate(y = substr(x, -1, 6)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = substr(x, 6, 1)) %>%
+ .input |>
+ mutate(y = substr(x, 6, 1)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = substr(x, -1, -2)) %>%
+ .input |>
+ mutate(y = substr(x, -1, -2)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = substr(x, 9, 6)) %>%
+ .input |>
+ mutate(y = substr(x, 9, 6)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = substr(x, 1, 6)) %>%
+ .input |>
+ mutate(y = substr(x, 1, 6)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = substr(x, 8, 12)) %>%
+ .input |>
+ mutate(y = substr(x, 8, 12)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = substr(x, -5, -1),
y2 = base::substr(x, -5, -1)
- ) %>%
+ ) |>
collect(),
df
)
@@ -1067,9 +1067,9 @@ test_that("substr with binary()", {
# Check a field reference input
expect_identical(
- batch %>%
- transmute(y = substr(x, 1, 3)) %>%
- collect() %>%
+ batch |>
+ transmute(y = substr(x, 1, 3)) |>
+ collect() |>
# because of the arrow_binary class
mutate(y = unclass(y)),
tibble::tibble(y = list(charToRaw("Apa")))
@@ -1078,9 +1078,9 @@ test_that("substr with binary()", {
# Check a Scalar input
scalar <- Scalar$create(batch$x)
expect_identical(
- batch %>%
- transmute(y = substr(scalar, 1, 3)) %>%
- collect() %>%
+ batch |>
+ transmute(y = substr(scalar, 1, 3)) |>
+ collect() |>
# because of the arrow_binary class
mutate(y = unclass(y)),
tibble::tibble(y = list(charToRaw("Apa")))
@@ -1093,11 +1093,11 @@ test_that("substring", {
df <- tibble(x = "Apache Arrow")
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = substring(x, 1, 6),
y2 = base::substring(x, 1, 6)
- ) %>%
+ ) |>
collect(),
df
)
@@ -1107,83 +1107,83 @@ test_that("str_sub", {
df <- tibble(x = "Apache Arrow")
compare_dplyr_binding(
- .input %>%
- mutate(y = str_sub(x, 1, 6)) %>%
+ .input |>
+ mutate(y = str_sub(x, 1, 6)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = str_sub(x, 0, 6)) %>%
+ .input |>
+ mutate(y = str_sub(x, 0, 6)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = str_sub(x, -1, 6)) %>%
+ .input |>
+ mutate(y = str_sub(x, -1, 6)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = str_sub(x, 6, 1)) %>%
+ .input |>
+ mutate(y = str_sub(x, 6, 1)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = str_sub(x, -1, -2)) %>%
+ .input |>
+ mutate(y = str_sub(x, -1, -2)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = str_sub(x, -1, 3)) %>%
+ .input |>
+ mutate(y = str_sub(x, -1, 3)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = str_sub(x, 9, 6)) %>%
+ .input |>
+ mutate(y = str_sub(x, 9, 6)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = str_sub(x, 1, 6)) %>%
+ .input |>
+ mutate(y = str_sub(x, 1, 6)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(y = str_sub(x, 8, 12)) %>%
+ .input |>
+ mutate(y = str_sub(x, 8, 12)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = str_sub(x, -5, -1),
y2 = stringr::str_sub(x, -5, -1)
- ) %>%
+ ) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
y = str_sub(x, 1, -3),
y2 = stringr::str_sub(x, 1, -3)
- ) %>%
+ ) |>
collect(),
df
)
@@ -1204,123 +1204,123 @@ test_that("str_starts, str_ends, startsWith, endsWith", {
df <- tibble(x = c("Foo", "bar", "baz", "qux", NA_character_))
compare_dplyr_binding(
- .input %>%
- filter(str_starts(x, "b.*")) %>%
+ .input |>
+ filter(str_starts(x, "b.*")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(str_starts(x, "b.*", negate = TRUE)) %>%
+ .input |>
+ filter(str_starts(x, "b.*", negate = TRUE)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(str_starts(x, fixed("b.*"))) %>%
+ .input |>
+ filter(str_starts(x, fixed("b.*"))) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(str_starts(x, fixed("b"))) %>%
+ .input |>
+ filter(str_starts(x, fixed("b"))) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
a = str_starts(x, "b.*"),
a2 = stringr::str_starts(x, "b.*"),
b = str_starts(x, "b.*", negate = TRUE),
c = str_starts(x, fixed("b")),
d = str_starts(x, fixed("b"), negate = TRUE)
- ) %>%
+ ) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(str_ends(x, "r")) %>%
+ .input |>
+ filter(str_ends(x, "r")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(str_ends(x, "r", negate = TRUE)) %>%
+ .input |>
+ filter(str_ends(x, "r", negate = TRUE)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(str_ends(x, fixed("r$"))) %>%
+ .input |>
+ filter(str_ends(x, fixed("r$"))) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(str_ends(x, fixed("r"))) %>%
+ .input |>
+ filter(str_ends(x, fixed("r"))) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
a = str_ends(x, "r"),
a2 = stringr::str_ends(x, "r"),
b = str_ends(x, "r", negate = TRUE),
c = str_ends(x, fixed("r")),
d = str_ends(x, fixed("r"), negate = TRUE)
- ) %>%
+ ) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(startsWith(x, "b")) %>%
+ .input |>
+ filter(startsWith(x, "b")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(endsWith(x, "r")) %>%
+ .input |>
+ filter(endsWith(x, "r")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(startsWith(x, "b.*")) %>%
+ .input |>
+ filter(startsWith(x, "b.*")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- filter(endsWith(x, "r$")) %>%
+ .input |>
+ filter(endsWith(x, "r$")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
transmute(
a = startsWith(x, "b"),
b = endsWith(x, "r"),
a2 = base::startsWith(x, "b"),
b2 = base::endsWith(x, "r")
- ) %>%
+ ) |>
collect(),
df
)
@@ -1333,57 +1333,57 @@ test_that("str_count", {
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
a_count = str_count(cities, pattern = "a"),
a_count_nmspc = stringr::str_count(cities, pattern = "a")
- ) %>%
+ ) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(p_count = str_count(cities, pattern = "d")) %>%
+ .input |>
+ mutate(p_count = str_count(cities, pattern = "d")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(p_count = str_count(cities,
pattern = regex("d", ignore_case = TRUE)
- )) %>%
+ )) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(e_count = str_count(cities, pattern = "u")) %>%
+ .input |>
+ mutate(e_count = str_count(cities, pattern = "u")) |>
collect(),
df
)
# call_binding("str_count", ) is not vectorised over pattern
compare_dplyr_binding(
- .input %>%
- mutate(let_count = str_count(cities, pattern = c("a", "b", "e", "g", "p", "n", "s"))) %>%
+ .input |>
+ mutate(let_count = str_count(cities, pattern = c("a", "b", "e", "g", "p", "n", "s"))) |>
collect(),
df,
warning = TRUE
)
compare_dplyr_binding(
- .input %>%
- mutate(dots_count = str_count(dots, ".")) %>%
+ .input |>
+ mutate(dots_count = str_count(dots, ".")) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(dots_count = str_count(dots, fixed("."))) %>%
+ .input |>
+ mutate(dots_count = str_count(dots, fixed("."))) |>
collect(),
df
)
@@ -1391,13 +1391,13 @@ test_that("str_count", {
test_that("base::tolower and base::toupper", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
verse_to_upper = toupper(verses),
verse_to_lower = tolower(verses),
verse_to_upper_nmspc = base::toupper(verses),
verse_to_lower_nmspc = base::tolower(verses)
- ) %>%
+ ) |>
collect(),
tbl
)
@@ -1406,11 +1406,11 @@ test_that("base::tolower and base::toupper", {
test_that("namespaced unary and binary string functions", {
# str_length and stringi::stri_reverse
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
verse_length = stringr::str_length(verses),
reverses_verse = stringi::stri_reverse(verses)
- ) %>%
+ ) |>
collect(),
tbl
)
@@ -1419,15 +1419,15 @@ test_that("namespaced unary and binary string functions", {
df <- tibble(x = c("foo1", " \tB a R\n", "!apACHe aRroW!"))
for (times in 0:8) {
compare_dplyr_binding(
- .input %>%
- mutate(x = base::strrep(x, times)) %>%
+ .input |>
+ mutate(x = base::strrep(x, times)) |>
collect(),
df
)
compare_dplyr_binding(
- .input %>%
- mutate(x = stringr::str_dup(x, times)) %>%
+ .input |>
+ mutate(x = stringr::str_dup(x, times)) |>
collect(),
df
)
@@ -1436,8 +1436,8 @@ test_that("namespaced unary and binary string functions", {
test_that("nchar with namespacing", {
compare_dplyr_binding(
- .input %>%
- mutate(verses_nchar = base::nchar(verses)) %>%
+ .input |>
+ mutate(verses_nchar = base::nchar(verses)) |>
collect(),
tbl
)
@@ -1445,7 +1445,7 @@ test_that("nchar with namespacing", {
test_that("str_trim()", {
compare_dplyr_binding(
- .input %>%
+ .input |>
mutate(
left_trim_padded_string = str_trim(padded_strings, "left"),
right_trim_padded_string = str_trim(padded_strings, "right"),
@@ -1453,7 +1453,7 @@ test_that("str_trim()", {
left_trim_padded_string_nmspc = stringr::str_trim(padded_strings, "left"),
right_trim_padded_string_nmspc = stringr::str_trim(padded_strings, "right"),
both_trim_padded_string_nmspc = stringr::str_trim(padded_strings, "both")
... 6272 lines suppressed ...