Skip to content

Commit

Permalink
fix cran bug
Browse files Browse the repository at this point in the history
  • Loading branch information
huizezhang-sherry committed Jul 1, 2024
1 parent b142934 commit cbf819b
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 67 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Language: en-US
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Imports:
cli,
dplyr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ S3method(key,cubble_df)
S3method(key_data,cubble_df)
S3method(key_vars,cubble_df)
S3method(mutate,spatial_cubble_df)
S3method(mutate,temporal_cubble_df)
S3method(print,cubble_df)
S3method(rename,spatial_cubble_df)
S3method(rename,temporal_cubble_df)
Expand Down
24 changes: 16 additions & 8 deletions R/dplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
#' cb_long |> arrange(prcp)
#'
#' # summarise - summarise.spatial_cubble_df, summarise.temporal_cubble_df
#' cb_long |>
#' group_by(first_5 = ifelse(lubridate::day(date) <=5, 1, 2 )) |>
#' cb_long |>
#' group_by(first_5 = ifelse(lubridate::day(date) <=5, 1, 2 )) |>
#' summarise(tmax = mean(tmax))
#' cb_long |>
#' mutate(first_5 = ifelse(lubridate::day(date) <=5, 1, 2)) |>
#' cb_long |>
#' mutate(first_5 = ifelse(lubridate::day(date) <=5, 1, 2)) |>
#' summarise(t = mean(tmax), .by = first_5)
#'
#' # select - select.spatial_cubble_df, select.temporal_cubble_df
Expand Down Expand Up @@ -99,11 +99,10 @@
#' # group_by & ungroup -
#' (res <- cb_nested |> mutate(group1 = c(1, 1, 2)) |> group_by(group1))
#' res |> ungroup()
#' (res2 <- res |> face_temporal() |> unfold(group1) |> group_by(group1))
#' (res2 <- res |> face_temporal())
#' res2 |> ungroup()
#' res2 |> mutate(first_5 = ifelse(lubridate::day(date) <= 5, 1, 6)) |>
#' group_by(first_5) |>
#' ungroup(group1)
#' res2 |> mutate(first_5 = ifelse(lubridate::day(date) <= 5, 1, 6)) |>
#' group_by(first_5)
arrange.temporal_cubble_df <- function(.data, ...){
out <- NextMethod()
dplyr_reconstruct(out, .data)
Expand Down Expand Up @@ -427,6 +426,15 @@ mutate.spatial_cubble_df <- function(.data, ...){
dplyr_reconstruct(res, data)
}

#' @export
#' @rdname dplyr
mutate.temporal_cubble_df <- function(.data, ...){
data <- .data
class(.data) <- setdiff(class(.data), cb_temporal_cls)
res <- NextMethod()
dplyr_reconstruct(res, data)
}


#' @export
#' @rdname dplyr
Expand Down
5 changes: 2 additions & 3 deletions man/cubble-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions man/dplyr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 53 additions & 14 deletions man/glyph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 27 additions & 25 deletions tests/testthat/_snaps/dplyr.md
Original file line number Diff line number Diff line change
Expand Up @@ -606,24 +606,26 @@
---

Code
(res2 <- group_by(unfold(face_temporal(res), group1), group1))
(res2 <- face_temporal(res))
Message
Adding missing grouping variables: `group1`
Output
# cubble: key: id [3], index: date, long form, groups: group1 [2]
# temporal: 2020-01-01 -- 2020-01-10 [1D], no gaps
# spatial: long [dbl], lat [dbl], elev [dbl], name [chr], wmo_id [dbl], group1
# [dbl]
id date prcp tmax tmin group1
<chr> <date> <dbl> <dbl> <dbl> <dbl>
1 ASN00086038 2020-01-01 0 26.8 11 1
2 ASN00086038 2020-01-02 0 26.3 12.2 1
3 ASN00086038 2020-01-03 0 34.5 12.7 1
4 ASN00086038 2020-01-04 0 29.3 18.8 1
5 ASN00086038 2020-01-05 18 16.1 12.5 1
6 ASN00086038 2020-01-06 104 17.5 11.1 1
7 ASN00086038 2020-01-07 14 20.7 12.1 1
8 ASN00086038 2020-01-08 0 26.4 16.4 1
9 ASN00086038 2020-01-09 0 33.1 17.4 1
10 ASN00086038 2020-01-10 0 34 19.6 1
group1 id date prcp tmax tmin
<dbl> <chr> <date> <dbl> <dbl> <dbl>
1 1 ASN00086038 2020-01-01 0 26.8 11
2 1 ASN00086038 2020-01-02 0 26.3 12.2
3 1 ASN00086038 2020-01-03 0 34.5 12.7
4 1 ASN00086038 2020-01-04 0 29.3 18.8
5 1 ASN00086038 2020-01-05 18 16.1 12.5
6 1 ASN00086038 2020-01-06 104 17.5 11.1
7 1 ASN00086038 2020-01-07 14 20.7 12.1
8 1 ASN00086038 2020-01-08 0 26.4 16.4
9 1 ASN00086038 2020-01-09 0 33.1 17.4
10 1 ASN00086038 2020-01-10 0 34 19.6
# i 20 more rows

---
Expand All @@ -635,17 +637,17 @@
# temporal: 2020-01-01 -- 2020-01-10 [1D], no gaps
# spatial: long [dbl], lat [dbl], elev [dbl], name [chr], wmo_id [dbl], group1
# [dbl]
id date prcp tmax tmin group1
<chr> <date> <dbl> <dbl> <dbl> <dbl>
1 ASN00086038 2020-01-01 0 26.8 11 1
2 ASN00086038 2020-01-02 0 26.3 12.2 1
3 ASN00086038 2020-01-03 0 34.5 12.7 1
4 ASN00086038 2020-01-04 0 29.3 18.8 1
5 ASN00086038 2020-01-05 18 16.1 12.5 1
6 ASN00086038 2020-01-06 104 17.5 11.1 1
7 ASN00086038 2020-01-07 14 20.7 12.1 1
8 ASN00086038 2020-01-08 0 26.4 16.4 1
9 ASN00086038 2020-01-09 0 33.1 17.4 1
10 ASN00086038 2020-01-10 0 34 19.6 1
group1 id date prcp tmax tmin
<dbl> <chr> <date> <dbl> <dbl> <dbl>
1 1 ASN00086038 2020-01-01 0 26.8 11
2 1 ASN00086038 2020-01-02 0 26.3 12.2
3 1 ASN00086038 2020-01-03 0 34.5 12.7
4 1 ASN00086038 2020-01-04 0 29.3 18.8
5 1 ASN00086038 2020-01-05 18 16.1 12.5
6 1 ASN00086038 2020-01-06 104 17.5 11.1
7 1 ASN00086038 2020-01-07 14 20.7 12.1
8 1 ASN00086038 2020-01-08 0 26.4 16.4
9 1 ASN00086038 2020-01-09 0 33.1 17.4
10 1 ASN00086038 2020-01-10 0 34 19.6
# i 20 more rows

16 changes: 16 additions & 0 deletions tests/testthat/_snaps/sf.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,19 @@
2 ASN00086077 145. -38.0 12.1 moora~ 94870 <tibble> (145.0964 -37.98)
3 ASN00086282 145. -37.7 113. melbo~ 94866 <tibble> (144.8321 -37.6655)

---

Code
make_spatial_sf(rename(climate_mel, x = long, y = lat))
Message
CRS missing: using OGC:CRS84 (WGS84) as default
Output
# cubble: key: id [3], index: date, nested form, [sf]
# spatial: [144.8321, -37.98, 145.0964, -37.6655], WGS 84
# temporal: date [date], prcp [dbl], tmax [dbl], tmin [dbl]
id x y elev name wmo_id ts geometry
<chr> <dbl> <dbl> <dbl> <chr> <dbl> <list> <POINT [°]>
1 ASN00086038 145. -37.7 78.4 essen~ 95866 <tibble> (144.9066 -37.7276)
2 ASN00086077 145. -38.0 12.1 moora~ 94870 <tibble> (145.0964 -37.98)
3 ASN00086282 145. -37.7 113. melbo~ 94866 <tibble> (144.8321 -37.6655)

15 changes: 7 additions & 8 deletions tests/testthat/test-dplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ test_that("dplyr verbs work", {

# summarise - summarise.spatial_cubble_df, summarise.temporal_cubble_df
expect_snapshot(
cb_long |>
group_by(first_5 = ifelse(lubridate::day(date) <=5, 1, 2 )) |>
cb_long |>
group_by(first_5 = ifelse(lubridate::day(date) <=5, 1, 2 )) |>
summarise(tmax = mean(tmax))
)
expect_snapshot(
cb_long |>
mutate(first_5 = ifelse(lubridate::day(date) <=5, 1, 2)) |>
cb_long |>
mutate(first_5 = ifelse(lubridate::day(date) <=5, 1, 2)) |>
summarise(t = mean(tmax), .by = first_5)
)

Expand Down Expand Up @@ -77,9 +77,8 @@ test_that("dplyr verbs work", {
# group_by & ungroup -
expect_snapshot((res <- cb_nested |> mutate(group1 = c(1, 1, 2)) |> group_by(group1)))
expect_snapshot(res |> ungroup())
expect_snapshot((res2 <- res |> face_temporal() |> unfold(group1) |> group_by(group1)))
expect_snapshot((res2 <- res |> face_temporal()))
expect_snapshot(res2 |> ungroup())
res2 |> mutate(first_5 = ifelse(lubridate::day(date) <= 5, 1, 6)) |>
group_by(first_5) |>
ungroup(group1)
res2 |> mutate(first_5 = ifelse(lubridate::day(date) <= 5, 1, 6)) |>
group_by(first_5)
})

0 comments on commit cbf819b

Please sign in to comment.