tidyverts / tsibble

Tidy Temporal Data Frames and Tools
https://tsibble.tidyverts.org
GNU General Public License v3.0
530 stars 49 forks source link

Naming Conflict in as_tsibble() Results in Unsupported Index Error #284

Closed jimmyrigby94 closed 1 year ago

jimmyrigby94 commented 2 years ago
Details

When a data frame is passed to as_tsibble() with a column named index the object conversion fails.


Consider the following example, where the grouping variable is stored as "index", the time variable stored as "qtr", and the time series value named "value".

tbl2 <- tibble(
    qtr = rep(yearquarter("2010 Q1") + 0:9, 3),
    index = rep(c("x", "y", "z"), each = 10),
    value = rnorm(30)
)

as_tsibble(tbl2, key = index, index = qtr)

Results:

Error in `validate_index()`:
! Unsupported index type: character

Eliminating naming conflicts with specials fixes the error.

tbl2_conf <- tbl2%>%
      rename(grp = index)

as_tsibble(tbl2_conf , key = grp, index = qtr)
earowang commented 1 year ago

Thanks for reporting the issue and providing a reproducible example. Fixed.