aphalo / ggpmisc

R package ggpmisc is an extension to ggplot2 and the Grammar of Graphics
https://docs.r4photobiology.info/ggpmisc
94 stars 6 forks source link

Allow `method` functions in model fit functions to return NA and NULL #31

Closed aphalo closed 3 months ago

aphalo commented 1 year ago

stat_poly_line(), stat_poly_eq() and relatives should be able to gracefully handle NA and NULL returned by model fit methods as an indication of failure, so that in such cases no line or equation is added to the plot. This would be useful in user defined wrappers on model fit methods.

aphalo commented 1 year ago

Not easy to implement because we need to pass all the variables to the geometry. As different geometries could be used this is not straightfoward, specially for lines.

aphalo commented 1 year ago

At least all variables mapped by default would need to be set to NA or "", but to do this correctly every value returned would need to be set also in the special case to something that does not trigger an error. So, I am closing this.

aphalo commented 4 months ago

One could possibly simply return an empty data frame with data.frame(), I think. It needs to be tested. A warning would also need to be issued.

aphalo commented 3 months ago

Implemented by returning data.frame() from stat_poly_eq(), stat_poly_line(), stat_ma_eq(), stat_ma_line(), stat_quant_eq(), stat_quant_line(), and stat_quant_band(). No warning is issued, assuming that, if needed, a warning will be issued by the user-defined model fit function. Unit tests added.