Skip to content

Commit 47f9f1c

Browse files
committed
add checks
1 parent 6ff019e commit 47f9f1c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

R/check_group_variation.R

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#'
66
#' @param x A data frame.
77
#' @param select Character vector (or formula) with names of variables to select
8-
#' that should be checked.
8+
#' that should be checked. If `NULL`, selects all variables (except those in
9+
#' `by`).
910
#' @param by Character vector (or formula) with the name of the variable that
1011
#' indicates the group- or cluster-ID. For cross-classified or nested designs,
1112
#' `by` can also identify two or more variables as group- or cluster-IDs. If
@@ -63,6 +64,19 @@ check_group_variation <- function(x, select = NULL, by = NULL, nested = FALSE, t
6364
}
6465
my_data <- x
6566

67+
# sanity check
68+
if (is.null(by)) {
69+
insight::format_error("Please provide the group variable using `by`.")
70+
}
71+
if (!all(by %in% colnames(x))) {
72+
insight::format_error("The variable(s) speciefied in `by` were not found in the data.")
73+
}
74+
75+
# select all, if not given
76+
if (is.null(select)) {
77+
select <- setdiff(colnames(x), by)
78+
}
79+
6680
# for nested designs?
6781
if (nested) {
6882
# separate level-indicators with "/", as supported by datawizard

man/check_group_variation.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)