R/deduplicate_predictions.R

Defines functions deduplicate_predictions

#' @importFrom dplyr across any_of

deduplicate_predictions <- function(df){
  
  has_dups <- df %>% 
    select(-any_of("prediction")) %>% 
    vctrs::vec_group_id() %>% 
    vctrs::vec_duplicate_any()
  
  if(has_dups) {
    df <- df %>%
      filter(!is.na(prediction)) %>%
      group_by(across(-any_of("prediction"))) %>% 
      filter(dplyr::row_number() == 1L)
  }
  
  df
}
eco4cast/score4cast documentation built on Nov. 21, 2023, 12:25 p.m.