Skip to content

Commit c66418c

Browse files
committed
%>% -> |>
1 parent c1c1bab commit c66418c

File tree

10 files changed

+823
-3994
lines changed

10 files changed

+823
-3994
lines changed

DESCRIPTION

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Version: 0.2.0.9000
44
Authors@R: c(
55
person("Max", "Kuhn", , "max@posit.co", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-2402-136X")),
7-
person(given = "Posit Software, PBC", role = c("cph", "fnd"))
7+
person("Posit Software, PBC", role = c("cph", "fnd"))
88
)
99
Description: Code snippets to fit models using the tidymodels framework
1010
can be easily created for a given data set.
@@ -13,7 +13,7 @@ URL: https://usemodels.tidymodels.org/,
1313
https://github.com/tidymodels/usemodels
1414
BugReports: https://github.com/tidymodels/usemodels/issues
1515
Depends:
16-
R (>= 3.4)
16+
R (>= 4.1)
1717
Imports:
1818
cli,
1919
clipr,
@@ -28,8 +28,7 @@ Suggests:
2828
modeldata,
2929
spelling,
3030
testthat
31-
Config/Needs/website:
32-
tidyverse/tidytemplate
31+
Config/Needs/website: tidyverse/tidytemplate
3332
Config/testthat/edition: 3
3433
Encoding: UTF-8
3534
Language: en-US

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ import(tune)
2222
importFrom(dplyr,one_of)
2323
importFrom(dplyr,pull)
2424
importFrom(dplyr,select)
25-
importFrom(recipes,"%>%")
2625
importFrom(recipes,all_predictors)
2726
importFrom(recipes,recipe)

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# usemodels (development version)
22

3+
* Transition from the magrittr pipe to the base R pipe.
4+
35
* Added `use_nnet()`, `use_rpart()`, `use_bag_tree_rpart()`, `use_mgcv()`, `use_dbarts()`, `use_mixOmics()`, `use_xrf()`.
46

57
* Fix `recipe()` call when `clipboard = TRUE`
68

7-
89
# usemodels 0.2.0
910

1011
* SVM (#14) and C5.0 (#9) models were added.

R/misc.R

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ y_lvl <- function(rec) {
2020
}
2121
var_roles <- summary(rec)
2222
y_cols <- var_roles$variable[var_roles$role == "outcome"]
23-
y_dat <- rec$template %>%
24-
dplyr::select(one_of(y_cols)) %>%
23+
y_dat <- rec$template |>
24+
dplyr::select(one_of(y_cols)) |>
2525
dplyr::pull(1)
2626
length(levels(y_dat))
2727
}
@@ -57,14 +57,14 @@ chr_assign <- function(name, value, cr = TRUE) {
5757
res
5858
}
5959
pipe_value <- function(base, value) {
60-
# Find last non-comment line, add a `%>%` to the end, then add another line
60+
# Find last non-comment line, add a `|>` to the end, then add another line
6161
value <- rlang::enexpr(value)
6262
value <- rlang::expr_text(value, width = expr_width)
6363
clean_base <- gsub("\\n", "", base)
6464
clean_base <- trimws(base, which = "left")
6565
not_comment <- seq_along(base)[!grepl("## ", clean_base)]
6666
n <- max(1, max(not_comment))
67-
base[n] <- paste(base[n], "%>%")
67+
base[n] <- paste(base[n], "|>")
6868
c(base, paste0("\n ", value))
6969
}
7070
add_comment <- function(base, value, add = TRUE, colors = TRUE) {
@@ -84,38 +84,38 @@ add_comment <- function(base, value, add = TRUE, colors = TRUE) {
8484
res
8585
}
8686
add_steps_dummy_vars <- function(base, hot = FALSE, add = FALSE, colors = TRUE) {
87-
base <- base %>%
87+
base <- base |>
8888
pipe_value(step_novel(all_nominal_predictors()))
8989
if (hot) {
90-
base <- base %>%
91-
add_comment(dummy_hot_msg, add, colors = colors) %>%
90+
base <- base |>
91+
add_comment(dummy_hot_msg, add, colors = colors) |>
9292
pipe_value(step_dummy(all_nominal_predictors(), one_hot = TRUE))
9393
} else {
94-
base <- base %>%
95-
add_comment(dummy_msg, add, colors = colors) %>%
94+
base <- base |>
95+
add_comment(dummy_msg, add, colors = colors) |>
9696
pipe_value(step_dummy(all_nominal_predictors()))
9797
}
9898
base
9999
}
100100
add_steps_normalization <- function(base) {
101-
base %>%
102-
pipe_value(step_zv(all_predictors())) %>%
101+
base |>
102+
pipe_value(step_zv(all_predictors())) |>
103103
pipe_value(step_normalize(all_numeric_predictors()))
104104
}
105105
factor_check <- function(base, rec, add, colors = TRUE) {
106106
var_roles <- summary(rec)
107107
nominal <- var_roles$variable[var_roles$type == "nominal"]
108108
is_str <-
109109
purrr::map_lgl(
110-
rec$template %>% dplyr::select(dplyr::one_of(nominal)),
110+
rec$template |> dplyr::select(dplyr::one_of(nominal)),
111111
rlang::is_character
112112
)
113113
if (any(is_str)) {
114114
selector <- rlang::expr(one_of(!!!nominal[is_str]))
115115
step_expr <- rlang::expr(step_string2factor(!!selector))
116116
base <-
117-
base %>%
118-
add_comment(string_to_factor_msg, add = add, colors = colors) %>%
117+
base |>
118+
add_comment(string_to_factor_msg, add = add, colors = colors) |>
119119
pipe_value(!!step_expr)
120120
}
121121
base
@@ -135,9 +135,9 @@ top_level_comment <- function(..., add = FALSE, colors = TRUE) {
135135
}
136136

137137
template_workflow <- function(prefix) {
138-
paste0(prefix, "_workflow") %>%
139-
assign_value(workflow()) %>%
140-
pipe_value(add_recipe(!!rlang::sym(paste0(prefix, "_recipe")))) %>%
138+
paste0(prefix, "_workflow") |>
139+
assign_value(workflow()) |>
140+
pipe_value(add_recipe(!!rlang::sym(paste0(prefix, "_recipe")))) |>
141141
pipe_value(add_model(!!rlang::sym(paste0(prefix, "_spec"))))
142142
}
143143

0 commit comments

Comments
 (0)