Skip to content

Commit

Permalink
code style edits (see review)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanneoberman committed Jul 19, 2024
1 parent 3807f0a commit 5b66d19
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ export(stripplot)
export(xyplot)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
importFrom(rlang,enexpr)
importFrom(utils,tail)
24 changes: 9 additions & 15 deletions R/plot_trace.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#' for(v in vars)
#' plot_trace(imp, !!v) |> print()
#'
#' @importFrom utils tail
#' @importFrom rlang enexpr
#' @export
plot_trace <- function(data, vrb = "all") {
verify_data(data, imp = TRUE)
Expand All @@ -49,17 +47,18 @@ plot_trace <- function(data, vrb = "all") {
sm <- sqrt(data$chainVar)

# select variable to plot from list of imputed variables
vrb <- enexpr(vrb)
if(is.call(vrb))
vrb <- as.character(vrb) |> tail(-1)
else if(is.symbol(vrb))
vrb <- rlang::enexpr(vrb)
if (is.call(vrb))
vrb <- as.character(vrb) |> utils::tail(-1)
if (is.symbol(vrb))
vrb <- as.character(vrb)

varlist <-
names(data$imp)[apply(!(is.nan(mn) | is.na(mn)), 1, all)]
if (length(vrb) == 1 && as.character(vrb) == "all") {
vrb <- varlist
} else if (any(vrb %nin% colnames(data$data))) {
}
if (any(vrb %nin% colnames(data$data))) {
cli::cli_abort(
c(
"x" = "The following variables are not present in 'data':",
Expand All @@ -81,8 +80,7 @@ plot_trace <- function(data, vrb = "all") {
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 All @@ -95,8 +93,7 @@ plot_trace <- function(data, vrb = "all") {
vrb = rep(vrb, each = m * it, times = 2),
val = c(matrix(aperm(mn[vrb, , , drop = FALSE], c(
2, 3, 1
)), nrow = m * it * p),
matrix(aperm(sm[vrb, , , drop = FALSE], c(
)), nrow = m * it * p), matrix(aperm(sm[vrb, , , drop = FALSE], c(
2, 3, 1
)), nrow = m * it * p))
))
Expand All @@ -121,14 +118,11 @@ plot_trace <- function(data, vrb = "all") {
list(do.call(paste, c(labels, list(sep = "\n"))))
}
) +
ggplot2::labs(x = "Iteration",
y = "Imputation parameter",
color = "Imputation number") +
ggplot2::labs(x = "Iteration", y = "Imputation parameter", color = "Imputation number") +
theme_mice() +
ggplot2::theme(
strip.background = ggplot2::element_blank(),
strip.placement = "outside",
strip.switch.pad.wrap = ggplot2::unit(0, "cm")
)
}

2 changes: 1 addition & 1 deletion tests/testthat/test-plot_trace.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# create test objects
dat <- mice::nhanes
imp <- mice::mice(dat, printFlag = FALSE)
v <- c("bmi", "hyp")
v <- c("bmi", "hyp")

# tests
test_that("plot_trace creates ggplot object", {
Expand Down

0 comments on commit 5b66d19

Please sign in to comment.