-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create 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-objects
In 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
.The text was updated successfully, but these errors were encountered: