cmu-delphi / epidatr

Delphi Epidata API R Client
https://cmu-delphi.github.io/epidatr/
Other
1 stars 5 forks source link

Forbid `c(EpiRange, EpiRange)` constructions #97

Open dshemetov opened 1 year ago

dshemetov commented 1 year ago

Currently we error when someone does this, but the error is not very helpful. It would be nice to find a way to detect this combination ahead of time and throw a more useful error.

brookslogan commented 1 year ago

This particular construction and some others can be forbidden by providing a c.EpiRange <- function(...) { ..... } method that throws an error... all the time? Because c is "internal generic" and supports S3 "internal dispatch"; see ?InternalMethods.

A can of worms:

The above probably wouldn't catch c(object_with_class_that_is_not_an_epirange, an_epiprange), namely, if the first arg is a Date; for that, we may need to look into S4, because c is also S4 generic: from ?c:

S4 methods:

     This function is S4 generic, but with argument list '(x, ...)'.

S4 allows dispatch based on multiple arguments rather than a single argument, though I'm not sure how it works with dots.

dshemetov commented 1 year ago

Having learned just how gnarly c() is in the past month and given the can of worms in your comment, I'm fine with leaving this alone and just hoping the user knows not to use c() on complex R objects.