Skip to content

Commit

Permalink
Add omit argument to check_data
Browse files Browse the repository at this point in the history
Close #49
  • Loading branch information
llrs committed Apr 30, 2024
1 parent 10122cc commit 0ba2d5f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

* Check that index used in `inspect` has a valid length, positions and
replications matching the data provided.

* `check_data()` gains a new omit argument (#49).
If you relied on positional arguments it will break your scripts.

* Omitting non existing columns now creates a warning.

# experDesign 0.3.0

Expand Down
5 changes: 3 additions & 2 deletions R/evaluate_category.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ evaluate_independence <- function(i, pheno) {
#' In order to run a successful experiment a good design is needed even before measuring the data.
#' This functions checks several heuristics for a good experiment and warns if they are not found.
#' @param pheno Data.frame with the variables of each sample, one row one sample.
#' @param omit Character vector with the names of the columns to omit.
#' @param na.omit Check the effects of missing values too.
#' @return A logical value indicating if everything is alright (TRUE) or not (FALSE).
#' @export
Expand All @@ -91,9 +92,9 @@ evaluate_independence <- function(i, pheno) {
#' data(survey, package = "MASS")
#' check_data(survey)
#' }
check_data <- function(pheno, na.omit = FALSE) {
check_data <- function(pheno, omit = NULL, na.omit = FALSE) {
stopifnot(is.data.frame(pheno) || is.matrix(pheno), is_logical(na.omit))
.check_data(pheno = pheno, na.omit = na.omit, verbose = TRUE)
.check_data(pheno = omit(pheno, omit), na.omit = na.omit, verbose = TRUE)
}
#' @importFrom utils combn
.check_data <- function(pheno, na.omit = FALSE, verbose = FALSE) {
Expand Down
5 changes: 5 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ is_cat <- function(x, ...) {
omit <- function(pheno, omit){
# Omit columns
if (!is.null(omit)) {
col_diff <- setdiff(omit, colnames(pheno))
if (length(col_diff) != 0L) {
warning("Columns to omit were not present: ",
paste(col_diff, collapse = ", "), ".")
}
pheno[, !colnames(pheno) %in% omit, drop = FALSE]
} else {
pheno
Expand Down
4 changes: 3 additions & 1 deletion man/check_data.Rd

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

0 comments on commit 0ba2d5f

Please sign in to comment.