Skip to content

Commit 1953103

Browse files
committed
drop check_pname in favor just just check_name
1 parent 93386d8 commit 1953103

File tree

5 files changed

+13
-37
lines changed

5 files changed

+13
-37
lines changed

R/layer_cdc_flatline_quantiles.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ slather.layer_cdc_flatline_quantiles <-
227227
) %>%
228228
select(all_of(c(avail_grps, ".pred_distn_all")))
229229

230-
# res <- check_pname(res, components$predictions, object)
231230
components$predictions <- left_join(
232231
components$predictions,
233232
res,

R/layer_point_from_distn.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ slather.layer_point_from_distn <-
9393
components$predictions$.pred <- dstn
9494
} else {
9595
dstn <- tibble(dstn = dstn)
96-
dstn <- check_pname(dstn, components$predictions, object)
96+
dstn <- check_name(
97+
dstn,
98+
components$predictions,
99+
object,
100+
newname = object$name
101+
)
97102
components$predictions <- mutate(components$predictions, !!!dstn)
98103
}
99104
components

R/layer_quantile_distn.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ slather.layer_quantile_distn <-
9696
dstn <- snap(dstn, truncate[1], truncate[2])
9797
}
9898
dstn <- tibble(dstn = dstn)
99-
dstn <- check_pname(dstn, components$predictions, object)
99+
dstn <- check_name(
100+
dstn,
101+
components$predictions,
102+
object,
103+
newname = object$name
104+
)
100105
components$predictions <- mutate(components$predictions, !!!dstn)
101106
components
102107
}

R/layer_residual_quantiles.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ slather.layer_residual_quantiles <-
139139

140140
estimate <- components$predictions$.pred
141141
res <- tibble(.pred_distn = r$dstn + estimate)
142-
res <- check_pname(res, components$predictions, object)
142+
res <- check_name(res, components$predictions, object, newname = object$name)
143143
components$predictions <- mutate(components$predictions, !!!res)
144144
components
145145
}

R/utils-misc.R

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,3 @@
1-
#' Check that newly created variable names don't overlap
2-
#'
3-
#' `check_pname` is to be used in a slather method to ensure that
4-
#' newly created variable names don't overlap with existing names.
5-
#' Throws an warning if check fails, and creates a random string.
6-
#' @param res A data frame or tibble of the newly created variables.
7-
#' @param preds An epi_df or tibble containing predictions.
8-
#' @param object A layer object passed to [slather()].
9-
#' @param newname A string of variable names if the object doesn't contain a
10-
#' $name element
11-
#'
12-
#' @keywords internal
13-
check_pname <- function(res, preds, object, newname = NULL) {
14-
if (is.null(newname)) newname <- object$name
15-
new_preds_names <- colnames(preds)
16-
intersection <- new_preds_names %in% newname
17-
if (any(intersection)) {
18-
newname <- rand_id(newname)
19-
rlang::warn(
20-
paste0(
21-
"Name collision occured in `",
22-
class(object)[1],
23-
"`. The following variable names already exists: ",
24-
paste0(new_preds_names[intersection], collapse = ", "),
25-
". Result instead has randomly generated string `",
26-
newname, "`."
27-
)
28-
)
29-
}
30-
names(res) <- newname
31-
res
32-
}
33-
341
# Copied from `epiprocess`:
352

363
#' "Format" a character vector of column/variable names for cli interpolation

0 commit comments

Comments
 (0)