Skip to content

Commit

Permalink
styler, lints
Browse files Browse the repository at this point in the history
  • Loading branch information
rempsyc committed Dec 19, 2024
1 parent e8d393d commit f26f247
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
20 changes: 11 additions & 9 deletions R/describe_missing.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
#' df,
#' select = -1,
#' names_sep = "_",
#' names_to = c("dimension", "item"))
#' names_to = c("dimension", "item")
#' )
#'
#' describe_missing(
#' df_long,
#' select = -c(1, 3),
#' by = "dimension")
#' by = "dimension"
#' )
#'
describe_missing <- function(data,
select = NULL,
Expand All @@ -65,9 +67,14 @@ describe_missing <- function(data,
...
)
}
if (!is.null(by)) {
if (is.null(by)) {
na_list <- lapply(names(data), function(x) {
data_subset <- data[, x, drop = FALSE]
.describe_missing(data_subset)
})
} else {
if (!by %in% names(data)) {
stop("The 'by' column does not exist in the data.")
stop("The 'by' column does not exist in the data.", call. = FALSE)
}
grouped_data <- split(data, data[[by]])
na_list <- lapply(names(grouped_data), function(group_name) {
Expand All @@ -82,11 +89,6 @@ describe_missing <- function(data,
group_na_df$variable <- group_name
group_na_df
})
} else {
na_list <- lapply(names(data), function(x) {
data_subset <- data[, x, drop = FALSE]
.describe_missing(data_subset)
})
}
na_df <- do.call(rbind, na_list)
if (isTRUE(sort)) {
Expand Down
6 changes: 4 additions & 2 deletions man/describe_missing.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/testthat/test-describe_missing.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ test_that("describe_missing", {
ID = c("idz", NA),
openness_1 = fun(), openness_2 = fun(), openness_3 = fun(),
extroversion_1 = fun(), extroversion_2 = fun(), extroversion_3 = fun(),
agreeableness_1 = fun(), agreeableness_2 = fun(), agreeableness_3 = fun()
agreeableness_1 = fun(), agreeableness_2 = fun(), agreeableness_3 = fun(),
stringsAsFactors = FALSE
)

# Pivot and group using datawizard
Expand Down

0 comments on commit f26f247

Please sign in to comment.