Skip to content

Convert xts indexes to Date#122

Open
joshuaulrich wants to merge 1 commit intorchlumsk:masterfrom
joshuaulrich:update-xts-data
Open

Convert xts indexes to Date#122
joshuaulrich wants to merge 1 commit intorchlumsk:masterfrom
joshuaulrich:update-xts-data

Conversation

@joshuaulrich
Copy link
Copy Markdown

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
Copy Markdown
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