From c742bdb3791af0110d3d0922930dceacd2d342ca Mon Sep 17 00:00:00 2001 From: Noah Greifer Date: Sun, 7 Jul 2019 02:07:41 -0700 Subject: [PATCH] Renamed word.list to word_list --- R/bal.plot.R | 20 ++++++++++---------- R/get.w.R | 24 ++++++++++++------------ R/love.plot.R | 4 ++-- R/print.bal.tab.R | 8 ++++---- R/utilities.R | 18 +++++++++--------- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/R/bal.plot.R b/R/bal.plot.R index 24251f0d..f589839e 100644 --- a/R/bal.plot.R +++ b/R/bal.plot.R @@ -89,7 +89,7 @@ bal.plot <- function(obj, var.name, ..., which, which.sub = NULL, cluster = NULL } if (is.numeric(which.sub) && any(which.sub %in% levels(X$subclass))) { if (any(!which.sub %in% levels(X$subclass))) { - w.l <- word.list(which.sub[!which.sub %in% levels(X$subclass)]) + w.l <- word_list(which.sub[!which.sub %in% levels(X$subclass)]) warning(paste(w.l, ifelse(attr(w.l, "plural"), "do", "does"), "not correspond to any subclass in the object and will be ignored."), call. = FALSE) which.sub <- which.sub[which.sub %in% levels(X$subclass)] } @@ -160,7 +160,7 @@ bal.plot <- function(obj, var.name, ..., which, which.sub = NULL, cluster = NULL in.imp <- !is.na(X$imp) & sapply(X$imp, function(x) !is.na(match(x, levels(X$imp)[which.imp]))) } else { - stop(paste0("The following inputs to which.imp do not correspond to given imputations:\n\t", word.list(which.imp[!which.imp %in% seq_len(nlevels(X$imp))])), call. = FALSE) + stop(paste0("The following inputs to which.imp do not correspond to given imputations:\n\t", word_list(which.imp[!which.imp %in% seq_len(nlevels(X$imp))])), call. = FALSE) } } else stop("The argument to which.imp must be the indices corresponding to the imputations for which distributions are to be displayed.", call. = FALSE) @@ -182,7 +182,7 @@ bal.plot <- function(obj, var.name, ..., which, which.sub = NULL, cluster = NULL in.cluster <- !is.na(X$cluster) & sapply(X$cluster, function(x) !is.na(match(x, levels(X$cluster)[which.cluster]))) } else { - stop(paste0("The following inputs to which.cluster do not correspond to given clusters:\n\t", word.list(which.cluster[!which.cluster %in% seq_len(nlevels(X$cluster))])), call. = FALSE) + stop(paste0("The following inputs to which.cluster do not correspond to given clusters:\n\t", word_list(which.cluster[!which.cluster %in% seq_len(nlevels(X$cluster))])), call. = FALSE) } } else if (is.character(which.cluster)) { @@ -190,7 +190,7 @@ bal.plot <- function(obj, var.name, ..., which, which.sub = NULL, cluster = NULL in.cluster <- !is.na(X$cluster) & sapply(X$cluster, function(x) !is.na(match(x, which.cluster))) } else { - stop(paste0("The following inputs to which.cluster do not correspond to given clusters:\n\t", word.list(which.cluster[is.na(match(which.cluster, levels(X$cluster)))])), call. = FALSE) + stop(paste0("The following inputs to which.cluster do not correspond to given clusters:\n\t", word_list(which.cluster[is.na(match(which.cluster, levels(X$cluster)))])), call. = FALSE) } } else stop("The argument to which.cluster must be the names or indices corresponding to the clusters for which distributions are to be displayed.", call. = FALSE) @@ -213,16 +213,16 @@ bal.plot <- function(obj, var.name, ..., which, which.sub = NULL, cluster = NULL #nothing; which.time is good } else if (any(which.time %in% seq_along(X$covs.list)[appears.in.time])) { - warning(paste0(var.name, " does not appear in time period ", word.list(which.time[!which.time %in% seq_along(X$covs.list)[appears.in.time]], "or"), "."), call. = FALSE) + warning(paste0(var.name, " does not appear in time period ", word_list(which.time[!which.time %in% seq_along(X$covs.list)[appears.in.time]], "or"), "."), call. = FALSE) which.time <- which.time[which.time %in% seq_along(X$covs.list)[appears.in.time]] } else { - stop(paste0(var.name, " does not appear in time period ", word.list(which.time, "or"), "."), call. = FALSE) + stop(paste0(var.name, " does not appear in time period ", word_list(which.time, "or"), "."), call. = FALSE) } in.time <- !is.na(X$time) & X$time %in% which.time } else { - stop(paste0("The following inputs to which.time do not correspond to given time periods:\n\t", word.list(which.time[!which.time %in% seq_along(X$covs.list)])), call. = FALSE) + stop(paste0("The following inputs to which.time do not correspond to given time periods:\n\t", word_list(which.time[!which.time %in% seq_along(X$covs.list)])), call. = FALSE) } } else if (is.character(which.time)) { @@ -231,14 +231,14 @@ bal.plot <- function(obj, var.name, ..., which, which.sub = NULL, cluster = NULL #nothing; which.time is good } else if (any(which.time %in% treat.names[appears.in.time])) { - time.periods <- word.list(which.time[!which.time %in% treat.names[appears.in.time]], "and") + time.periods <- word_list(which.time[!which.time %in% treat.names[appears.in.time]], "and") warning(paste0(var.name, " does not appear in the time period", ifelse(attr(time.periods, "plural"), "s ", " "), "corresponding to treatment", ifelse(attr(time.periods, "plural"), "s ", " "), time.periods, "."), call. = FALSE) which.time <- which.time[which.time %in% treat.names[appears.in.time]] } else { - time.periods <- word.list(which.time, "and") + time.periods <- word_list(which.time, "and") stop(paste0(var.name, " does not appear in the time period", ifelse(attr(time.periods, "plural"), "s ", " "), "corresponding to treatment", ifelse(attr(time.periods, "plural"), "s ", " "), time.periods, "."), call. = FALSE) @@ -247,7 +247,7 @@ bal.plot <- function(obj, var.name, ..., which, which.sub = NULL, cluster = NULL } else { - stop(paste0("The following inputs to which.time do not correspond to given time periods:\n\t", word.list(which.time[!which.time %in% treat.names])), call. = FALSE) + stop(paste0("The following inputs to which.time do not correspond to given time periods:\n\t", word_list(which.time[!which.time %in% treat.names])), call. = FALSE) } } else stop("The argument to which.time must be the names or indices corresponding to the time periods for which distributions are to be displayed.", call. = FALSE) diff --git a/R/get.w.R b/R/get.w.R index 3fb564fc..3e6e2684 100644 --- a/R/get.w.R +++ b/R/get.w.R @@ -9,19 +9,19 @@ get.w.ps <- function(x, stop.method = NULL, estimand = NULL, s.weights = FALSE, if (any(is.character(stop.method))) { rule1 <- names(ps$w)[pmatch(tolower(names(ps$w)), tolower(stop.method), 0L)] if (is_null(rule1)) { - message(paste0("Warning: stop.method should be ", word.list(names(ps$w), and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.")) + message(paste0("Warning: stop.method should be ", word_list(names(ps$w), and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.")) rule1 <- names(ps$w) } } else if (is.numeric(stop.method) && any(stop.method %in% seq_along(names(ps$w)))) { if (any(!stop.method %in% seq_along(names(ps$w)))) { message(paste0("Warning: There are ", length(names(ps$w)), " stop methods available, but you requested ", - word.list(stop.method[!stop.method %in% seq_along(names(ps$w))], and.or = "and"),".")) + word_list(stop.method[!stop.method %in% seq_along(names(ps$w))], and.or = "and"),".")) } rule1 <- names(ps$w)[stop.method %in% seq_along(names(ps$w))] } else { - warning("stop.method should be ", word.list(names(ps$w), and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.", call. = FALSE) + warning("stop.method should be ", word_list(names(ps$w), and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.", call. = FALSE) rule1 <- names(ps$w) } } @@ -62,19 +62,19 @@ get.w.mnps <- function(x, stop.method = NULL, s.weights = FALSE, ...) { if (is.character(stop.method)) { rule1 <- mnps$stopMethods[pmatch(tolower(stop.method), tolower(mnps$stopMethods), nomatch = 0L)] if (is_null(rule1)) { - message(paste0("Warning: stop.method should be ", word.list(mnps$stopMethods, and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.")) + message(paste0("Warning: stop.method should be ", word_list(mnps$stopMethods, and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.")) rule1 <- mnps$stopMethods } } else if (is.numeric(stop.method) && any(stop.method %in% seq_along(mnps$stopMethods))) { if (any(!stop.method %in% seq_along(mnps$stopMethods))) { message(paste0("Warning: There are ", length(mnps$stopMethods), " stop methods available, but you requested ", - word.list(stop.method[!stop.method %in% seq_along(mnps$stopMethods)], and.or = "and"),".")) + word_list(stop.method[!stop.method %in% seq_along(mnps$stopMethods)], and.or = "and"),".")) } rule1 <- mnps$stopMethods[stop.method %in% seq_along(mnps$stopMethods)] } else { - warning("stop.method should be ", word.list(mnps$stopMethods, and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.", call. = FALSE) + warning("stop.method should be ", word_list(mnps$stopMethods, and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.", call. = FALSE) rule1 <- mnps$stopMethods } } @@ -128,7 +128,7 @@ get.w.ps.cont <- function(x, stop.method = NULL, s.weights = FALSE, ...) { if (any(is.character(stop.method))) { rule1 <- names(ps.cont$w)[pmatch(tolower(names(ps.cont$w)), tolower(stop.method), 0L)] if (is_null(rule1)) { - message(paste0("Warning: stop.method should be ", word.list(names(ps.cont$w), and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.")) + message(paste0("Warning: stop.method should be ", word_list(names(ps.cont$w), and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.")) rule1 <- names(ps.cont$w) } @@ -136,12 +136,12 @@ get.w.ps.cont <- function(x, stop.method = NULL, s.weights = FALSE, ...) { else if (is.numeric(stop.method) && any(stop.method %in% seq_along(names(ps.cont$w)))) { if (any(!stop.method %in% seq_along(names(ps.cont$w)))) { message(paste0("Warning: There are ", length(names(ps.cont$w)), " stop methods available, but you requested ", - word.list(stop.method[!stop.method %in% seq_along(names(ps.cont$w))], and.or = "and"),".")) + word_list(stop.method[!stop.method %in% seq_along(names(ps.cont$w))], and.or = "and"),".")) } rule1 <- names(ps.cont$w)[stop.method %in% seq_along(names(ps.cont$w))] } else { - warning("stop.method should be ", word.list(names(ps.cont$w), and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.", call. = FALSE) + warning("stop.method should be ", word_list(names(ps.cont$w), and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.", call. = FALSE) rule1 <- names(ps.cont$w) } } @@ -169,19 +169,19 @@ get.w.iptw <- function(x, stop.method = NULL, s.weights = FALSE, ...) { if (any(is.character(stop.method))) { rule1 <- names(iptw$psList[[1]]$ps)[pmatch(tolower(names(iptw$psList[[1]]$ps)), tolower(stop.method), 0L)] if (is_null(rule1)) { - message(paste0("Warning: stop.method should be ", word.list(names(iptw$psList[[1]]$ps), and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.")) + message(paste0("Warning: stop.method should be ", word_list(names(iptw$psList[[1]]$ps), and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.")) rule1 <- names(iptw$psList[[1]]$ps) } } else if (is.numeric(stop.method) && any(stop.method %in% seq_along(names(iptw$psList[[1]]$ps)))) { if (any(!stop.method %in% seq_along(names(iptw$psList[[1]]$ps)))) { message(paste0("Warning: There are ", length(names(iptw$psList[[1]]$ps)), " stop methods available, but you requested ", - word.list(stop.method[!stop.method %in% seq_along(names(iptw$psList[[1]]$ps))], and.or = "and"),".")) + word_list(stop.method[!stop.method %in% seq_along(names(iptw$psList[[1]]$ps))], and.or = "and"),".")) } rule1 <- names(iptw$psList[[1]]$ps)[stop.method %in% seq_along(names(iptw$psList[[1]]$ps))] } else { - warning("stop.method should be ", word.list(names(iptw$psList[[1]]$ps), and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.", call. = FALSE) + warning("stop.method should be ", word_list(names(iptw$psList[[1]]$ps), and.or = "or", quotes = TRUE), ".\nUsing all available stop methods instead.", call. = FALSE) rule1 <- names(iptw$psList[[1]]$ps) } } diff --git a/R/love.plot.R b/R/love.plot.R index 6afe058d..0b464f10 100644 --- a/R/love.plot.R +++ b/R/love.plot.R @@ -752,7 +752,7 @@ love.plot <- function(x, stat = "mean.diffs", threshold = NULL, missing.stats <- vapply(which.stat, function(s) { all(is.na(SS[["mean.stat"]][SS[["Statistic"]] == which.stat2[s]])) }, logical(1L)) - if (any(missing.stats)) stop(paste0(word.list(firstup(tolower(which.stat2[which.stat[missing.stats]]))), " cannot be displayed. This can occur when ", word.list(paste.("disp", tolower(which.stat[missing.stats])), and.or = "and", is.are = TRUE), " FALSE and quick = TRUE in the original call to bal.tab()."), call. = FALSE) + if (any(missing.stats)) stop(paste0(word_list(firstup(tolower(which.stat2[which.stat[missing.stats]]))), " cannot be displayed. This can occur when ", word_list(paste.("disp", tolower(which.stat[missing.stats])), and.or = "and", is.are = TRUE), " FALSE and quick = TRUE in the original call to bal.tab()."), call. = FALSE) gone <- character(0) for (i in levels(SS$Sample)) { @@ -828,7 +828,7 @@ love.plot <- function(x, stat = "mean.diffs", threshold = NULL, missing.stats <- vapply(which.stat, function(s) { all(is.na(SS[["stat"]][SS[["Statistic"]] == which.stat2[s]])) }, logical(1L)) - if (any(missing.stats)) stop(paste0(word.list(firstup(tolower(which.stat2[which.stat[missing.stats]]))), " cannot be displayed. This can occur when ", word.list(paste.("disp", tolower(which.stat[missing.stats])), and.or = "and"), " are FALSE and quick = TRUE in the original call to bal.tab()."), call. = FALSE) + if (any(missing.stats)) stop(paste0(word_list(firstup(tolower(which.stat2[which.stat[missing.stats]]))), " cannot be displayed. This can occur when ", word_list(paste.("disp", tolower(which.stat[missing.stats])), and.or = "and"), " are FALSE and quick = TRUE in the original call to bal.tab()."), call. = FALSE) gone <- character(0) for (i in levels(SS$Sample)) { diff --git a/R/print.bal.tab.R b/R/print.bal.tab.R index 2f43d6d6..30d49850 100644 --- a/R/print.bal.tab.R +++ b/R/print.bal.tab.R @@ -589,7 +589,7 @@ print.bal.tab.cluster <- function(x, disp.m.threshold = "as.is", disp.v.threshol p.ops$cluster.fun <- cluster.fun } if (is_not_null(p.ops$cluster.fun)) { - if (!is.character(p.ops$cluster.fun)) stop(paste0("cluster.fun must be ", word.list(c(cluster.funs, "as.is"), and.or = "or", quotes = TRUE))) + if (!is.character(p.ops$cluster.fun)) stop(paste0("cluster.fun must be ", word_list(c(cluster.funs, "as.is"), and.or = "or", quotes = TRUE))) p.ops$cluster.fun <- match_arg(tolower(p.ops$cluster.fun), cluster.funs, several.ok = TRUE) if (is_null(p.ops$cluster.fun)) { warning("There were no valid entries to cluster.fun. Using the default cluster.funs instead.", call. = FALSE) @@ -895,7 +895,7 @@ print.bal.tab.imp <- function(x, disp.m.threshold = "as.is", disp.v.threshold = p.ops$imp.fun <- imp.fun } if (is_not_null(p.ops$imp.fun)) { - if (!is.character(p.ops$imp.fun)) stop(paste0("imp.fun must be ", word.list(c(imp.funs, "as.is"), and.or = "or", quotes = TRUE))) + if (!is.character(p.ops$imp.fun)) stop(paste0("imp.fun must be ", word_list(c(imp.funs, "as.is"), and.or = "or", quotes = TRUE))) p.ops$imp.fun <- match_arg(tolower(p.ops$imp.fun), imp.funs, several.ok = TRUE) if (is_null(p.ops$imp.fun)) { warning("There were no valid entries to imp.fun. Using the default imp.funs instead.", call. = FALSE) @@ -1162,7 +1162,7 @@ print.bal.tab.imp.cluster <- function(x, disp.m.threshold = "as.is", disp.v.thre p.ops$cluster.fun <- cluster.fun } if (is_not_null(p.ops$cluster.fun)) { - if (!is.character(p.ops$cluster.fun)) stop(paste0("cluster.fun must be ", word.list(c(cluster.funs, "as.is"), and.or = "or", quotes = TRUE))) + if (!is.character(p.ops$cluster.fun)) stop(paste0("cluster.fun must be ", word_list(c(cluster.funs, "as.is"), and.or = "or", quotes = TRUE))) p.ops$cluster.fun <- match_arg(tolower(p.ops$cluster.fun), cluster.funs, several.ok = TRUE) if (is_null(p.ops$cluster.fun)) { warning("There were no valid entries to cluster.fun. Using the default cluster.funs instead.", call. = FALSE) @@ -1210,7 +1210,7 @@ print.bal.tab.imp.cluster <- function(x, disp.m.threshold = "as.is", disp.v.thre p.ops$imp.fun <- imp.fun } if (is_not_null(p.ops$imp.fun)) { - if (!is.character(p.ops$imp.fun)) stop(paste0("imp.fun must be ", word.list(c(imp.funs, "as.is"), and.or = "or", quotes = TRUE))) + if (!is.character(p.ops$imp.fun)) stop(paste0("imp.fun must be ", word_list(c(imp.funs, "as.is"), and.or = "or", quotes = TRUE))) p.ops$imp.fun <- match_arg(tolower(p.ops$imp.fun), imp.funs, several.ok = TRUE) if (is_null(p.ops$imp.fun)) { warning("There were no valid entries to imp.fun. Using the default imp.funs instead.", call. = FALSE) diff --git a/R/utilities.R b/R/utilities.R index 46c79680..5b470978 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -33,7 +33,7 @@ splitfactor <- function(data, var.name, replace = TRUE, sep = "_", drop.level = if (any(var.name %in% factor.names)) { if (any(!var.name %in% factor.names)) { not.in.factor.names <- var.name[!var.name %in% factor.names] - warning(paste(word.list(not.in.factor.names, "and", is.are = TRUE), + warning(paste(word_list(not.in.factor.names, "and", is.are = TRUE), "not the name(s) of factor variable(s) in data and will not be split."), call. = FALSE) } @@ -58,7 +58,7 @@ splitfactor <- function(data, var.name, replace = TRUE, sep = "_", drop.level = if (any(var.name %in% names(data))) { if (any(var.name %nin% names(data))) { not.in.data.names <- var.name[!var.name %in% names(data)] - warning(paste(word.list(not.in.data.names, "and", is.are = TRUE), + warning(paste(word_list(not.in.data.names, "and", is.are = TRUE), "not the name(s) of variable(s) in data and will not be split."), call. = FALSE) } @@ -220,7 +220,7 @@ unsplitfactor <- function(data, var.name, replace = TRUE, sep = "_", dropped.lev var.to.combine <- var.to.combine[names(var.to.combine) != NA.column] } else { - stop(paste("There is no variable called", word.list(NA.column, quotes = TRUE), "to generate the NA values."), call. = FALSE) + stop(paste("There is no variable called", word_list(NA.column, quotes = TRUE), "to generate the NA values."), call. = FALSE) } } var.sum <- rowSums(var.to.combine) @@ -275,7 +275,7 @@ unsplitfactor <- function(data, var.name, replace = TRUE, sep = "_", dropped.lev } } - if (is_not_null(not.the.stem)) warning(paste0(word.list(not.the.stem, is.are = TRUE, quotes = TRUE), " not the stem of any variables in data and will be ignored. Ensure var.name and sep are correct."), call. = FALSE) + if (is_not_null(not.the.stem)) warning(paste0(word_list(not.the.stem, is.are = TRUE, quotes = TRUE), " not the stem of any variables in data and will be ignored. Ensure var.name and sep are correct."), call. = FALSE) return(data) } @@ -352,11 +352,11 @@ set.cobalt.options <- function(..., default = FALSE) { any.string.allowed <- c("int_sep", "factor_sep") if (any(duplicates <- table(names(opts)) > 1)) { - stop(paste0(word.list(names(duplicates)[duplicates], is.are = TRUE), " present more than once in the input to set.cobalt.options."), call. = FALSE) + stop(paste0(word_list(names(duplicates)[duplicates], is.are = TRUE), " present more than once in the input to set.cobalt.options."), call. = FALSE) } if (any(names(opts) %nin% names(acceptable.options()))) { - warning(paste("The following are not acceptable options and will be ignored:", word.list(unique(names(opts)[names(opts) %nin% names(acceptable.options())]))), call. = FALSE, immediate. = TRUE) + warning(paste("The following are not acceptable options and will be ignored:", word_list(unique(names(opts)[names(opts) %nin% names(acceptable.options())]))), call. = FALSE, immediate. = TRUE) opts <- opts[names(opts) %in% names(acceptable.options())] } @@ -390,11 +390,11 @@ set.cobalt.options <- function(..., default = FALSE) { }), multiple.opts) problematic.opts[["bad"]] <- setNames(lapply(bad.opts, function(i) { if (i %in% any.string.allowed) paste0(i, " must be a character string.") - else paste0(i, " must be ", word.list(acceptable.options()[[i]], quotes = is.character(acceptable.options()[[i]]), and.or = "or"), ".") + else paste0(i, " must be ", word_list(acceptable.options()[[i]], quotes = is.character(acceptable.options()[[i]]), and.or = "or"), ".") }), bad.opts) problematic.opts[["both"]] <- setNames(lapply(both.opts, function(i) { if (i %in% any.string.allowed) paste0(i, " must be a character string of length 1.") - else paste0(i, " must be one of ", word.list(acceptable.options()[[i]], quotes = is.character(acceptable.options()[[i]]), and.or = "or"), ".") + else paste0(i, " must be one of ", word_list(acceptable.options()[[i]], quotes = is.character(acceptable.options()[[i]]), and.or = "or"), ".") }), both.opts) problems <- do.call("c", unname(problematic.opts)) @@ -425,7 +425,7 @@ get.cobalt.options <- function(...) { opts <- do.call("c", opts) if (any(not.in.accept <- opts %nin% names(acceptable.options()))) { plural <- sum(not.in.accept) > 1 - stop(paste0(word.list(opts[not.in.accept], is.are = TRUE, quotes = TRUE), + stop(paste0(word_list(opts[not.in.accept], is.are = TRUE, quotes = TRUE), " not", ifelse(plural, "", " an"), " acceptable option", ifelse(plural, "s", ""), "."), call. = FALSE) }