Skip to content

Commit

Permalink
Improve no visible binding issue fix (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
lshandross committed Mar 11, 2024
1 parent 60eb520 commit 52829ed
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -46,6 +46,7 @@ Imports:
magrittr,
matrixStats,
purrr,
rlang,
tidyr,
tidyselect
Remotes:
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -4,3 +4,4 @@ export("%>%")
export(linear_pool)
export(simple_ensemble)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
1 change: 0 additions & 1 deletion R/hubEnsembles-package.R
@@ -1 +0,0 @@
utils::globalVariables(c("model_id", "output_type", "output_type_id", "value", "pred_qs"))
4 changes: 3 additions & 1 deletion R/linear_pool.R
Expand Up @@ -80,6 +80,8 @@
#' all.equal(lp_from_component_qs$value, lp_qs, tolerance = 1e-3,
#' check.attributes=FALSE)
#'
#' @importFrom rlang .data

linear_pool <- function(model_outputs, weights = NULL,
weights_col_name = "weight",
model_id = "hub-ensemble",
Expand All @@ -100,7 +102,7 @@ linear_pool <- function(model_outputs, weights = NULL,

# calculate linear opinion pool for different types
ensemble_model_outputs <- model_outputs_validated |>
dplyr::group_split(output_type) |>
dplyr::group_split(.data$output_type) |>
purrr::map_dfr(.f = function(split_outputs) {
type <- split_outputs$output_type[1]
if (type %in% c("mean", "cdf", "pmf")) {
Expand Down
9 changes: 5 additions & 4 deletions R/linear_pool_quantile.R
Expand Up @@ -36,6 +36,7 @@
#' 3. Collect the samples from all component models and extract the desired quantiles.
#' Steps 1 and 2 in this process are performed by `distfromq::make_q_fun`.
#' @return a `model_out_tbl` object of ensemble predictions for the `quantile` output type.
#' @importFrom rlang .data

linear_pool_quantile <- function(model_outputs, weights = NULL,
weights_col_name = "weight",

Check warning on line 42 in R/linear_pool_quantile.R

View workflow job for this annotation

GitHub Actions / lint

file=R/linear_pool_quantile.R,line=42,col=24,[indentation_linter] Hanging indent should be 33 spaces but is 24 spaces.
Expand Down Expand Up @@ -66,19 +67,19 @@ linear_pool_quantile <- function(model_outputs, weights = NULL,
dplyr::group_by(model_id, dplyr::across(dplyr::all_of(group_by_cols))) |>
dplyr::summarize(
pred_qs = list(distfromq::make_q_fn(

Check warning on line 69 in R/linear_pool_quantile.R

View workflow job for this annotation

GitHub Actions / lint

file=R/linear_pool_quantile.R,line=69,col=6,[indentation_linter] Hanging indent should be 21 spaces but is 6 spaces.
ps = as.numeric(output_type_id),
qs = value,
ps = as.numeric(.data$output_type_id),

Check warning on line 70 in R/linear_pool_quantile.R

View workflow job for this annotation

GitHub Actions / lint

file=R/linear_pool_quantile.R,line=70,col=8,[indentation_linter] Hanging indent should be 42 spaces but is 8 spaces.
qs = .data$value,
...)(seq(from = 0, to = 1, length.out = n_samples + 2)[2:n_samples])),
.groups = "drop") |>
tidyr::unnest(pred_qs) |>
tidyr::unnest(.data$pred_qs) |>
dplyr::group_by(dplyr::across(dplyr::all_of(task_id_cols))) |>
dplyr::summarize(
output_type_id = list(quantile_levels),
value = list(do.call(Hmisc::wtd.quantile, args = agg_args)),
.groups = "drop") |>
tidyr::unnest(cols = tidyselect::all_of(c("output_type_id", "value"))) |>
dplyr::mutate(model_id = model_id, .before = 1) |>
dplyr::mutate(output_type = "quantile", .before = output_type_id) |>
dplyr::mutate(output_type = "quantile", .before = .data$output_type_id) |>
dplyr::ungroup()

return(quantile_outputs)
Expand Down
10 changes: 5 additions & 5 deletions R/validate_output_type_ids.R
Expand Up @@ -14,15 +14,15 @@
#' @return no return value
#'
#' @noRd
#'
#' @importFrom rlang .data

validate_output_type_ids <- function(model_outputs, task_id_cols) {
same_output_id <- model_outputs |>
dplyr::filter(output_type %in% c("cdf", "pmf", "quantile")) |>
dplyr::group_by(model_id, dplyr::across(dplyr::all_of(task_id_cols)), output_type) |>
dplyr::summarize(output_type_id_list=list(sort(output_type_id))) |>
dplyr::filter(.data$output_type %in% c("cdf", "pmf", "quantile")) |>
dplyr::group_by(.data$model_id, dplyr::across(dplyr::all_of(task_id_cols)), .data$output_type) |>
dplyr::summarize(output_type_id_list=list(sort(.data$output_type_id))) |>
dplyr::ungroup() |>
dplyr::group_split(dplyr::across(dplyr::all_of(task_id_cols)), output_type) |>
dplyr::group_split(dplyr::across(dplyr::all_of(task_id_cols)), .data$output_type) |>
purrr::map(.f = function(split_outputs) {
length(unique(split_outputs$output_type_id_list)) == 1
}) |>
Expand Down

0 comments on commit 52829ed

Please sign in to comment.