ceefluz / radar

An interactive tool for rapid analysis of diagnostic and antimicrobial pattern in R using Shiny
https://ceefluz.shinyapps.io/radar/
GNU General Public License v2.0
105 stars 103 forks source link

antimicrobials atc_code index incompatible types #7

Open Youguang opened 6 months ago

Youguang commented 6 months ago

Error:

Error in left_join(): ! Can't join x$atc_code with y$atc_code due to incompatible types. ℹ x$atc_code is a . ℹ y$atc_code is a .

Possible reason:

https://github.com/ceefluz/radar/blob/df1df2324605d9165439785271d5bc11c4bae5b4/global.R#L105-L113

typeof(AMR::antibiotics$atc)
[1] "list"
Youguang commented 6 months ago

After unnest AMR::antibiotics, it works now

antimicrobials <- antimicrobials %>% 
   mutate(ab_days = as.integer(ab_stop_date - ab_start_date), 
          ab_timing = as.integer(ab_start_date - adm_start_date), 
          ddd_per_prescription = ddd_per_day*ab_days) %>% 
   left_join( 
     AMR::antibiotics %>% 
       select( 
         atc_code = atc, ab_type = name, ab_group = atc_group2 
       ) %>% unnest(atc_code), by = "atc_code") %>%