Open joshuaulrich opened 3 months ago
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.
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.