SeriesAggreg fails on `tibble` format
> library(airGR)
> data(L0123001)
> str(SeriesAggreg(BasinObs[, 1:2], "%Y%m", ConvertFun = "sum"))
'data.frame': 348 obs. of 2 variables:
$ DatesR: POSIXct, format: "1984-01-01" "1984-02-01" "1984-03-01" "1984-04-01" ...
$ P : num 78.8 85.6 47.4 71.7 77.4 ...
> tibP <- tibble::as_tibble(BasinObs[, 1:2])
> str(SeriesAggreg(tibP, "%Y%m", ConvertFun = "sum"))
tibble [10,593 × 2] (S3: tbl_df/tbl/data.frame)
$ DatesR: POSIXct[1:10593], format: "1984-01-01" "1984-01-02" "1984-01-03" "1984-01-04" ...
$ P : num [1:10593] 4.1 15.9 0.8 0 0 0 0 0 2.9 0 ...
Message d'avis :
Dans SeriesAggreg.data.frame(tibP, "%Y%m", ConvertFun = "sum") :
the requested time 'Format' is the same as the one in 'x'. No time-step conversion was performed
SeriesAggreg
doesn't stop with error but only warns and return a wrong output which is a bit more difficult to take care of...
tibble
is a format which inherits from data.frame
with more restriction. One of these restriction is that a selection on a tibble
returns a tibble
by default whereas a data.frame
selection returns a vector if you select a single column. This behavior is handled by the parameter drop
:
> str(cars[1:5,1])
num [1:5] 4 4 7 7 8
> str(tibble::as_tibble(cars)[1:5,1])
tibble [5 × 1] (S3: tbl_df/tbl/data.frame)
$ speed: num [1:5] 4 4 7 7 8
> str(tibble::as_tibble(cars)[1:5, 1, drop = TRUE])
num [1:5] 4 4 7 7 8
Line 107 of R\SeriesAggreg.data.frame.R
: a drop = TRUE
is missing in unitTs <- format(diff(x[1:2, 1]))
Moreover, it is not robust to trust the else
operator in line 113, we should check everytime the pattern returned by unitTs
.