Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve verify_data function #138

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 11 additions & 43 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,50 +39,18 @@
df = FALSE,
imp = FALSE,
pred = FALSE) {
if (df && !imp) {
if (!(is.data.frame(data) || is.matrix(data))) {
cli::cli_abort(
c(
"The 'data' argument requires an object of class 'data.frame' or 'matrix'.",
"i" = "Input object is of class {class(data)}."
),
call. = FALSE
)
}
}
if (df && imp) {
if (!(is.data.frame(data) ||
is.matrix(data) || mice::is.mids(data))) {
cli::cli_abort(
c(
"The 'data' argument requires an object of class 'data.frame', 'matrix', or 'mids'.",
"i" = "Input object is of class {class(data)}."
),
call. = FALSE
)
}
df <- data.frame(val = unlist(as.list(environment())[-1]),
type = c("data.frame", "mids", "matrix"))
types <- df[df$val==T,]$type

Check warning on line 44 in R/utils.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utils.R,line=44,col=21,[infix_spaces_linter] Put spaces around all infix operators.

Check warning on line 44 in R/utils.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utils.R,line=44,col=24,[T_and_F_symbol_linter] Use TRUE instead of the symbol T.

Check warning on line 44 in R/utils.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utils.R,line=44,col=25,[commas_linter] Commas should always have a space after.
types_format <- purrr::map(types, function(x) paste0("`", x, "`")) %>% unlist()

Check warning on line 45 in R/utils.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utils.R,line=45,col=3,[object_usage_linter] local variable 'types_format' assigned but may not be used
if(!inherits(data, types)){

Check warning on line 46 in R/utils.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utils.R,line=46,col=5,[spaces_left_parentheses_linter] Place a space before left parenthesis, except in a function call.
cli::cli_abort(c(
"!" = "The {.arg data} argument requires an object of class {stringr::str_flatten_comma({types_format}, \", or \")}.",
"i" = "Input object is of class {class(data)}"
),
call. = FALSE)
}
if (imp && !df) {
if (!mice::is.mids(data)) {
cli::cli_abort(
c(
"The 'data' argument requires an object of class 'mids'.",
"i" = "Input object is of class {class(data)}."
),
call. = FALSE
)
}
}
if (pred) {
if (!is.matrix(data)) {
cli::cli_abort(
c(
"The 'data' argument requires an object of class 'matrix'.",
"i" = "Input object is of class {class(data)}."
),
call. = FALSE
)
}
if (is.matrix(data)) {
if (dim(data)[1] != dim(data)[2]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is actually a bug in ggmice, because mice does accept non-square predictor matrices

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So line 54 is not correct

cli::cli_abort(
c(
Expand Down
Loading