Skip to content

Commit

Permalink
* updated standalone-helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Dec 15, 2024
1 parent fc17319 commit 69def8d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 49 deletions.
24 changes: 12 additions & 12 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,39 @@ BugReports: https://github.com/andrewallenbruce/fuimus/issues
Depends:
R (>= 4.1.0)
Imports:
cheapr,
collapse,
kit,
cheapr (>= 0.9.92),
collapse (>= 2.0.18),
kit (>= 0.0.19),
rlang,
stringfish,
stringr,
vctrs
stringfish (>= 0.16.0),
vctrs (>= 0.6.5)
Suggests:
cli,
purrr,
clock,
dplyr,
glue,
janitor,
strex,
fipio,
fixtuRes,
fontawesome,
forcats,
fs,
fs (>= 1.6.5),
ggplot2,
glue,
graphics,
gt,
janitor,
lubridate,
pak,
pillar,
pins,
pins (>= 1.4.0),
prettycode,
purrr,
roxyglobals,
scales,
sf,
stats,
strex,
stringi,
stringr,
styler,
testthat (>= 3.0.0),
tidyr,
Expand Down
34 changes: 31 additions & 3 deletions R/standalone-helpers.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# ---
# repo: andrewallenbruce/fuimus
# file: standalone-helpers.R
# last-updated: 2024-12-14
# last-updated: 2024-12-15
# license: https://unlicense.org
# imports: [cheapr (>= 0.9.92), collapse (>= 2.0.18), kit (>= 0.0.19), stringfish (>= 0.16.0), stringi (>= 1.8.4), vctrs (>= 0.6.5)]
# ---
#
# ## Changelog
#
# 2024-12-15:
#
# * Added gelm()
#
# 2024-12-14:
#
# * Added remove_all_na() and na_if()
# * Fixed errors in roxygen documentation
#
# 2024-12-13:
#
Expand Down Expand Up @@ -91,7 +96,8 @@ search_in <- \(x, column, what) {
#' @param y values to convert to `NA`. Type must match that of `x`.
#'
#' @returns `x` with values in `y` converted to `NA`
#' noRd
#'
#' @noRd
na_if <- \(x, y) {

vctrs::vec_slice(
Expand Down Expand Up @@ -142,8 +148,9 @@ not_na <- \(x) { !na(x) }

#' Remove columns and rows with all NAs
#'
#' @param x `<data.frame>`
#' @param x vector or `<data.frame>`
#'
#' @noRd
remove_all_na <- \(x) { cheapr::na_rm(x[, !cheapr::col_all_na(x)]) }

# collapse -----------------------------------------------------------------
Expand All @@ -157,6 +164,27 @@ remove_all_na <- \(x) { cheapr::na_rm(x[, !cheapr::col_all_na(x)]) }
#' @noRd
getelem <- \(l, e) { collapse::get_elem(l = l, elem = e, regex = TRUE) }

#' `getelem` with more flexibility
#'
#' @param l named `<list>`
#'
#' @param e `<chr>` element name; can be a regex pattern if `m` is `"re"`
#'
#' @param m `<chr>` mode; default is `"re"` (regex) or `"df"` (data frame)
#'
#' @param ... additional arguments to pass to `collapse::get_elem()`
#'
#' @noRd
gelm <- \(l, e, m = "re", ...) {

collapse::get_elem(
l = l,
elem = e,
regex = ifelse(m == "re", TRUE, FALSE),
DF.as.list = ifelse(m == "df", TRUE, FALSE), ...)

}

#' Lengths of Vector
#'
#' @param x vector
Expand Down
20 changes: 0 additions & 20 deletions man/na_if.Rd

This file was deleted.

14 changes: 0 additions & 14 deletions man/remove_all_na.Rd

This file was deleted.

0 comments on commit 69def8d

Please sign in to comment.