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

Convert xts indexes to Date #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joshuaulrich
Copy link

The xts objects are daily, but have a POSIXct index without a timezone. That means behavior will depend on the user's system timezone settings. Convert the index to Date to avoid this potential issue.

Also remove old index attributes from the xts object, and update the attributes on the index. This doesn't affect behavior, but ensures the xts objects are consistent with the current structure.

The xts objects are daily, but have a POSIXct index without a timezone.
That means behavior will depend on the user's system timezone settings.
Convert the index to Date to avoid this potential issue.

Also remove old index attributes from the xts object, and update the
attributes on the index.
@joshuaulrich
Copy link
Author

joshuaulrich commented Jun 5, 2024

The structure of these xts objects caused the example below to fail for me because my system timezone is America/Chicago. The first observation in Sub36_obs is NA and that first observation is the only observation in the week for my timezone, so the result of which.max() on that subset is an empty xts object (no rows or columns).

library(RavenR)
data(rvn_hydrograph_data)
rvn_apply_wyearly(rvn_hydrograph_data$hyd$Sub43_obs, rvn_which_max_xts)
## Error in `colnames<-`(`*tmp*`, value = colnames(x)) : 
##   attempt to set 'colnames' on an object with less than two dimensions
## Calls: rvn_apply_wyearly ... period.apply -> sapply -> lapply -> FUN -> FUN -> colnames<-

The example failure causes R CMD check to fail for me during my xts reverse dependency checks. Note that the example works on CRAN checks because their timezone is Europe/Berlin, so this isn't urgent to fix.

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

Successfully merging this pull request may close these issues.

1 participant