Giter Club home page Giter Club logo

cubble's People

Contributors

dicook avatar edzer avatar hadley avatar huizezhang-sherry avatar loreabad6 avatar olivroy avatar schloerke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cubble's Issues

should these functions be options to geom_glyph rather than separate?

geom_glyph_box() and geom_glyph_line() both might be better to be optional arguments on the geom_glyph() function, so the user doesn't need to specify the data and aes for each separate line. For example,

ggplot() +
geom_polygon(data=sth_america,
aes(x=long, y=lat, group=group),
fill="grey70") +
geom_glyph(data=nasa, aes(x_major = long, x_minor = day,
y_major = lat, y_minor = ozone)) +
geom_glyph_box(data=nasa, aes(x_major = long, x_minor = day,
y_major = lat, y_minor = ozone)) +
geom_glyph_line(data=nasa, aes(x_major = long, x_minor = day,
y_major = lat, y_minor = ozone)) +
coord_map() +
theme_map()

Release plans

Hi

I'm in the process of updating ggforce on CRAN and my reverse dependency checks shows an issue with the CRAN version of cubble (it doesn't suggest concaveman). This seems to be fixed already on GitHub so this is mostly an inquiry on when you plan to release the next version of cubble to CRAN?

with best wishes
Thomas

`unfold()` does not work for coords/columns called "x"

Hi Sherry,

I have been playing with the package lately, it is really a great implementation and I am looking forward to contributing to it as much as possible, so consider this my first step πŸ˜€

I am working with projected data, which when creating a cubble_df result in the columns "x" and "y" as the "coords". However, when using unfold() I get an error for the column called "x".

I traced it back to this line in new_temporal_cubble() when assigning the classes. The backtrace leads me to tsibble:::validate_index(tbl, !!qindex) but that is as far as I got.

Here is a reproducible example:

library(cubble)
library(dplyr)

climate_mel |>
  rename(x = long, y = lat) |> 
  face_temporal() |> 
  unfold(x)
#> Error in `validate_index()`:
#> ! Problem while evaluating `index(x)`.
#> Caused by error in `sym()`:
#> ! Can't convert `NULL` to a symbol.
#> ---
#> Backtrace:
#>      β–†
#>  1. β”œβ”€base (local) `<fn>`(x)
#>  2. β”œβ”€cubble:::print.cubble_df(x)
#>  3. β”‚ β”œβ”€base::writeLines(format(x, width = width, ...))
#>  4. β”‚ β”œβ”€base::format(x, width = width, ...)
#>  5. β”‚ └─pillar:::format.tbl(x, width = width, ...)
#>  6. β”‚   └─pillar:::format_tbl(...)
#>  7. β”‚     └─pillar::tbl_format_setup(...)
#>  8. β”‚       β”œβ”€pillar:::tbl_format_setup_dispatch(...)
#>  9. β”‚       └─pillar:::tbl_format_setup.tbl(...)
#> 10. β”‚         β”œβ”€pillar::tbl_sum(x)
#> 11. β”‚         └─cubble:::tbl_sum.temporal_cubble_df(x)
#> 12. β”‚           β”œβ”€tsibble::as_tsibble(as_tibble(x), key = key_vars(x), index = index(x))
#> 13. β”‚           └─tsibble:::as_tsibble.tbl_df(...)
#> 14. β”‚             └─tsibble::build_tsibble(...)
#> 15. β”‚               └─tsibble:::validate_index(tbl, !!qindex)
#> 16. β”‚                 └─tidyselect::vars_pull(names, !!index)
#> 17. β”‚                   β”œβ”€tidyselect:::with_chained_errors(...)
#> 18. β”‚                   β”‚ └─rlang::try_fetch(...)
#> 19. β”‚                   β”‚   β”œβ”€base::tryCatch(...)
#> 20. β”‚                   β”‚   β”‚ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 21. β”‚                   β”‚   β”‚   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 22. β”‚                   β”‚   β”‚     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 23. β”‚                   β”‚   └─base::withCallingHandlers(...)
#> 24. β”‚                   └─rlang::eval_tidy(expr, set_names(seq_along(vars), vars))
#> 25. └─cubble::index(x)
#> 26.   └─rlang::sym(index_var(data))

When trying for "y" or even when calling the coordinates "X" and "Y" (capital letters) then everythinh works.

climate_mel |>
  rename(x = long, y = lat) |> 
  face_temporal() |> 
  unfold(y)
#> # 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     y
#>    <chr>       <date>     <dbl> <dbl> <dbl> <dbl>
#>  1 ASN00086038 2020-01-01     0  26.8  11   -37.7
#>  2 ASN00086038 2020-01-02     0  26.3  12.2 -37.7
#>  3 ASN00086038 2020-01-03     0  34.5  12.7 -37.7
#>  4 ASN00086038 2020-01-04     0  29.3  18.8 -37.7
#>  5 ASN00086038 2020-01-05    18  16.1  12.5 -37.7
#>  6 ASN00086038 2020-01-06   104  17.5  11.1 -37.7
#>  7 ASN00086038 2020-01-07    14  20.7  12.1 -37.7
#>  8 ASN00086038 2020-01-08     0  26.4  16.4 -37.7
#>  9 ASN00086038 2020-01-09     0  33.1  17.4 -37.7
#> 10 ASN00086038 2020-01-10     0  34    19.6 -37.7
#> # β„Ή 20 more rows

climate_mel |>
  rename(X = long, Y = lat) |> 
  face_temporal() |> 
  unfold(X, Y)
#> # 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     Y
#>    <chr>       <date>     <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1 ASN00086038 2020-01-01     0  26.8  11    145. -37.7
#>  2 ASN00086038 2020-01-02     0  26.3  12.2  145. -37.7
#>  3 ASN00086038 2020-01-03     0  34.5  12.7  145. -37.7
#>  4 ASN00086038 2020-01-04     0  29.3  18.8  145. -37.7
#>  5 ASN00086038 2020-01-05    18  16.1  12.5  145. -37.7
#>  6 ASN00086038 2020-01-06   104  17.5  11.1  145. -37.7
#>  7 ASN00086038 2020-01-07    14  20.7  12.1  145. -37.7
#>  8 ASN00086038 2020-01-08     0  26.4  16.4  145. -37.7
#>  9 ASN00086038 2020-01-09     0  33.1  17.4  145. -37.7
#> 10 ASN00086038 2020-01-10     0  34    19.6  145. -37.7
#> # β„Ή 20 more rows

Release cubble 0.2.0

Prepare for release:

  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • Review pkgdown reference index for, e.g., missing topics
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted πŸŽ‰
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

Why does the cubble lose it's geometry here

covid <- read_csv("https://raw.githubusercontent.com/numbats/eda/master/data/melb_lga_covid.csv") %>%
  mutate(Buloke = as.numeric(ifelse(Buloke == "null", "0", Buloke))) %>%
   mutate(Hindmarsh = as.numeric(ifelse(Hindmarsh == "null", "0", Hindmarsh))) %>%
   mutate(Towong = as.numeric(ifelse(Towong == "null", "0", Towong))) %>%
  pivot_longer(cols = Alpine:Yarriambiack, names_to="NAME", values_to="cases") %>%
  mutate(Date = ydm(paste0("2020/",Date))) %>%
  mutate(cases=replace_na(cases, 0))

covid <- covid %>%
  group_by(NAME) %>%
  mutate(new_cases = cases - dplyr::lag(cases)) %>%
  na.omit()

lga <- strayr::read_absmap("lga2018") |>
  rename(lga = lga_name_2018) |>
  filter(state_name_2016 == "Victoria") 

covid <- covid %>%
  select(-cases) %>%
  rename(lga = NAME, date=Date, cases = new_cases) 
covid_ts <- as_tsibble(covid, key=lga, index=date)

covid_matching <- check_key(spatial = lga, temporal = covid_ts)

lga <- lga %>% 
  mutate(lga = ifelse(lga == "Colac-Otway (S)", "Colac Otway (S)", lga)) %>%
  filter(!(lga %in% covid_matching$others$spatial))

covid_matching <- check_key(spatial = lga, temporal = covid_ts)

covid_cb <- make_cubble(
  spatial = lga, temporal = covid_ts,
  potential_match = covid_matching, index = date)

covid_tot <- covid_cb %>%
  face_temporal() %>%
  summarise(totcases = sum(cases, na.rm = TRUE))

> covid_tot
# A tibble: 79 Γ— 2
   lga            totcases
   <chr>             <dbl>
 1 Alpine (S)            0
 2 Ararat (RC)           2
 3 Ballarat (C)         46
 4 Banyule (C)         350
....

Error on mismatched sizes in making a cubble

library(tidyverse)
library(tsibble)
library(cubble)
library(ozmaps)

# Read and handle missing
covid <- read_csv("https://raw.githubusercontent.com/numbats/eda/master/data/melb_lga_covid.csv") %>%
  mutate(Buloke = as.numeric(ifelse(Buloke == "null", "0", Buloke))) %>%
  mutate(Hindmarsh = as.numeric(ifelse(Hindmarsh == "null", "0", Hindmarsh))) %>%
   mutate(Towong = as.numeric(ifelse(Towong == "null", "0", Towong))) %>%
  pivot_longer(cols = Alpine:Yarriambiack, names_to="NAME", values_to="cases") %>%
  mutate(Date = ydm(paste0("2020/",Date))) %>%
  mutate(cases=replace_na(cases, 0))

# Create a tsibble
covid_ts <- as_tsibble(covid, key=NAME, index=Date)

# Get spatial polygons from ozmaps
data("abs_lga")

# Create cubble
covid_cb <- as_cubble(
  list(spatial = abs_lga, temporal = covid_ts),
  key = NAME, index = Date, 
  output = "unmatch")

gives the following error:

Error:
! Tibble columns must have compatible sizes.
β€’ Size 84: Existing data.
β€’ Size 78: Column `temporal`.
β„Ή Only values of size one are recycled.
Run `rlang::last_error()` to see where the error occurred.

All the time series are of the same length according to my check.

Release cubble 0.3.0

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Check if any deprecation processes should be advanced, as described in Gradual deprecation
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted πŸŽ‰
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

Should `add_geometry_column()` add a subclass `sf` to a `cubble_df` object?

Hi @huizezhang-sherry and @edzer,

currently, add_geometry_column() does not add the sf subclass to the cubble_df object. Is this desired behavior?

It may cause somewhat unintuitive things like:

library(cubble)
library(sf)
#> Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(tibble)
library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.2.2
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

# create cubble_df from an sf object and a tibble
stations_sf <- 
  cubble::climate_subset |> 
  dplyr::select(-ts) |>
  sf::st_as_sf(coords = c("long", "lat"), crs = 4283, remove = FALSE)

ts <- 
  cubble::climate_aus |>
  cubble::face_temporal() |>
  tibble::as_tibble() |>
  dplyr::filter(id %in% stations_sf$id)

weather1 <- 
  cubble::as_cubble(
    list(spatial = stations_sf, temporal = ts),
    key = id, index = date, coords = c(long, lat)
  )

class(weather1)
#> [1] "cubble_df"  "sf"         "rowwise_df" "tbl_df"     "tbl"       
#> [6] "data.frame"

# create a cubble object without sf and use `add_geometry_column()`
weather2 <- 
  cubble::climate_subset |>
  cubble::add_geometry_column()
#> CRS missing: using OGC:CRS84 (WGS84) as default

class(weather2)
#> [1] "cubble_df"  "rowwise_df" "tbl_df"     "tbl"        "data.frame"

Created on 2023-05-03 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.0 (2022-04-22 ucrt)
#>  os       Windows 10 x64 (build 22621)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  German_Germany.utf8
#>  ctype    German_Germany.utf8
#>  tz       Europe/Berlin
#>  date     2023-05-03
#>  pandoc   2.19.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  anytime       0.3.9   2020-08-27 [1] CRAN (R 4.2.3)
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.2.1)
#>  class         7.3-20  2022-01-16 [2] CRAN (R 4.2.0)
#>  classInt      0.4-3   2020-04-07 [1] CRAN (R 4.2.0)
#>  cli           3.4.1   2022-09-23 [1] CRAN (R 4.2.1)
#>  crayon        1.5.1   2022-03-26 [1] CRAN (R 4.2.0)
#>  cubble      * 0.2.1   2023-05-03 [1] Github (huizezhang-sherry/cubble@d6610f4)
#>  DBI           1.1.2   2021-12-20 [1] CRAN (R 4.2.0)
#>  digest        0.6.29  2021-12-01 [1] CRAN (R 4.2.0)
#>  dplyr       * 1.0.10  2022-09-01 [1] CRAN (R 4.2.2)
#>  e1071         1.7-9   2021-09-16 [1] CRAN (R 4.2.0)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.2.0)
#>  evaluate      0.15    2022-02-18 [1] CRAN (R 4.2.0)
#>  fansi         1.0.3   2022-03-24 [1] CRAN (R 4.2.0)
#>  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.2.0)
#>  fs            1.5.2   2021-12-08 [1] CRAN (R 4.2.0)
#>  generics      0.1.2   2022-01-31 [1] CRAN (R 4.2.0)
#>  geosphere     1.5-18  2022-11-15 [1] CRAN (R 4.2.3)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.2.0)
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.2.0)
#>  htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.2.0)
#>  KernSmooth    2.23-20 2021-05-03 [2] CRAN (R 4.2.0)
#>  knitr         1.39    2022-04-26 [1] CRAN (R 4.2.0)
#>  lattice       0.20-45 2021-09-22 [1] CRAN (R 4.2.0)
#>  lifecycle     1.0.3   2022-10-07 [1] CRAN (R 4.2.2)
#>  lubridate     1.8.0   2021-10-07 [1] CRAN (R 4.2.0)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.2.0)
#>  ncdf4         1.21    2023-01-07 [1] CRAN (R 4.2.2)
#>  pillar        1.7.0   2022-02-01 [1] CRAN (R 4.2.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.2.0)
#>  proxy         0.4-26  2021-06-07 [1] CRAN (R 4.2.0)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.2.0)
#>  R.cache       0.15.0  2021-04-30 [1] CRAN (R 4.2.0)
#>  R.methodsS3   1.8.1   2020-08-26 [1] CRAN (R 4.2.0)
#>  R.oo          1.24.0  2020-08-26 [1] CRAN (R 4.2.0)
#>  R.utils       2.11.0  2021-09-26 [1] CRAN (R 4.2.0)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.2.0)
#>  Rcpp          1.0.8.3 2022-03-17 [1] CRAN (R 4.2.0)
#>  reprex        2.0.1   2021-08-05 [1] CRAN (R 4.2.0)
#>  rlang         1.0.6   2022-09-24 [1] CRAN (R 4.2.1)
#>  rmarkdown     2.14    2022-04-25 [1] CRAN (R 4.2.0)
#>  rstudioapi    0.14    2022-08-22 [1] CRAN (R 4.2.1)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.0)
#>  sf          * 1.0-10  2022-12-07 [1] Github (r-spatial/sf@9534e4a)
#>  sp            1.5-0   2022-06-12 [1] Github (edzer/sp@cfe9cdb)
#>  stringi       1.7.6   2021-11-29 [1] CRAN (R 4.2.0)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.2.0)
#>  styler        1.7.0   2022-03-13 [1] CRAN (R 4.2.0)
#>  tibble      * 3.1.7   2022-05-03 [1] CRAN (R 4.2.0)
#>  tidyr         1.2.0   2022-02-01 [1] CRAN (R 4.2.0)
#>  tidyselect    1.2.0   2022-10-10 [1] CRAN (R 4.2.2)
#>  tsibble       1.1.3   2022-10-09 [1] CRAN (R 4.2.3)
#>  units         0.8-1   2022-12-10 [1] CRAN (R 4.2.3)
#>  utf8          1.2.2   2021-07-24 [1] CRAN (R 4.2.0)
#>  vctrs         0.5.1   2022-11-16 [1] CRAN (R 4.2.2)
#>  withr         2.5.0   2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun          0.30    2022-03-02 [1] CRAN (R 4.2.0)
#>  yaml          2.3.5   2022-02-21 [1] CRAN (R 4.2.0)
#> 
#>  [1] C:/Users/henni/AppData/Local/R/win-library/4.2
#>  [2] C:/Program Files/R/R-4.2.0/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Need range01 function

In converting from

temp.gly <- glyphs(nasa, "long", "day", "lat",
                   "ozone", height=2.5, 
                   y_scale = range01, polar = TRUE)
ggplot(temp.gly, ggplot2::aes(gx, gy, group = gid)) +
  geom_polygon(data=sth_america, 
            aes(x=long, y=lat, group=group), 
            fill="grey70") +
  add_ref_lines(temp.gly, color = "grey90") +
  add_ref_boxes(temp.gly, color = "grey90") +
  geom_path() +
  labs(x = "", y = "") +
  coord_map() +
  theme_map()  

to

ggplot() +
  geom_polygon(data=sth_america, 
           aes(x=long, y=lat, group=group), 
          fill="#014221", alpha=0.5, colour="#ffffff") +
  geom_glyph_box(data=nasa, aes(x_major = long, x_minor = day,
            y_major = lat, y_minor = ozone), fill=NA) +
  geom_glyph_line(data=nasa, aes(x_major = long, x_minor = day,
            y_major = lat, y_minor = ozone)) +
  geom_glyph(data=nasa, aes(x_major = long, x_minor = day,
            y_major = lat, y_minor = ozone), 
            y_scale = range01, polar = TRUE) +
  theme_map()

will throw an error. cubble is missing the range01 function, that will scale each spatial location data to range between 0 and 1, necessary to make polar glyphs with local scale.

Suggested improvements for add_missing_prct()

exprs <- expr(...)

This code assumes that ... is of length 1 (since expr() only accepts one argument).
Instead, you can introduce a new argument for the function cols which supports tidyselect (much like tidyr::pivot_longer() and others), then capture the inputted expression with rlang::enexpr(cols).

Alternatively, you could probably directly use tidyselect::eval_select({{cols}}, face_temporal(data)). Note that I've removed the pipe as it complicates the evaluation environment and is a slight slow down.

calls <- map(names(vars), ~quo(sum(is.na(ts[[.x]]))/length(ts[[.x]])))

Using quo() here is capturing the environment of your mapped function, and the contents of the add_missing_prct() environment. Since you just want to evaluate elements from your data, it is simpler to use expr() here.

out <- data %>% mutate(missing = list(map(calls, ~eval(.x)))) %>% tidyr::unnest_wider(missing)

Since you have a list of expressions (or quosures) you can apply them across multiple function arguments with !!!, avoiding the conflict with variable name missing and the need to unnest_wider().

cubble coerced from raster `stars` object does not inherit CRS

Raster data cubes do not inherit the CRS when coerced to cubble. This is because the cubble creation is extracting the coordinate values as integers, losing the geometry here.

library(stars)
library(cubble)
tif = system.file("tif/L7_ETMs.tif", package = "stars")
(x =  stars::read_stars(tif))
#> stars object with 3 dimensions and 1 attribute
#> attribute(s):
#>              Min. 1st Qu. Median     Mean 3rd Qu. Max.
#> L7_ETMs.tif     1      54     69 68.91242      86  255
#> dimension(s):
#>      from  to  offset delta                     refsys point x/y
#> x       1 349  288776  28.5 SIRGAS 2000 / UTM zone 25S FALSE [x]
#> y       1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y]
#> band    1   6      NA    NA                         NA    NA
(t = x |> as_cubble())
#> β„Ή More than 10,000 keys: only use the first key to test spatial &
#> temporal variables.
#> # cubble:   key: id [122848], index: time, nested form
#> # spatial:  [288790.500000803, 9110743.00002899, 298708.50000055,
#> #   9120746.50002874], Missing CRS!
#> # temporal: band [int], L7_ETMs.tif [dbl]
#>          x        y     id ts              
#>      <dbl>    <dbl>  <int> <list>          
#>  1 288791. 9120747. 122500 <tibble [6 Γ— 2]>
#>  2 288819. 9120747. 122501 <tibble [6 Γ— 2]>
#>  3 288848. 9120747. 122502 <tibble [6 Γ— 2]>
#>  4 288876. 9120747. 122503 <tibble [6 Γ— 2]>
#>  5 288905. 9120747. 122504 <tibble [6 Γ— 2]>
#>  6 288933. 9120747. 122505 <tibble [6 Γ— 2]>
#>  7 288962. 9120747. 122506 <tibble [6 Γ— 2]>
#>  8 288990. 9120747. 122507 <tibble [6 Γ— 2]>
#>  9 289019. 9120747. 122508 <tibble [6 Γ— 2]>
#> 10 289047. 9120747. 122509 <tibble [6 Γ— 2]>
#> # β„Ή 122,838 more rows

One option would be to coerce the tibble to sf before coercing to cubble before line 192, to recover the CRS:

    as_tibble(data) |>
      mutate(id = as.integer(interaction(!!sym(longlat[[1]]),
                                         !!sym(longlat[[2]])))) |>
      st_as_sf(crs = st_crs(x), coords = longlat) |>
      as_cubble(key = id, index = time) 

or to add make_spatial_sf() after line 192:

    as_tibble(data) |>
      mutate(id = as.integer(interaction(!!sym(longlat[[1]]),
                                         !!sym(longlat[[2]])))) |>
      as_cubble(key = id, index = time, coords = longlat) |>
      make_spatial_sf(crs = sf::st_crs(data))

But that is not such a fast approach and also adds an extra geometry column that the user might find unexpected. So I am not sure what would be the best approach here.

Recommend keep magrittr pipe

I'd recommend keeping the magrittr pipe %>% (it's part of tibble anyway so won't make difference). The native pipe is only available for R version >=4.1.0 which was only released last year. There are going to be a number of people who won't be able to use it so it's just adding a barrier for people to use your package.

For the automatic matching can we choose which label to use

covid <- read_csv("https://raw.githubusercontent.com/numbats/eda/master/data/melb_lga_covid.csv") %>%
  mutate(Buloke = as.numeric(ifelse(Buloke == "null", "0", Buloke))) %>%
   mutate(Hindmarsh = as.numeric(ifelse(Hindmarsh == "null", "0", Hindmarsh))) %>%
   mutate(Towong = as.numeric(ifelse(Towong == "null", "0", Towong))) %>%
  pivot_longer(cols = Alpine:Yarriambiack, names_to="NAME", values_to="cases") %>%
  mutate(Date = ydm(paste0("2020/",Date))) %>%
  mutate(cases=replace_na(cases, 0))

covid <- covid %>%
  group_by(NAME) %>%
  mutate(new_cases = cases - dplyr::lag(cases)) %>%
  na.omit()

lga <- strayr::read_absmap("lga2018") |>
  rename(lga = lga_name_2018) |>
  filter(state_name_2016 == "Victoria") 

covid <- covid %>%
  select(-cases) %>%
  rename(lga = NAME, date=Date, cases = new_cases) 
covid_ts <- as_tsibble(covid, key=lga, index=date)

covid_matching <- check_key(spatial = lga, temporal = covid_ts)

lga <- lga %>% 
  mutate(lga = ifelse(lga == "Colac-Otway (S)", "Colac Otway (S)", lga)) %>%
  filter(!(lga %in% covid_matching$others$spatial))

covid_matching <- check_key(spatial = lga, temporal = covid_ts)

covid_cb <- make_cubble(
  spatial = lga, temporal = covid_ts,
  potential_match = covid_matching, index = date)

It uses the key from the spatial data, but the temporal one would be better.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.