Skip to content

Commit c360b11

Browse files
Remove {magrittr} pipes and {purrr} lambdas (#436)
* Fix features * Fix source * Fix rust sitrep * Fix eval * Fix toml serialization 1 * Fix toml_serialization 2 * Fix test-eval * Drop import
1 parent b55d0c5 commit c360b11

File tree

8 files changed

+38
-39
lines changed

8 files changed

+38
-39
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export(use_extendr)
2626
export(use_msrv)
2727
export(vendor_pkgs)
2828
export(write_license_note)
29-
importFrom(dplyr,"%>%")
3029
importFrom(dplyr,mutate)
3130
importFrom(glue,glue)
3231
importFrom(glue,glue_collapse)

R/eval.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn {fn_name}() -> Result<Robj> {{
119119
#' `NULL` if no such dll is loaded.
120120
#' @noRd
121121
find_loaded_dll <- function(name) {
122-
dlls <- keep(getLoadedDLLs(), ~ .x[["name"]] == name)
122+
dlls <- keep(getLoadedDLLs(), \(.x) .x[["name"]] == name)
123123
if (rlang::is_empty(dlls)) {
124124
NULL
125125
} else {

R/features.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ validate_extendr_features <- function(features, suppress_warnings) {
1616

1717
features <- unique(features)
1818

19-
unknown_features <- features %>%
20-
setdiff(features_config$known_features) %>%
19+
unknown_features <- features |>
20+
setdiff(features_config$known_features) |>
2121
discard_empty()
2222

2323
if (!isTRUE(suppress_warnings) && length(unknown_features) > 0) {

R/rextendr.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#' @keywords internal
77
"_PACKAGE"
88

9-
#' @importFrom dplyr mutate %>%
9+
#' @importFrom dplyr mutate
1010
#' @importFrom glue glue glue_collapse
1111
#' @importFrom rlang dots_list names2 as_function is_missing is_atomic is_null
1212
#' @importFrom rlang is_na .data .env caller_env as_name as_label enquo %||%

R/rust_sitrep.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,32 +120,32 @@ rustup_toolchain_target <- function() {
120120
host_index <- grep("host:", output)
121121
gsub("host: ", "", output[host_index])
122122
} else {
123-
try_exec_cmd("rustup", "show") %>%
124-
stringi::stri_sub(from = 15L) %>%
123+
try_exec_cmd("rustup", "show") |>
124+
stringi::stri_sub(from = 15L) |>
125125
vctrs::vec_slice(1L)
126126
}
127127

128128
# > rustup toolchain list
129129
# stable-x86_64-pc-windows-msvc
130130
# nightly-x86_64-pc-windows-msvc (default)
131-
toolchain_info <- try_exec_cmd("rustup", c("toolchain", "list")) %>%
132-
stringi::stri_trim_both() %>%
131+
toolchain_info <- try_exec_cmd("rustup", c("toolchain", "list")) |>
132+
stringi::stri_trim_both() |>
133133
verify_toolchains(host)
134134

135135
if (is.null(toolchain_info[["missing_toolchain"]]) && is.null(toolchain_info[["candidate_toolchains"]])) {
136136
# > rustup target list --installed
137137
# i686-pc-windows-gnu
138138
# x86_64-pc-windows-gnu
139139
# x86_64-pc-windows-msvc
140-
targets_info <- try_exec_cmd("rustup", c("target", "list", "--installed")) %>%
141-
stringi::stri_trim_both() %>%
140+
targets_info <- try_exec_cmd("rustup", c("target", "list", "--installed")) |>
141+
stringi::stri_trim_both() |>
142142
verify_targets(host)
143143
} else {
144144
targets_info <- list()
145145
}
146146

147-
list(host = host) %>%
148-
append(targets_info) %>%
147+
list(host = host) |>
148+
append(targets_info) |>
149149
append(toolchain_info)
150150
}
151151

R/source.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ rust_function <- function(code,
239239
if (vctrs::vec_is_empty(options)) {
240240
attr_arg <- ""
241241
} else {
242-
attr_arg <- options %>%
243-
glue::glue_data("{Name} = {RustValue}") %>%
242+
attr_arg <- options |>
243+
glue::glue_data("{Name} = {RustValue}") |>
244244
glue::glue_collapse(sep = ", ")
245245
attr_arg <- glue::glue("({attr_arg})")
246246
}
@@ -405,11 +405,11 @@ invoke_cargo <- function(toolchain, specific_target, dir, profile,
405405
#' @noRd
406406
gather_cargo_output <- function(json_output, level, tty_has_colors) {
407407
rendered_output <-
408-
json_output %>%
408+
json_output |>
409409
keep(
410-
~ .x$reason == "compiler-message" && .x$message$level == level
411-
) %>%
412-
map_chr(~ .x$message$rendered)
410+
\(.x) .x$reason == "compiler-message" && .x$message$level == level
411+
) |>
412+
map_chr(\(.x) .x$message$rendered)
413413

414414
if (!tty_has_colors) {
415415
rendered_output <- cli::ansi_strip(rendered_output)
@@ -446,13 +446,13 @@ check_cargo_output <- function(compilation_result, message_buffer, tty_has_color
446446
cargo_output,
447447
"error",
448448
tty_has_colors
449-
) %>%
449+
) |>
450450
map_chr(
451451
cli::format_inline,
452452
keep_whitespace = TRUE
453-
) %>%
453+
) |>
454454
# removing double new lines with single new line
455-
stringi::stri_replace_all_fixed("\n\n", "\n") %>%
455+
stringi::stri_replace_all_fixed("\n\n", "\n") |>
456456
# ensures that the leading cli style `x` is there
457457
rlang::set_names("x")
458458

R/toml_serialization.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ to_toml <- function(...,
4141
names <- names2(args)
4242

4343
# We disallow unnamed top-level atomic arguments
44-
invalid <- which(map2_lgl(names, args, ~ !nzchar(.x) && is.atomic(.y)))
44+
invalid <- which(map2_lgl(names, args, \(.x, .y) !nzchar(.x) && is.atomic(.y)))
4545

4646
# If such args found, display an error message
4747
if (length(invalid) > 0) {
@@ -97,13 +97,13 @@ get_toml_missing_msg <- function() {
9797
simplify_row <- function(row) {
9898
result <- map_if(
9999
row,
100-
~ is.list(.x) && all(!nzchar(names2(.x))),
101-
~ .x[1],
102-
.else = ~.x
100+
\(.x) is.list(.x) && all(!nzchar(names2(.x))),
101+
\(.x) .x[1],
102+
.else = identity
103103
)
104104
discard(
105105
result,
106-
~ is_na(.x) || is_null(unlist(.x))
106+
\(.x) is_na(.x) || is_null(unlist(.x))
107107
)
108108
}
109109

@@ -203,7 +203,7 @@ format_toml_atomic <- function(x,
203203
"[ ]"
204204
} else {
205205
formatter <- rlang::as_function(.formatter)
206-
items <- glue_collapse(formatter(x, ...), ", ")
206+
items <- glue_collapse(formatter(x), ", ")
207207
if (len > 1L || !is.null(dims)) {
208208
items <- glue("[ {items} ]")
209209
}
@@ -223,9 +223,9 @@ format_toml.character <- function(x,
223223
.str_as_literal = TRUE,
224224
.top_level = FALSE) {
225225
if (isTRUE(.str_as_literal)) {
226-
.formatter <- ~ glue("'{.x}'")
226+
.formatter <- \(.x) glue("'{.x}'")
227227
} else {
228-
.formatter <- ~ glue("\"{escape_dbl_quotes(.x)}\"")
228+
.formatter <- \(.x) glue("\"{escape_dbl_quotes(.x)}\"")
229229
}
230230
format_toml_atomic(
231231
x,
@@ -246,7 +246,7 @@ format_toml.integer <- function(x,
246246
...,
247247
.format_int = .format_int,
248248
.top_level = FALSE,
249-
.formatter = ~ sprintf(.format_int, .x)
249+
.formatter = \(.x) sprintf(.format_int, .x)
250250
)
251251
}
252252

@@ -260,7 +260,7 @@ format_toml.double <- function(x,
260260
...,
261261
.format_dbl = .format_dbl,
262262
.top_level = FALSE,
263-
.formatter = ~ sprintf(.format_dbl, .x)
263+
.formatter = \(.x) sprintf(.format_dbl, .x)
264264
)
265265
}
266266

@@ -272,7 +272,7 @@ format_toml.logical <- function(x,
272272
x,
273273
...,
274274
.top_level = FALSE,
275-
.formatter = ~ ifelse(.x, "true", "false")
275+
.formatter = \(.x) ifelse(.x, "true", "false")
276276
)
277277
}
278278

tests/testthat/test-eval.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ test_that("multiple `rust_eval_deferred()` work correctly", {
2222
provided_values <- seq_len(5)
2323
deferred_handles <- map(
2424
provided_values,
25-
~ rust_eval_deferred(glue::glue("{.x}i32"))
25+
\(.x) rust_eval_deferred(glue::glue("{.x}i32"))
2626
)
2727

28-
obtained_values <- map_int(deferred_handles, ~ (.x)())
28+
obtained_values <- map_int(deferred_handles, rlang::exec)
2929

3030
testthat::expect_equal(
3131
obtained_values,
@@ -50,12 +50,12 @@ test_that("multiple `rust_eval_deferred()` work correctly in reverse order", {
5050

5151
deferred_handles <- map(
5252
provided_values,
53-
~ rust_eval_deferred(glue::glue("{.x}i32"))
53+
\(.x) rust_eval_deferred(glue::glue("{.x}i32"))
5454
)
5555

5656
deferred_handles <- rev(deferred_handles)
5757

58-
obtained_values <- map_int(deferred_handles, ~ (.x)())
58+
obtained_values <- map_int(deferred_handles, rlang::exec)
5959

6060
testthat::expect_equal(
6161
obtained_values,
@@ -99,13 +99,13 @@ test_that("`rust_eval_deferred()` environment cleanup", {
9999
dll_path <- attr(handle, "dll_path")
100100

101101
testthat::expect_true(exists(fn_name))
102-
dlls <- keep(getLoadedDLLs(), ~ .x[["path"]] == dll_path)
102+
dlls <- keep(getLoadedDLLs(), \(.x) .x[["path"]] == dll_path)
103103
testthat::expect_length(dlls, 1L)
104104

105105
testthat::expect_equal(handle(), 42L)
106106

107107
testthat::expect_false(exists(fn_name))
108-
dlls <- keep(getLoadedDLLs(), ~ .x[["path"]] == dll_path)
108+
dlls <- keep(getLoadedDLLs(), \(.x) .x[["path"]] == dll_path)
109109
testthat::expect_length(dlls, 0L)
110110
})
111111

0 commit comments

Comments
 (0)