FelicienLL / mapbayr

Easy Maximum A Posteriori Bayesian Estimation of PK parameters in R.
21 stars 2 forks source link

Deal with non numeric columns in `do_model_averaging()` #197

Closed LauraMvn closed 1 year ago

LauraMvn commented 1 year ago

When there is one or more non numeric columns in elements from list_of_tabs used in do_model_averaging() , as for example a character column with PRED and IPRED, the function does not manage this case.

library(tibble)
list_tab1 <- list(
  tibble(ID = 1, char = rep(c("PRED", "IPRED"), 2), num = 1:4),
  tibble(ID = 1, char = rep(c("PRED", "IPRED"), 2), num = 5:8)
  )
list_tab2 <- list(
  tibble(ID = 1, num = 1:4),
  tibble(ID = 1, num = 5:8)
)
weights <- matrix(nrow = 1, ncol = 2, data = c(0.3, 0.7))

library(mapbayr)
do_model_averaging(list_tab2, weights)
#>   ID num
#> 1  1 3.8
#> 2  1 4.8
#> 3  1 5.8
#> 4  1 6.8
do_model_averaging(list_tab1, weights)
#> Error in `map2()`:
#> ℹ In index: 1.
#> ℹ With name: 1.
#> Caused by error in `FUN()`:
#> ! argument non numérique pour un opérateur binaire

Created on 2023-04-20 with reprex v2.0.2