Skip to content
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

use_first_valid_of leaves POSIX variables as numerics #71

Closed
sfirke opened this issue Oct 11, 2016 · 3 comments
Closed

use_first_valid_of leaves POSIX variables as numerics #71

sfirke opened this issue Oct 11, 2016 · 3 comments

Comments

@sfirke
Copy link
Owner

sfirke commented Oct 11, 2016

dat <- data.frame(a = c(as.POSIXct(as.Date("2006-12-12")), as.POSIXct(as.Date("2005-01-05"))))
dat$b <- dat$a + 1
use_first_valid_of(dat$a, dat$b)
[1] 1165881600 1104883200
Warning messages:
1: In if (class(vars[[1]]) == "factor") { :
  the condition has length > 1 and only the first element will be used
2: In if (class(vars[[1]]) == "Date") { :
  the condition has length > 1 and only the first element will be used

Right now it sets the result vector to class Date if inputs are Date which is insufficient. Can it just set to whatever the resulting class should be?

@sfirke
Copy link
Owner Author

sfirke commented Oct 11, 2016

That error message indicates a separate problem: some variables have multiple classes, like POSIXct and POSIXt, so saying class(x) == "factor" causes that error message above. Will also address that here by making the condition if(sum(class(vars[[1]]) %in% "factor") > 0).

@sfirke
Copy link
Owner Author

sfirke commented Oct 11, 2016

Turns out dplyr does not support POSIXlt variables.

@sfirke
Copy link
Owner Author

sfirke commented Oct 12, 2016

Ended up being a trickier fix than I thought. It didn't occur to me that POSIXlt is a list, not a vector, so it wasn't stored correctly in the nested for-loops and I was getting the not-helpful message $ operator is invalid for atomic vectors. Good thing I wrote POSIXlt unit tests when I wrote the POSIXct ones that covered my immediate problem :)

@sfirke sfirke closed this as completed in aa3671a Oct 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant