Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upcreate use_first_valid_of function #32
Comments
|
Like this code I just reviewed:
|
|
Numeric, logical, character instances are easy. Is it important to retain factor class if all inputs are factors? And how should this work for dates? Maybe allow the user to specify a class and then the empty result vector will be initialized with that type of NA? Edit: if possible, better to have the function detect the uniform class of the input vectors and do that automatically. Dates -> Dates without user specification. |
|
Not going to have this create a new variable indicating the source vector used for each value. That's a non-critical option, and this is clearest if it always returns a single vector. |
For saying, use A if not NA, otherwise use B if not NA, otherwise... could just be a big case_when call (edit: case_when is probably not right given variable # of args, for loop may be simplest). Optionally create a new variable indicating which one was used.
Besides being more readable than nested ifelse, it would work for dates, which is vexing af if you run into this:
http://stackoverflow.com/questions/6668963/how-to-prevent-ifelse-from-turning-date-objects-into-numeric-objectsIn fact, have it print a warning if you feed it at least one input vector with class Date, suggesting that they specify
force_class = "date.