ddediu / AdhereR

Computation of adherence to medications from Electronic Healthcare Data in R
26 stars 6 forks source link

Interactive plot not showing 'per episode' results #22

Closed ptityeti closed 5 years ago

ptityeti commented 5 years ago

Open interactive shiny plot using following code.

dataset <- structure(list(patientid = c("N05AX07", "N05AX07", "C09CA03", 
                                        "N05AX07", "C09CA03", "C09CA03", "N05AX07", "N05AX07", "N05AX07", 
                                        "A10BA02", "A10BA02", "A10BA02", "C07AB07", "A10BA02", "A10BA02", 
                                        "A10BA02", "A10BA02", "A10BA02", "C09CA03", "A10BA02", "A10BA02", 
                                        "A10BA02", "C07AB07", "A10BA02", "A10BA02", "C07AB07", "A10BA02", 
                                        "C07AB07", "C09CA03", "A10BA02", "A10BA02", "A10BA02", "C09CA03", 
                                        "A10BA02", "A10BA02", "C09CA03", "A10BA02", "C07AB07", "A10BA02", 
                                        "A10BA02", "A10BA02", "A10BA02", "A10BA02", "C07AB07", "C09CA03", 
                                        "A10BA02"), deliverydate = structure(c(16881, 16905, 16905, 16955, 
                                                                               16955, 17050, 17081, 17107, 17108, 17115, 17134, 17136, 17136, 
                                                                               17147, 17147, 17168, 17171, 17175, 17235, 17235, 17255, 17255, 
                                                                               17276, 17283, 17315, 17315, 17319, 17326, 17326, 17326, 17326, 
                                                                               17458, 17458, 17458, 17493, 17569, 17569, 17582, 17582, 17606, 
                                                                               17626, 17649, 17649, 17649, 17649, 17649), class = "Date"), NDays = c(12.5, 
                                                                                                                                                     12.5, 98, 12.5, 98, 98, 12.5, 12.5, 12.5, 20, 20, 20, 50, 20, 
                                                                                                                                                     20, 20, 20, 20, 98, 20, 20, 20, 50, 20, 20, 50, 20, 50, 98, 20, 
                                                                                                                                                     20, 20, 98, 20, 20, 98, 20, 50, 20, 20, 20, 20, 20, 50, 98, 20
                                                                               )), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
                                                                                                                                           -46L))
library(AdhereR)
plot_interactive_cma(data = dataset, ID.colname = 'patientid', event.date.colname = 'deliverydate', event.duration.colname = 'NDays')

This works as expected.

When now selecting "per episode" in the menu "Select CMA type", errors appear:

AdhereR version 0.3.1 R version 3.5.1

ddediu commented 5 years ago

Hi Wouter! thanks for the bug report and sorry it took me so long (I just came back from yet another travel). The thing is very simple and boils down to not doing enough consistency checks on the parameter values when computing episodes (now, we spit a much more informative error message). More precisely, you don't define any medication class column but CMA_per_episode() by default has medication.change.means.new.treatment.episode = TRUE which forces the use of medication class and which, thus, resulted in an ugly crash: now this case is checked and explicitly marked as an error which can be corrected either by providing a medication class name or by setting medication.change.means.new.treatment.episode to FALSE... These changes will be in the devel branch soon Best, Dan