diff --git a/R/import-standalone-check_pkg_installed.R b/R/import-standalone-check_pkg_installed.R index ec564e170..5624692e3 100644 --- a/R/import-standalone-check_pkg_installed.R +++ b/R/import-standalone-check_pkg_installed.R @@ -1,11 +1,12 @@ # Standalone file: do not edit by hand -# Source: +# Source: https://github.com/insightsengineering/standalone/blob/HEAD/R/standalone-check_pkg_installed.R +# Generated by: usethis::use_standalone("insightsengineering/standalone", "check_pkg_installed") # ---------------------------------------------------------------------- # # --- # repo: insightsengineering/standalone # file: standalone-check_pkg_installed.R -# last-updated: 2024-04-19 +# last-updated: 2025-02-03 # license: https://unlicense.org # dependencies: standalone-cli_call_env.R # imports: [rlang, dplyr, tidyr] @@ -14,6 +15,9 @@ # This file provides functions to check package installation. # # ## Changelog +# 2025-02-03 +# - `get_pkg_dependencies()` was updated to use base r equivalents for `str_extract()` and `str_remove_all()`. + # nocov start # styler: off @@ -164,8 +168,10 @@ get_pkg_dependencies <- function(pkg = utils::packageName(), lib.loc = NULL) { sep = " ", extra = "merge", fill = "right" ) |> dplyr::mutate( - compare = .data$version |> str_extract(pattern = "[>=<]+"), - version = .data$version |> str_remove_all(pattern = "[\\(\\) >=<]") + compare = as.character(ifelse(regexpr("[>=<]+", .data$version) > 0, + regmatches(.data$version, regexpr("[>=<]+", .data$version)), + NA)), + version = gsub(pattern = "[\\(\\) >=<]", replacement = "", x = .data$version) ) } diff --git a/R/import-standalone-forcats.R b/R/import-standalone-forcats.R index cf2fa4b8f..de1275fce 100644 --- a/R/import-standalone-forcats.R +++ b/R/import-standalone-forcats.R @@ -1,5 +1,6 @@ # Standalone file: do not edit by hand -# Source: +# Source: https://github.com/insightsengineering/standalone/blob/HEAD/R/standalone-forcats.R +# Generated by: usethis::use_standalone("insightsengineering/standalone", "forcats") # ---------------------------------------------------------------------- # # --- @@ -15,6 +16,8 @@ # of programming. # # ## Changelog +# 2025-02-24 +# - `add fct_relevel()` function. # # nocov start # styler: off @@ -69,6 +72,21 @@ fct_na_value_to_level <- function(f, level = NA) { } +fct_relevel <- function(f, ..., after = 0L) { + old_levels <- levels(f) + # Handle re-leveling function or specified levels + first_levels <- if (rlang::dots_n(...) == 1L && (is.function(..1) || rlang::is_formula(..1))) { + fun <- rlang::as_function(..1) + fun(old_levels) + } else { + rlang::chr(...) + } + + # Reorder levels + new_levels <- append(setdiff(old_levels, first_levels), first_levels, after = after) + new_factor <- factor(f, levels = new_levels) + return(new_factor) +} # nocov end # styler: on