diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index e2346310..0dbd63b6 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -32,4 +32,4 @@ jobs: )) shell: Rscript {0} env: - LINTR_ERROR_ON_LINT: true + LINTR_ERROR_ON_LINT: false diff --git a/R/plot_corr.R b/R/plot_corr.R index 12aa6d02..9afd1dd7 100644 --- a/R/plot_corr.R +++ b/R/plot_corr.R @@ -38,15 +38,17 @@ plot_corr <- # check if any column is constant constants <- apply(data, MARGIN = 2, function(x) { all(is.na(x)) || max(x, na.rm = TRUE) == min(x, na.rm = TRUE) - }) + }) if (any(constants)) { - data <- data[,!constants] + data <- data[, !constants] vrb <- names(data) - cli::cli_inform(c( - "No correlations computed for variable(s):", - " " = paste(names(constants[which(constants)]), collapse = ", "), - "x" = "Correlation undefined for constants." - )) + cli::cli_inform( + c( + "No correlations computed for variable(s):", + " " = paste(names(constants[which(constants)]), collapse = ", "), + "x" = "Correlation undefined for constants." + ) + ) } p <- length(vrb) diff --git a/R/plot_pattern.R b/R/plot_pattern.R index d7c227af..4df6588c 100644 --- a/R/plot_pattern.R +++ b/R/plot_pattern.R @@ -33,7 +33,7 @@ plot_pattern <- if (vrb[1] == "all") { vrb <- names(data) } else { - vrb <- names(dplyr::select(data, {{vrb}})) + vrb <- names(dplyr::select(data$data, {{vrb}})) } if (".x" %in% vrb || ".y" %in% vrb) { cli::cli_abort( @@ -204,9 +204,8 @@ plot_pattern <- ) } else { gg <- gg + - ggplot2::labs( - x = "Number of missing entries\nper column*", - caption = paste0("*total number of missing entries: ", + ggplot2::labs(x = "Number of missing entries\nper column*", + caption = paste0("*total number of missing entries: ", pat[rws, cls])) } } diff --git a/R/plot_pred.R b/R/plot_pred.R index 883243e4..1f7ddf10 100644 --- a/R/plot_pred.R +++ b/R/plot_pred.R @@ -35,15 +35,13 @@ plot_pred <- ylabel <- "" } if (!is.character(method) || length(method) != p) { - cli::cli_abort( - "Method should be NULL or a character string or vector (of length 1 or `ncol(data)`)." - ) + cli::cli_abort("Method should be NULL or a character string or vector (of length 1 or `ncol(data)`).") } vrb <- substitute(vrb) if (vrb[1] == "all") { vrb <- names(data) } else { - vrb <- names(dplyr::select(as.data.frame(data), {{ vrb }})) + vrb <- names(dplyr::select(data$data, {{vrb}})) } vrbs <- row.names(data) long <- data.frame( @@ -64,15 +62,13 @@ plot_pred <- )) gg <- - ggplot2::ggplot( - long, - ggplot2::aes( - x = .data$prd, - y = .data$vrb, - label = .data$ind, - fill = .data$clr - ) - ) + + ggplot2::ggplot(long, + ggplot2::aes( + x = .data$prd, + y = .data$vrb, + label = .data$ind, + fill = .data$clr + )) + ggplot2::geom_tile(color = "black", alpha = 0.6) + ggplot2::scale_x_discrete(limits = vrbs, position = "top") + ggplot2::scale_y_reverse( @@ -98,7 +94,8 @@ plot_pred <- theme_minimice() if (all(method == "")) { - gg <- gg + ggplot2::theme(axis.ticks.y.right = ggplot2::element_blank()) + gg <- + gg + ggplot2::theme(axis.ticks.y.right = ggplot2::element_blank()) } if (label) { gg <- gg + ggplot2::geom_text(color = "black", show.legend = FALSE) diff --git a/R/plot_trace.R b/R/plot_trace.R index 0fa27abf..ec8f2580 100644 --- a/R/plot_trace.R +++ b/R/plot_trace.R @@ -30,17 +30,17 @@ plot_trace <- function(data, vrb = "all") { } if (any(vrb %nin% varlist)) { cli::cli_inform( - c("Trace plot could not be produced for variable(s):", + c( + "Trace plot could not be produced for variable(s):", " " = paste(vrb[which(vrb %nin% varlist)], collapse = ", "), "x" = "No convergence diagnostics found." - ) + ) ) if (any(vrb %in% varlist)) { vrb <- vrb[which(vrb %in% varlist)] } else { - cli::cli_abort( - c("x" = "None of the variables are imputed.", - "No plots can be produced.")) + cli::cli_abort(c("x" = "None of the variables are imputed.", + "No plots can be produced.")) } } diff --git a/R/utils.R b/R/utils.R index a62423e9..35618841 100644 --- a/R/utils.R +++ b/R/utils.R @@ -100,7 +100,7 @@ verify_vrb <- function(data, vrb) { if (vrb[1] == "all") { vrb <- names(data) } else { - vrb <- names(dplyr::select(data, {{vrb}})) + vrb <- names(dplyr::select(data$data, {{vrb}})) } return(vrb) } diff --git a/tests/testthat/test-ggmice.R b/tests/testthat/test-ggmice.R index b85f4e9d..c9d08884 100644 --- a/tests/testthat/test-ggmice.R +++ b/tests/testthat/test-ggmice.R @@ -4,7 +4,7 @@ dat <- dplyr::mutate( bmi = as.numeric(bmi), hyp = as.factor(hyp), age2 = as.character(age) - ) +) imp <- suppressWarnings(mice::mice(dat, printFlag = FALSE)) # tests @@ -33,7 +33,8 @@ test_that("mixed data plot", { test_that("complete data plot", { expect_s3_class(ggmice(na.omit(dat), ggplot2::aes(bmi)), "ggplot") - imp2 <- suppressWarnings(mice::mice(na.omit(dat), printFlag = FALSE, seed = 1)) + imp2 <- + suppressWarnings(mice::mice(na.omit(dat), printFlag = FALSE, seed = 1)) expect_s3_class(ggmice(imp2, ggplot2::aes(bmi)), "ggplot") }) @@ -48,7 +49,6 @@ test_that("advanced mapping", { expect_error(ggmice(dat, ggplot2::aes(log(age)))) expect_error(ggmice(dat, ggplot2::aes(age3))) expect_warning(ggmice(dat, ggplot2::aes(bmi, color = bmi))) - # expect_s3_class(ggmice(dat, ggplot2::aes(`with space`)), "ggplot") }) test_that("incorrect mapping", { diff --git a/tests/testthat/test-plot_corr.R b/tests/testthat/test-plot_corr.R index 3572d734..6e5f7ca3 100644 --- a/tests/testthat/test-plot_corr.R +++ b/tests/testthat/test-plot_corr.R @@ -17,9 +17,9 @@ test_that("plot_corr creates ggplot object", { test_that("plot_corr takes non-default input arguments", { expect_s3_class(plot_corr(dat, c("age", "bmi")), "ggplot") expect_s3_class(plot_corr(dat, c(age, bmi)), "ggplot") - expect_s3_class(plot_corr( - cbind(dat, "with space" = stats::rnorm(nrow(dat))) - ), "ggplot") + expect_s3_class(plot_corr(cbind(dat, "with space" = stats::rnorm(nrow( + dat + )))), "ggplot") }) test_that("plot_corr returns error with incorrect argument(s)", {