From 9519acec24517366fb99f3c5b582830280e9e9b8 Mon Sep 17 00:00:00 2001 From: huizezhang-sherry Date: Mon, 26 Jun 2023 15:51:43 +1000 Subject: [PATCH] misc small changes --- R/as_cubble.R | 7 ++++--- R/cubble-class.R | 6 ++++-- man/as_cubble.Rd | 5 +++-- man/cubble-class.Rd | 6 ++++-- man/dplyr.Rd | 3 +++ vignettes/cb3tsibblesf.Rmd | 5 ++--- vignettes/cb5match.Rmd | 2 +- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/R/as_cubble.R b/R/as_cubble.R index a43fcf45..7929081c 100644 --- a/R/as_cubble.R +++ b/R/as_cubble.R @@ -1,8 +1,9 @@ #' Coerce foreign objects into a cubble object #' @param ... other arguments. -#' @param data an object to be converted into an cubble object. +#' @param data an object to be converted into an cubble object. Currently +#' support objects of classes `tibble`, `ncdf4`, `stars`, and `sftime`. #' @param key a character (symbol), the spatial identifier, -#' see [cubble::make_cubble()]. +#' see [cubble::make_cubble()] #' @param index a character (symbol), the temporal identifier, #' see [cubble::make_cubble()]. #' @param coords a vector of character (symbol) of length 2, @@ -114,7 +115,7 @@ as_cubble.ncdf4 <- function(data, key, index, coords, vars, # extract variables lat_raw <- extract_longlat(data)$lat long_raw <- extract_longlat(data)$long - time_raw <- extract_time(data) + time_raw <- extract_time(data) %>% as.Date() var <- extract_var(data, vars) lat_idx <- 1:length(lat_raw) long_idx <- 1:length(long_raw) diff --git a/R/cubble-class.R b/R/cubble-class.R index 8b7b372b..e79ceb7b 100644 --- a/R/cubble-class.R +++ b/R/cubble-class.R @@ -2,11 +2,13 @@ #' #' @param ... a set of name-value pairs to create a cubble, need to include the #' `key`, `index`, and `coords` variables. -#' @param key a character (or symbol), the spatial identifier. +#' @param key a character (or symbol), the spatial identifier. See the Key +#' section in [tsibble::as_tsibble()] #' @param index a character (or symbol), the temporal identifier. #' Currently support base R classes \code{Date}, \code{POSIXlt}, #' \code{POSIXct} and tsibble's [tsibble::yearmonth()], [tsibble::yearweek()], -#' and [tsibble::yearquarter()] class. +#' and [tsibble::yearquarter()] class. See the Index section in +#' [tsibble::as_tsibble()] #' @param coords a vector of character (or symbol) of length two, in the order of #' longitude first and then latitude, the argument can be omitted if created #' from an sf and its subclasses. In case the sf geometry column is not POINT, diff --git a/man/as_cubble.Rd b/man/as_cubble.Rd index 2aac8474..716761cb 100644 --- a/man/as_cubble.Rd +++ b/man/as_cubble.Rd @@ -31,10 +31,11 @@ as_cubble(data, key, index, coords, ...) \method{as_cubble}{sftime}(data, key, index, coords, ...) } \arguments{ -\item{data}{an object to be converted into an cubble object.} +\item{data}{an object to be converted into an cubble object. Currently +support objects of classes \code{tibble}, \code{ncdf4}, \code{stars}, and \code{sftime}.} \item{key}{a character (symbol), the spatial identifier, -see \code{\link[=make_cubble]{make_cubble()}}.} +see \code{\link[=make_cubble]{make_cubble()}}} \item{index}{a character (symbol), the temporal identifier, see \code{\link[=make_cubble]{make_cubble()}}.} diff --git a/man/cubble-class.Rd b/man/cubble-class.Rd index 51e02650..8bc40480 100644 --- a/man/cubble-class.Rd +++ b/man/cubble-class.Rd @@ -13,12 +13,14 @@ make_cubble(spatial, temporal, by = NULL, key, index, coords) \item{...}{a set of name-value pairs to create a cubble, need to include the \code{key}, \code{index}, and \code{coords} variables.} -\item{key}{a character (or symbol), the spatial identifier.} +\item{key}{a character (or symbol), the spatial identifier. See the Key +section in \code{\link[tsibble:as-tsibble]{tsibble::as_tsibble()}}} \item{index}{a character (or symbol), the temporal identifier. Currently support base R classes \code{Date}, \code{POSIXlt}, \code{POSIXct} and tsibble's \code{\link[tsibble:year-month]{tsibble::yearmonth()}}, \code{\link[tsibble:year-week]{tsibble::yearweek()}}, -and \code{\link[tsibble:year-quarter]{tsibble::yearquarter()}} class.} +and \code{\link[tsibble:year-quarter]{tsibble::yearquarter()}} class. See the Index section in +\code{\link[tsibble:as-tsibble]{tsibble::as_tsibble()}}} \item{coords}{a vector of character (or symbol) of length two, in the order of longitude first and then latitude, the argument can be omitted if created diff --git a/man/dplyr.Rd b/man/dplyr.Rd index cf803b55..214e81ad 100644 --- a/man/dplyr.Rd +++ b/man/dplyr.Rd @@ -13,6 +13,7 @@ \alias{rename.spatial_cubble_df} \alias{rename.temporal_cubble_df} \alias{bind_rows.temporal_cubble_df} +\alias{bind_rows.spatial_cubble_df} \alias{bind_cols.spatial_cubble_df} \alias{bind_cols.temporal_cubble_df} \alias{rowwise.spatial_cubble_df} @@ -51,6 +52,8 @@ bind_rows.temporal_cubble_df(..., .id = NULL) +bind_rows.spatial_cubble_df(..., .id = NULL) + bind_cols.spatial_cubble_df(..., .name_repair) bind_cols.temporal_cubble_df(..., .name_repair) diff --git a/vignettes/cb3tsibblesf.Rmd b/vignettes/cb3tsibblesf.Rmd index 79225657..dfcad349 100644 --- a/vignettes/cb3tsibblesf.Rmd +++ b/vignettes/cb3tsibblesf.Rmd @@ -72,11 +72,10 @@ sf_nested %>% sf::st_transform(crs = "EPSG:3857") The counterpart to promote the spatial component in an existing cubble to be an sf object is `make_spatial_sf()`: ```{r echo = TRUE} -sf_nested2 <- make_cubble( +(sf_nested2 <- make_cubble( stations, meteo, key = id, index = date, coords = c(long, lat)) %>% - make_spatial_sf() -all.equal(sf_nested2, sf_nested) + make_spatial_sf()) ``` # Reference diff --git a/vignettes/cb5match.Rmd b/vignettes/cb5match.Rmd index 600f1cd1..6104e1be 100644 --- a/vignettes/cb5match.Rmd +++ b/vignettes/cb5match.Rmd @@ -24,7 +24,7 @@ library(patchwork) One common task when working with spatio-temporal data is to match nearby sites. For example, we may want to verify the location of an old list of stations with current stations, or we may want to match the data from different data sources. In this vignette, we will introduce the spatial and temporal matching in cubble using an example on matching river level data with precipitation in Victoria, Australia. -In cubble, spatial and tmeporal matching are performed using the functions `match_spatial()` and `match_temporal()`. The `match_spatial()` function calculates the spatial distance between observations in two cubble objects. Various distance measures are available (check `sf::st_distance`). Analysts can specify the number of matched groups to output using the `spatial_n_group` argument (default to 4 groups) and the number of matches per group using the `spatial_n_group`argument (default to 1, one-to-one matching). The syntax to use `match_spatial()` is: +In cubble, spatial and temporal matching are performed using the functions `match_spatial()` and `match_temporal()`. The `match_spatial()` function calculates the spatial distance between observations in two cubble objects. Various distance measures are available (check `sf::st_distance`). Analysts can specify the number of matched groups to output using the `spatial_n_group` argument (default to 4 groups) and the number of matches per group using the `spatial_n_group` argument (default to 1, one-to-one matching). The syntax to use `match_spatial()` is: ```` match_spatial(, , ...)