Skip to content

Commit 0e6eeab

Browse files
removed wrappers for base functions
1 parent b080ff1 commit 0e6eeab

File tree

13 files changed

+12
-383
lines changed

13 files changed

+12
-383
lines changed

NAMESPACE

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ export(list_pins)
5252
export(make_interval)
5353
export(mount_board)
5454
export(na_if_common)
55-
export(na_iqr)
56-
export(na_mad)
57-
export(na_max)
58-
export(na_mean)
59-
export(na_med)
60-
export(na_min)
61-
export(na_range)
62-
export(na_sd)
63-
export(na_sum)
64-
export(na_var)
6555
export(named_group_split)
6656
export(new_value)
6757
export(null_if_empty)
@@ -89,3 +79,5 @@ export(upgrade_personal_pkgs)
8979
export(years_df)
9080
export(years_floor)
9181
export(years_vec)
82+
importFrom(stats,IQR)
83+
importFrom(stats,median)

R/describe.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#'
1414
#' @autoglobal
1515
#'
16+
#' @importFrom stats median IQR
17+
#'
1618
#' @export
1719
describe <- function(df, ...) {
1820

@@ -28,14 +30,14 @@ describe <- function(df, ...) {
2830
) |>
2931
dplyr::mutate(n = 1 - is.na(value)) |>
3032
dplyr::reframe(
31-
n = as.integer(na_sum(n)),
32-
mean = na_mean(value),
33-
sd = na_sd(value),
34-
iqr = na_iqr(value),
35-
med = na_med(value),
36-
mad = na_mad(value),
33+
n = as.integer(sum(n, na.rm = TRUE)),
34+
mean = mean(value, na.rm = TRUE),
35+
sd = sd(value, na.rm = TRUE),
36+
iqr = IQR(value, na.rm = TRUE),
37+
med = median(value, na.rm = TRUE),
38+
mad = mad(value, na.rm = TRUE),
3739
range = glue_chr(
38-
"[{roundup(na_min(value))} - {roundup(na_max(value))}]"
40+
"[{roundup(min(value, na.rm = TRUE))} - {roundup(max(value, na.rm = TRUE))}]"
3941
),
4042
histogram = histo(value),
4143
.by = variable
@@ -113,7 +115,7 @@ histo <- function(x, width = 10) {
113115
bins <- graphics::hist(x, breaks = width, plot = FALSE)
114116

115117
factor <- cut(
116-
bins$counts / na_max(bins$counts),
118+
bins$counts / max(bins$counts, na.rm = TRUE),
117119
breaks = seq(0, 1, length = length(sparks) + 1),
118120
labels = sparks,
119121
include.lowest = TRUE

R/wrappers.R

Lines changed: 0 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -46,175 +46,6 @@ roundup <- function(x, digits = 2) {
4646
)
4747
}
4848

49-
#' `mean()` with `NA` removal
50-
#'
51-
#' @param x `<numeric>` vector
52-
#'
53-
#' @examples
54-
#' na_mean(c(1, 2, NA))
55-
#'
56-
#' @autoglobal
57-
#'
58-
#' @keywords internal
59-
#'
60-
#' @export
61-
na_mean <- function(x) {
62-
base::mean(x, na.rm = TRUE)
63-
}
64-
65-
#' `sum()` with `NA` removal
66-
#'
67-
#' @param x `<numeric>` vector
68-
#'
69-
#' @examples
70-
#' na_sum(c(1, 2, NA))
71-
#'
72-
#' @autoglobal
73-
#'
74-
#' @keywords internal
75-
#'
76-
#' @export
77-
na_sum <- function(x) {
78-
base::sum(x, na.rm = TRUE)
79-
}
80-
81-
#' `sd()` with `NA` removal
82-
#'
83-
#' @param x `<numeric>` vector
84-
#'
85-
#' @examples
86-
#' na_sd(c(1, 2, NA))
87-
#'
88-
#' @autoglobal
89-
#'
90-
#' @keywords internal
91-
#'
92-
#' @export
93-
na_sd <- function(x) {
94-
stats::sd(x, na.rm = TRUE)
95-
}
96-
97-
#' `median()` with `NA` removal
98-
#'
99-
#' @param x `<numeric>` vector
100-
#'
101-
#' @examples
102-
#' na_med(c(1, 2, NA))
103-
#'
104-
#' @autoglobal
105-
#'
106-
#' @keywords internal
107-
#'
108-
#' @export
109-
na_med <- function(x) {
110-
stats::median(x, na.rm = TRUE)
111-
}
112-
113-
#' `var()` with `NA` removal
114-
#'
115-
#' @param x `<numeric>` vector
116-
#'
117-
#' @examples
118-
#' na_var(c(1, 2, NA))
119-
#'
120-
#' @autoglobal
121-
#'
122-
#' @keywords internal
123-
#'
124-
#' @export
125-
na_var <- function(x) {
126-
stats::var(x, na.rm = TRUE)
127-
}
128-
129-
#' `mad()` with `NA` removal
130-
#'
131-
#' Compute the median absolute deviation, i.e., the (lo-/hi-) median of the
132-
#' absolute deviations from the median, and (by default) adjust by a factor for
133-
#' asymptotically normal consistency.
134-
#'
135-
#' @param x `<numeric>` vector
136-
#'
137-
#' @param ... additional arguments to pass to `stats::mad()`
138-
#'
139-
#' @examples
140-
#' na_mad(c(1, 2, NA))
141-
#'
142-
#' @autoglobal
143-
#'
144-
#' @keywords internal
145-
#'
146-
#' @export
147-
na_mad <- function(x, ...) {
148-
stats::mad(x, na.rm = TRUE, ...)
149-
}
150-
151-
#' `IQR()` with `NA` removal
152-
#'
153-
#' @param x `<numeric>` vector
154-
#'
155-
#' @param ... additional arguments to pass to `stats::IQR()`
156-
#'
157-
#' @examples
158-
#' na_iqr(c(1, 2, NA))
159-
#'
160-
#' @autoglobal
161-
#'
162-
#' @keywords internal
163-
#'
164-
#' @export
165-
na_iqr <- function(x, ...) {
166-
stats::IQR(x, na.rm = TRUE, ...)
167-
}
168-
169-
#' `range()` with `NA` removal
170-
#'
171-
#' @param ... `<numeric>` vector
172-
#'
173-
#' @examples
174-
#' na_range(c(1, 2, NA))
175-
#'
176-
#' @autoglobal
177-
#'
178-
#' @keywords internal
179-
#'
180-
#' @export
181-
na_range <- function(...) {
182-
base::range(..., na.rm = TRUE)
183-
}
184-
185-
#' `min()` with `NA` removal
186-
#'
187-
#' @param ... `<numeric>` vector
188-
#'
189-
#' @examples
190-
#' na_min(c(1, 2, NA))
191-
#'
192-
#' @autoglobal
193-
#'
194-
#' @keywords internal
195-
#'
196-
#' @export
197-
na_min <- function(...) {
198-
base::min(..., na.rm = TRUE)
199-
}
200-
201-
#' `max()` with `NA` removal
202-
#'
203-
#' @param ... `<numeric>` vector
204-
#'
205-
#' @examples
206-
#' na_max(c(1, 2, NA))
207-
#'
208-
#' @autoglobal
209-
#'
210-
#' @keywords internal
211-
#'
212-
#' @export
213-
na_max <- function(...) {
214-
base::max(..., na.rm = TRUE)
215-
}
216-
217-
21849
#' Wrapper for `as.character(glue::glue(x))`
21950
#'
22051
#' @param ... dots to pass to glue function

man/na_iqr.Rd

Lines changed: 0 additions & 21 deletions
This file was deleted.

man/na_mad.Rd

Lines changed: 0 additions & 23 deletions
This file was deleted.

man/na_max.Rd

Lines changed: 0 additions & 19 deletions
This file was deleted.

man/na_mean.Rd

Lines changed: 0 additions & 19 deletions
This file was deleted.

man/na_med.Rd

Lines changed: 0 additions & 19 deletions
This file was deleted.

man/na_min.Rd

Lines changed: 0 additions & 19 deletions
This file was deleted.

man/na_range.Rd

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)