Skip to content

Commit

Permalink
fix #21
Browse files Browse the repository at this point in the history
  • Loading branch information
huizezhang-sherry committed Jan 2, 2024
1 parent cdab59e commit e0f9765
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/cubble-print.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ tbl_sum.temporal_cubble_df <- function(x){

# line 2: FROM -- TO [BY] HAS_GAP
if (!is_tsibble(x)) {
x_tsibble <- as_tsibble(as_tibble(x), key = key_vars(x), index = index(x))
xx <- x # a wired issue raised in issue 21
x_tsibble <- as_tsibble(as_tibble(x), key = key_vars(x), index = index(xx))
} else{
x_tsibble <- x
}
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/_snaps/cubble-print.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# from issue 21

Code
a
Output
# cubble: key: id [3], index: date, long form
# temporal: 2020-01-01 -- 2020-01-10 [1D], no gaps
# spatial: x [dbl], y [dbl], elev [dbl], name [chr], wmo_id [dbl]
id date prcp tmax tmin x
<chr> <date> <dbl> <dbl> <dbl> <dbl>
1 ASN00086038 2020-01-01 0 26.8 11 145.
2 ASN00086038 2020-01-02 0 26.3 12.2 145.
3 ASN00086038 2020-01-03 0 34.5 12.7 145.
4 ASN00086038 2020-01-04 0 29.3 18.8 145.
5 ASN00086038 2020-01-05 18 16.1 12.5 145.
6 ASN00086038 2020-01-06 104 17.5 11.1 145.
7 ASN00086038 2020-01-07 14 20.7 12.1 145.
8 ASN00086038 2020-01-08 0 26.4 16.4 145.
9 ASN00086038 2020-01-09 0 33.1 17.4 145.
10 ASN00086038 2020-01-10 0 34 19.6 145.
# i 20 more rows

8 changes: 8 additions & 0 deletions tests/testthat/test-cubble-print.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test_that("from issue 21", {
a <- climate_mel |>
rename(x = long, y = lat) |>
face_temporal() |>
unfold(x)

expect_snapshot(a)
})

0 comments on commit e0f9765

Please sign in to comment.