Skip to content

Commit 48a2e88

Browse files
authored
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 <[email protected]> Signed-off-by: Bryce Mecum <[email protected]>
1 parent 047ac04 commit 48a2e88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3440
-3433
lines changed

r/R/dataset-write.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@
105105
#' # output directory will be different.
106106
#' library(dplyr)
107107
#' two_levels_tree_2 <- tempfile()
108-
#' mtcars %>%
109-
#' group_by(cyl, gear) %>%
108+
#' mtcars |>
109+
#' group_by(cyl, gear) |>
110110
#' write_dataset(two_levels_tree_2)
111111
#' list.files(two_levels_tree_2, recursive = TRUE)
112112
#'
@@ -115,8 +115,8 @@
115115
#'
116116
#' # Write a structure X/Y/part-Z.parquet.
117117
#' two_levels_tree_no_hive <- tempfile()
118-
#' mtcars %>%
119-
#' group_by(cyl, gear) %>%
118+
#' mtcars |>
119+
#' group_by(cyl, gear) |>
120120
#' write_dataset(two_levels_tree_no_hive, hive_style = FALSE)
121121
#' list.files(two_levels_tree_no_hive, recursive = TRUE)
122122
#' @export

r/R/dplyr-funcs-augmented.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@
2828
#' augmented column.
2929
#'
3030
#' @examples \dontrun{
31-
#' open_dataset("nyc-taxi") %>% mutate(
31+
#' open_dataset("nyc-taxi") |> mutate(
3232
#' file =
3333
#' add_filename()
3434
#' )
3535
#'
3636
#' # To use a verb like mutate() with add_filename() we need to first call
3737
#' # compute()
38-
#' open_dataset("nyc-taxi") %>%
39-
#' mutate(file = add_filename()) %>%
40-
#' compute() %>%
38+
#' open_dataset("nyc-taxi") |>
39+
#' mutate(file = add_filename()) |>
40+
#' compute() |>
4141
#' mutate(filename_length = nchar(file))
4242
#' }
4343
#'

r/R/dplyr-funcs-type.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ register_bindings_type <- function() {
3838
#'
3939
#' @examples
4040
#' \dontrun{
41-
#' mtcars %>%
42-
#' arrow_table() %>%
41+
#' mtcars |>
42+
#' arrow_table() |>
4343
#' mutate(cyl = cast(cyl, string()))
4444
#' }
4545
#' @keywords internal

r/R/dplyr-summarize.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ do_arrow_summarize <- function(.data, ..., .groups = NULL) {
5757
# and aggregations, but that's not how Acero works. For example, for us to do
5858
# summarize(mean = sum(x) / n())
5959
# we basically have to translate it into
60-
# summarize(..temp0 = sum(x), ..temp1 = n()) %>%
61-
# mutate(mean = ..temp0 / ..temp1) %>%
60+
# summarize(..temp0 = sum(x), ..temp1 = n()) |>
61+
# mutate(mean = ..temp0 / ..temp1) |>
6262
# select(-starts_with("..temp"))
6363
# That is, "first aggregate, then transform the result further."
6464
#
@@ -97,7 +97,7 @@ do_arrow_summarize <- function(.data, ..., .groups = NULL) {
9797
# One last check: it's possible that an expression like y - mean(y) would
9898
# successfully evaluate, but it's not supported. It gets transformed to:
9999
# nolint start
100-
# summarize(..temp0 = mean(y)) %>%
100+
# summarize(..temp0 = mean(y)) |>
101101
# mutate(y - ..temp0)
102102
# nolint end
103103
# but y is not in the schema of the data after summarize(). To catch this

r/R/dplyr.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,10 @@ tail.arrow_dplyr_query <- function(x, n = 6L, ...) {
279279
#'
280280
#' @examplesIf arrow_with_dataset() && requireNamespace("dplyr", quietly = TRUE)
281281
#' library(dplyr)
282-
#' mtcars %>%
283-
#' arrow_table() %>%
284-
#' filter(mpg > 20) %>%
285-
#' mutate(x = gear / carb) %>%
282+
#' mtcars |>
283+
#' arrow_table() |>
284+
#' filter(mpg > 20) |>
285+
#' mutate(x = gear / carb) |>
286286
#' show_exec_plan()
287287
show_exec_plan <- function(x) {
288288
result <- as_record_batch_reader(as_adq(x))

r/R/duckdb.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
#'
4646
#' ds <- InMemoryDataset$create(mtcars)
4747
#'
48-
#' ds %>%
49-
#' filter(mpg < 30) %>%
50-
#' group_by(cyl) %>%
51-
#' to_duckdb() %>%
48+
#' ds |>
49+
#' filter(mpg < 30) |>
50+
#' group_by(cyl) |>
51+
#' to_duckdb() |>
5252
#' slice_min(disp)
5353
to_duckdb <- function(.data,
5454
con = arrow_duck_connection(),
@@ -154,12 +154,12 @@ duckdb_disconnector <- function(con, tbl_name) {
154154
#'
155155
#' ds <- InMemoryDataset$create(mtcars)
156156
#'
157-
#' ds %>%
158-
#' filter(mpg < 30) %>%
159-
#' to_duckdb() %>%
160-
#' group_by(cyl) %>%
161-
#' summarize(mean_mpg = mean(mpg, na.rm = TRUE)) %>%
162-
#' to_arrow() %>%
157+
#' ds |>
158+
#' filter(mpg < 30) |>
159+
#' to_duckdb() |>
160+
#' group_by(cyl) |>
161+
#' summarize(mean_mpg = mean(mpg, na.rm = TRUE)) |>
162+
#' to_arrow() |>
163163
#' collect()
164164
to_arrow <- function(.data) {
165165
# If this is an Arrow object already, return quickly since we're already Arrow

r/R/type.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,11 @@ NestedType <- R6Class("NestedType", inherit = DataType)
408408
#' # You can also use `cast()` in an Arrow dplyr query.
409409
#' if (requireNamespace("dplyr", quietly = TRUE)) {
410410
#' library(dplyr, warn.conflicts = FALSE)
411-
#' arrow_table(mtcars) %>%
411+
#' arrow_table(mtcars) |>
412412
#' transmute(
413413
#' col1 = cast(cyl, string()),
414414
#' col2 = cast(cyl, int8())
415-
#' ) %>%
415+
#' ) |>
416416
#' compute()
417417
#' }
418418
int8 <- function() Int8__initialize()

r/R/udf.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
#' auto_convert = TRUE
6767
#' )
6868
#'
69-
#' as_arrow_table(mtcars) %>%
70-
#' transmute(mpg, mpg_predicted = mtcars_predict_mpg(disp, cyl)) %>%
71-
#' collect() %>%
69+
#' as_arrow_table(mtcars) |>
70+
#' transmute(mpg, mpg_predicted = mtcars_predict_mpg(disp, cyl)) |>
71+
#' collect() |>
7272
#' head()
7373
#'
7474
register_scalar_function <- function(name, fun, in_type, out_type,

r/data-raw/codegen.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ suppressPackageStartupMessages({
4141
})
4242

4343
get_exported_functions <- function(decorations, export_tag) {
44-
out <- decorations %>%
45-
filter(decoration %in% paste0(export_tag, "::export")) %>%
46-
mutate(functions = map(context, decor:::parse_cpp_function)) %>%
44+
out <- decorations |>
45+
filter(decoration %in% paste0(export_tag, "::export")) |>
46+
mutate(functions = map(context, decor:::parse_cpp_function)) |>
4747
{
4848
vec_cbind(., vec_rbind(!!!pull(., functions)))
49-
} %>%
50-
select(-functions) %>%
49+
} |>
50+
select(-functions) |>
5151
mutate(decoration = sub("::export", "", decoration))
5252
message(glue("*** > {n} functions decorated with [[{tags}::export]]", n = nrow(out), tags = paste0(export_tag, collapse = "|")))
5353
out
@@ -123,8 +123,8 @@ extern "C" SEXP {sexp_signature}{{
123123
#endif\n\n')
124124
}
125125

126-
cpp_functions_definitions <- arrow_exports %>%
127-
select(name, return_type, args, file, line, decoration) %>%
126+
cpp_functions_definitions <- arrow_exports |>
127+
select(name, return_type, args, file, line, decoration) |>
128128
pmap_chr(function(name, return_type, args, file, line, decoration) {
129129
sexp_params <- glue_collapse_data(args, "SEXP {name}_sexp")
130130
sexp_signature <- glue("_arrow_{name}({sexp_params})")
@@ -147,14 +147,14 @@ cpp_functions_definitions <- arrow_exports %>%
147147
",
148148
sep = "\n"
149149
)
150-
}) %>%
150+
}) |>
151151
glue_collapse(sep = "\n")
152152

153-
cpp_functions_registration <- arrow_exports %>%
154-
select(name, return_type, args) %>%
153+
cpp_functions_registration <- arrow_exports |>
154+
select(name, return_type, args) |>
155155
pmap_chr(function(name, return_type, args) {
156156
glue('\t\t{{ "_arrow_{name}", (DL_FUNC) &_arrow_{name}, {nrow(args)}}}, ')
157-
}) %>%
157+
}) |>
158158
glue_collapse(sep = "\n")
159159

160160
cpp_file_header <- '// Generated by using data-raw/codegen.R -> do not edit by hand
@@ -198,8 +198,8 @@ static const R_CallMethodDef CallEntries[] = {
198198

199199
write_if_modified(arrow_exports_cpp, "src/arrowExports.cpp")
200200

201-
r_functions <- arrow_exports %>%
202-
select(name, return_type, args) %>%
201+
r_functions <- arrow_exports |>
202+
select(name, return_type, args) |>
203203
pmap_chr(function(name, return_type, args) {
204204
params <- if (nrow(args)) {
205205
paste0(", ", glue_collapse_data(args, "{name}"))
@@ -220,7 +220,7 @@ r_functions <- arrow_exports %>%
220220
list_params = glue_collapse_data(args, "{name}"),
221221
sep = "\n"
222222
)
223-
}) %>%
223+
}) |>
224224
glue_collapse(sep = "\n")
225225

226226
arrow_exports_r <- glue::glue("

r/data-raw/docgen.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ render_fun <- function(fun, pkg_fun, notes) {
115115

116116
# This renders a bulleted list under a package heading
117117
render_pkg <- function(df, pkg) {
118-
bullets <- df %>%
119-
transmute(render_fun(fun, pkg_fun, notes)) %>%
118+
bullets <- df |>
119+
transmute(render_fun(fun, pkg_fun, notes)) |>
120120
pull()
121121
header <- paste0("## ", pkg, "\n#'")
122122
# Some packages have global notes to include
@@ -158,7 +158,7 @@ docs <- c(docs, setNames(rep(list(NULL), length(tidyselect)), tidyselect))
158158
fun_df <- tibble::tibble(
159159
pkg_fun = names(docs),
160160
notes = docs
161-
) %>%
161+
) |>
162162
mutate(
163163
has_pkg = grepl("::", pkg_fun),
164164
fun = sub("^.*?:{+}", "", pkg_fun),
@@ -167,7 +167,7 @@ fun_df <- tibble::tibble(
167167
pkg = if_else(has_pkg, pkg, "base"),
168168
# Flatten notes to a single string
169169
notes = map_chr(notes, ~ paste(., collapse = "\n#' "))
170-
) %>%
170+
) |>
171171
arrange(pkg, fun)
172172

173173
# Group by package name and render the lists
@@ -182,13 +182,13 @@ dplyr_verbs <- c(
182182
verb_bullets <- tibble::tibble(
183183
fun = names(dplyr_verbs),
184184
notes = dplyr_verbs
185-
) %>%
185+
) |>
186186
mutate(
187187
pkg_fun = paste0("dplyr::", fun),
188188
notes = map_chr(notes, ~ paste(., collapse = " "))
189-
) %>%
190-
arrange(fun) %>%
191-
transmute(render_fun(fun, pkg_fun, notes)) %>%
189+
) |>
190+
arrange(fun) |>
191+
transmute(render_fun(fun, pkg_fun, notes)) |>
192192
pull()
193193

194194
writeLines(

0 commit comments

Comments
 (0)