I wonder: Why does removing the index from a tsibble fail silently instead of giving an error? I just had a case where the error would have helped my debugging.
See this code:
library(tsibble)
ts <- tsibble(
Time = seq(as.Date("2020-01-01"), by = "1 months", length.out = 3),
Series1 = c(3, 1, 2), index = Time
)
print(ts)
library(dplyr)
ts_sel <- select(ts, -Time)
print(ts_sel)
with output
# A tsibble: 3 x 2 [1D]
Time Series1
<date> <dbl>
1 2020-01-01 3
2 2020-02-01 1
3 2020-03-01 2
# A tsibble: 3 x 2 [1D]
Series1 Time
<dbl> <date>
1 3 2020-01-01
2 1 2020-02-01
3 2 2020-03-01
I think it's because it didn't fail: It seems a tsibble requires an index column, so Time continues to be an index column until it's been replaced by another index column. This is in keeping with the principle that subsetting an object should produce a subobject (i.e., an object of the same type), so that any subsetting of a tsibble leaves the index column intact.
I don't know if you've tried the debug() function, but if you run debug(select) and then run your code, you can walk through how select() works in this context. (Use n to step over statements and s to step into statements.) After you're done, make sure to run undebug(select) so that you don't go into debug mode the next time you run select().
If you do this, you can see that there's a hidden function called bind_tsibble() that explicitly passes on the index column as the last column if it there's an attempt to remove it with select().