Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
hanneoberman committed Jul 21, 2023
1 parent f44716c commit 1e63a50
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
))
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
LINTR_ERROR_ON_LINT: false
16 changes: 9 additions & 7 deletions R/plot_corr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions R/plot_pattern.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]))
}
}
Expand Down
25 changes: 11 additions & 14 deletions R/plot_pred.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions R/plot_trace.R
Original file line number Diff line number Diff line change
Expand Up @@ -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."))
}
}

Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions tests/testthat/test-ggmice.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
})

Expand All @@ -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", {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-plot_corr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)", {
Expand Down

0 comments on commit 1e63a50

Please sign in to comment.