From 4f2ec3f8d8ed188cf4f4e06ce6bc3e31f8a2787f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:07:44 +0000 Subject: [PATCH 1/5] Initial plan From b8d6c239234f752b631272d5c512346cdcd42195 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:11:48 +0000 Subject: [PATCH 2/5] Fix PM_compare to use namespaced purrr and rlang functions Co-authored-by: mhovd <66058642+mhovd@users.noreply.github.com> --- R/PM_compare.R | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/R/PM_compare.R b/R/PM_compare.R index 7d5ba7427..33ef67f9c 100755 --- a/R/PM_compare.R +++ b/R/PM_compare.R @@ -118,8 +118,8 @@ PM_compare <- function(..., icen = "median", outeq = 1, plot = FALSE) { } }) tibble( - bias = map_chr(res, 1), - imp = map_chr(res, 2) + bias = purrr::map_chr(res, 1), + imp = purrr::map_chr(res, 2) ) @@ -397,10 +397,10 @@ PM_compare <- function(..., icen = "median", outeq = 1, plot = FALSE) { sort() - tbl_par <- map(par, \(x){ + tbl_par <- purrr::map(par, \(x){ all_par %in% x - })%>% map(~ set_names(., all_par)) %>% + })%>% purrr::map(~ rlang::set_names(., all_par)) %>% bind_rows() %>% mutate(Run = objNames[1:n()]) %>% select(Run, dplyr::everything()) @@ -461,7 +461,7 @@ if (getPMoptions("ic_method") == "aic"){ results$aic <- NULL } -op_tbl <- op %>% map(\(i) { +op_tbl <- op %>% purrr::map(\(i) { i %>% filter(icen == "median") %>% group_by(pred.type) %>% group_map(~ { fit <- lm(obs ~ pred, data = .x) @@ -470,16 +470,16 @@ op_tbl <- op %>% map(\(i) { sl = coef(fit)[2], r2 = summary(fit)$r.squared ) - }) %>% list_rbind() -}) %>% set_names(objNames[1:nobj]) %>% -map(~ .x %>% mutate(pred.type = c("pop", "post"))) %>% -list_rbind(names_to = "run") %>% + }) %>% purrr::list_rbind() +}) %>% rlang::set_names(objNames[1:nobj]) %>% +purrr::map(~ .x %>% mutate(pred.type = c("pop", "post"))) %>% +purrr::list_rbind(names_to = "run") %>% pivot_wider(id_cols = c(run), names_from = c(pred.type), names_glue = "{pred.type}{stringr::str_to_title({.value})}", values_from = c(int, sl, r2)) results <- bind_cols(results, op_tbl %>% select(-run)) results$pval <- t -results$best <- results %>% select(c(-run, -nvar, -converged, -pval)) %>% map(~ which(.x == min(.x))) %>% unlist() %>% table() +results$best <- results %>% select(c(-run, -nvar, -converged, -pval)) %>% purrr::map(~ which(.x == min(.x))) %>% unlist() %>% table() attr(results, "highlight") <- TRUE class(results) <- c("PM_compare", "data.frame") From 9d422c1194ba09012c6f899d0c8629946a8567f9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:16:08 +0000 Subject: [PATCH 3/5] Fix PMutilities cli_df to use namespaced purrr::map_vec and stringr::str_split Co-authored-by: mhovd <66058642+mhovd@users.noreply.github.com> --- NAMESPACE | 2 ++ R/PMutilities.R | 2 +- R/Pmetrics-package.R | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index d9dc970c2..68a97ae01 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -261,6 +261,7 @@ importFrom(purrr,map2) importFrom(purrr,map_chr) importFrom(purrr,map_df) importFrom(purrr,map_lgl) +importFrom(purrr,map_vec) importFrom(purrr,pluck) importFrom(purrr,reduce) importFrom(readr,read_file) @@ -358,6 +359,7 @@ importFrom(stats,wilcox.test) importFrom(stringr,regex) importFrom(stringr,str_glue) importFrom(stringr,str_replace) +importFrom(stringr,str_split) importFrom(tidyr,crossing) importFrom(tidyr,extract) importFrom(tidyr,fill) diff --git a/R/PMutilities.R b/R/PMutilities.R index 9fbf7c7fe..37e54c095 100755 --- a/R/PMutilities.R +++ b/R/PMutilities.R @@ -1463,7 +1463,7 @@ wtd.var <- function(x, weights = NULL, df_tab <- knitr::kable(df_chr, format = "simple") # rebuild the data frame - df2 <- map_vec(df_tab, \(x) str_split(x, "(?<=\\s)(?=\\S)")) + df2 <- purrr::map_vec(df_tab, \(x) stringr::str_split(x, "(?<=\\s)(?=\\S)")) df2 <- as.data.frame(do.call(rbind, df2)) # replace minima with highlighted versions diff --git a/R/Pmetrics-package.R b/R/Pmetrics-package.R index ad0232347..5e73e71e1 100755 --- a/R/Pmetrics-package.R +++ b/R/Pmetrics-package.R @@ -23,12 +23,12 @@ #' theme ggtitle element_blank element_text geom_segment aes_string aes_string theme_bw theme_grey #' coord_fixed facet_wrap labs geom_smooth xlim ylim theme_void #' scale_color_identity scale_fill_identity -#' @importFrom purrr map map2 reduce map_chr keep pluck map_lgl map_df list_rbind +#' @importFrom purrr map map2 reduce map_chr keep pluck map_lgl map_df list_rbind map_vec #' @importFrom magrittr %>% # #' @importFrom tibble as_tibble tibble #' @importFrom tidyr pivot_longer pivot_wider nest unnest extract separate fill #' crossing separate_wider_delim -#' @importFrom stringr str_replace regex +#' @importFrom stringr str_replace regex str_glue str_split # #' @importFrom mclust Mclust #' @importFrom grDevices col2rgb dev.off devAskNewPage gray.colors jpeg #' pdf png postscript rgb setEPS From acc4e3357b43595e2c32f0c4cef06952370b6176 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:17:37 +0000 Subject: [PATCH 4/5] Add namespace prefix to pluck call in PM_compare Co-authored-by: mhovd <66058642+mhovd@users.noreply.github.com> --- R/PM_compare.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/PM_compare.R b/R/PM_compare.R index 33ef67f9c..dc2d7ce82 100755 --- a/R/PM_compare.R +++ b/R/PM_compare.R @@ -492,7 +492,7 @@ if(plot){ p3 = p3, # likelihood comparison ft1 = ft1, # gamlam comparison: NULL if equal within PMoptions digits ft2 = ft2, # model parameter comparison - metric_types = sumobjPop[[1]]$pe %>% get_metric_info() %>% pluck("metric_types") + metric_types = sumobjPop[[1]]$pe %>% get_metric_info() %>% purrr::pluck("metric_types") ) From 0c8d94974c89de1b33c3d2800c4c320fe30bac89 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:19:42 +0000 Subject: [PATCH 5/5] Add missing purrr imports (imap, list_flatten) and fix set_names consistency Co-authored-by: mhovd <66058642+mhovd@users.noreply.github.com> --- NAMESPACE | 2 ++ R/PM_compare.R | 2 +- R/Pmetrics-package.R | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 68a97ae01..b5a5f7d5e 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -254,7 +254,9 @@ importFrom(plotly,plot_ly) importFrom(plotly,plotly_build) importFrom(plotly,renderPlotly) importFrom(plotly,subplot) +importFrom(purrr,imap) importFrom(purrr,keep) +importFrom(purrr,list_flatten) importFrom(purrr,list_rbind) importFrom(purrr,map) importFrom(purrr,map2) diff --git a/R/PM_compare.R b/R/PM_compare.R index dc2d7ce82..fb52fa621 100755 --- a/R/PM_compare.R +++ b/R/PM_compare.R @@ -316,7 +316,7 @@ PM_compare <- function(..., icen = "median", outeq = 1, plot = FALSE) { if(length(not_same$outeq)>0){ ft1 <- gamlam %>% select(Run, dplyr::everything()) %>% - purrr::set_names(c("Run", "Cycle", "Value", "Outeq", "Type")) %>% + rlang::set_names(c("Run", "Cycle", "Value", "Outeq", "Type")) %>% mutate(Value = round2(Value)) %>% flextable::flextable() %>% flextable::theme_zebra() %>% diff --git a/R/Pmetrics-package.R b/R/Pmetrics-package.R index 5e73e71e1..dee7a9544 100755 --- a/R/Pmetrics-package.R +++ b/R/Pmetrics-package.R @@ -23,7 +23,7 @@ #' theme ggtitle element_blank element_text geom_segment aes_string aes_string theme_bw theme_grey #' coord_fixed facet_wrap labs geom_smooth xlim ylim theme_void #' scale_color_identity scale_fill_identity -#' @importFrom purrr map map2 reduce map_chr keep pluck map_lgl map_df list_rbind map_vec +#' @importFrom purrr map map2 reduce map_chr keep pluck map_lgl map_df list_rbind map_vec imap list_flatten #' @importFrom magrittr %>% # #' @importFrom tibble as_tibble tibble #' @importFrom tidyr pivot_longer pivot_wider nest unnest extract separate fill