anhoej / qicharts2

R package: Quality improvement charts
38 stars 12 forks source link

If x.period is NULL, qic returns error message #18

Closed lenakba closed 5 years ago

lenakba commented 5 years ago

When using time data and defining x.period, qic works just fine: library(qicharts2) qic(x = date, y = los, data = cabg, x.period = "month", chart = "xbar")

Also, you can run qic without specifying x.period: library(qicharts2) qic(x = date, y = los, data = cabg, chart = "xbar")

But if you define x.period as NULL, the qic command returns an error and the figure is not returned:

library(qicharts2)
qic(x = date, y = los, data = cabg, x.period = NULL, chart = "xbar")
#> Error in cut.POSIXt(x, breaks = x.period): invalid specification of 'breaks'

This is problematic when someone calls the qic-command in a function where x.period is defined as NULL by default.

I think this can be solved by replacing !missing with !is.null in this part of the qic function:

if (inherits(x, c('Date', 'POSIXt'))) { 
x <- as.POSIXct(as.character(x), tz = 'UTC')    
if (!missing(x.period)) {   
x <- as.POSIXct(cut(x, breaks = x.period))  
 }  
}
anhoej commented 5 years ago

Fixed on GitHub. Please test and report back.

pwildenhain commented 5 years ago

Thanks for making this change, it's going to be a big help to my team who frequently useqic(). However, we exclusively use the latest CRAN version. Do you have an estimation for when the next CRAN release will be?

anhoej commented 5 years ago

No promises. But probably within a couple of weeks.