From 724f882bbdc4ea4002e081e8fde89b8f36401e62 Mon Sep 17 00:00:00 2001 From: Fran Barton Date: Tue, 26 Mar 2024 02:28:33 +0000 Subject: [PATCH] Remove magrittr pipes (issue #11) and fix more CMD check issues --- DESCRIPTION | 1 - NAMESPACE | 1 - R/get_latlon.R | 10 +++++----- R/myrmidon-package.R | 3 +-- R/order_along.R | 16 ++++++++-------- R/prompts.R | 6 +++--- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0e2fcae..5d4a03f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,7 +24,6 @@ Imports: janitor, jsonlite, lubridate, - magrittr, pillar, prompt, ps, diff --git a/NAMESPACE b/NAMESPACE index d2429eb..e1b4c2e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -47,7 +47,6 @@ importFrom(dplyr,desc) importFrom(dplyr,if_any) importFrom(dplyr,if_else) importFrom(dplyr,join_by) -importFrom(magrittr,"%>%") importFrom(rlang,`:=`) importFrom(tidyselect,all_of) importFrom(tidyselect,any_of) diff --git a/R/get_latlon.R b/R/get_latlon.R index 2530925..0056481 100644 --- a/R/get_latlon.R +++ b/R/get_latlon.R @@ -24,10 +24,10 @@ get_latlon <- function(postcode) { endpoint <- "https://www.doogal.co.uk/GetPostcode.ashx?postcode=" - paste0(endpoint, postcode) %>% - utils::URLencode() %>% - rvest::read_html() %>% - rvest::html_node("p") %>% - rvest::html_text() %>% + paste0(endpoint, postcode) |> + utils::URLencode() |> + rvest::read_html() |> + rvest::html_node("p") |> + rvest::html_text() |> readr::read_delim("\t", col_names = data_names) } diff --git a/R/myrmidon-package.R b/R/myrmidon-package.R index 5e4d729..f3d5bc1 100644 --- a/R/myrmidon-package.R +++ b/R/myrmidon-package.R @@ -15,8 +15,7 @@ # roxygen namespace tags. Modify with care! #' @importFrom assertthat assert_that #' @importFrom dplyr across c_across desc if_any if_else join_by -#' @importFrom magrittr %>% -#' @importFrom rlang `:=` +#' @importFrom rlang `:=` .data #' @importFrom tidyselect all_of any_of contains ends_with everything #' @importFrom tidyselect last_col matches num_range starts_with #' @importFrom usethis ui_info ui_stop ui_oops ui_nope ui_code diff --git a/R/order_along.R b/R/order_along.R index 10f59f3..8b8c222 100644 --- a/R/order_along.R +++ b/R/order_along.R @@ -45,30 +45,30 @@ order_along.sf <- function(sf, order_along, sort_by, desc = FALSE) { # gotta split🍌, and work without geometry on one fork🍴, otherwise # the left_join later on will fail (can't `dplyr::*-join` two `sf` tbls) - sf2 <- sf %>% + sf2 <- sf |> sf::st_drop_geometry() cols <- colnames(sf2) if (desc) { - sf2 <- sf2 %>% + sf2 <- sf2 |> dplyr::arrange(desc({{ sort_by }})) } else { - sf2 <- sf2 %>% + sf2 <- sf2 |> dplyr::arrange({{ sort_by }}) } - sf2 %>% + sf2 |> # create list of `order_along` variable, in order of appearance 😊 - dplyr::select({{ order_along }}) %>% - dplyr::distinct() %>% + dplyr::select({{ order_along }}) |> + dplyr::distinct() |> # now ordered along `order_along` and sorted by `sort_by` πŸ˜„ # not _necessary_ to stipulate `by`, but it avoids the join message 🀫. - dplyr::left_join(sf2, by = rlang::as_name(along)) %>% + dplyr::left_join(sf2, by = rlang::as_name(along)) |> # quick way to restore the original column order πŸ˜™ - dplyr::select(dplyr::all_of(cols)) %>% + dplyr::select(dplyr::all_of(cols)) |> # `right_join()` saves the day by retrieving and joining to the original # geometry without losing our carefully crafted sorting and ordering 😌 diff --git a/R/prompts.R b/R/prompts.R index 5ce44be..b193733 100644 --- a/R/prompts.R +++ b/R/prompts.R @@ -2,7 +2,7 @@ prompt_rstudio <- function() { rstd <- tryCatch(RStudio.Version()$release_name, error = \(e) NULL) if (!is.null(rstd)) { colour <- "myr_prompt_col3" |> - get0(.myr_prompt_env, ifnotfound = "darkslateblue") + get0(".myr_prompt_env", ifnotfound = "darkslateblue") crayon::style(rstd, colour) } else NULL } @@ -11,7 +11,7 @@ prompt_rstudio <- function() { prompt_location <- function(unicode) { colour <- "myr_prompt_col1" |> - get0(.myr_prompt_env, ifnotfound = "whitesmoke") + get0(".myr_prompt_env", ifnotfound = "whitesmoke") location <- basename(getwd()) icon <- if (unicode) { if (file.exists(here::here("DESCRIPTION"))) "\U1F4E6\u2009" @@ -26,7 +26,7 @@ prompt_location <- function(unicode) { prompt_git_branch <- function(unicode) { if (prompt::is_git_dir()) { colour <- "myr_prompt_col2" |> - get0(.myr_prompt_env, ifnotfound = "orange") + get0(".myr_prompt_env", ifnotfound = "orange") if (unicode) { paste0(