Learn R Programming

ohvbd (version 1.0.0)

assoc_ad: Associate other data sources with AREAdata data

Description

Intelligently bind together data from AREAdata and other sources at a given spatial scale.

Usage

assoc_ad(
  data,
  areadata,
  targetdate = NA,
  enddate = NA,
  gid = 0,
  lonlat_names = c("Longitude", "Latitude"),
  cache_location = NULL,
  basereq = ad_basereq()
)

Value

A matrix of the data with added columns extracted from areadata.

Arguments

data

the source data to bind AREAdata to. This must contain decimal lonlat data!

areadata

the AREAdata to bind, usually from fetch_ad().

targetdate

ONE OF the following:

  • The date to search for in ISO 8601 (e.g. "2020", "2021-09", or "2022-09-21").

  • The start date for a range of dates.

  • A character vector of fully specified dates to search for (i.e. "yyyy-mm-dd").

enddate

The (exclusive) end of the range of dates to search for. If this is unfilled, only the targetdate is searched for.

gid

the spatial scale to retrieve (0 = country-level, 1=province-level...). (Note: this will preferentially use the gid level of areadata if present.)

lonlat_names

a vector containing the column names of the longitude and latitude columns IN THAT ORDER!

cache_location

path to cache location (defaults to a temporary user directory, or one set by set_default_ohvbd_cache()).

basereq

the url of the AREAdata database (usually generated by ad_basereq()). If NA, uses the default.

Date ranges

The date range is a partially open interval. That is to say the lower bound (targetdate) is inclusive, but the upper bound (enddate) is exclusive.

For example a date range of "2020-08-04" - "2020-08-12" will return the 7 days from the 4th through to the 11th of August, but not the 12th.

Date inference

In cases where a full date is not provided, the earliest date possible with the available data is chosen.

So "2020-04" will internally become "2020-04-01".

If an incomplete date is specified as the targetdate and no enddate is specified, the range to search is inferred from the minimum temporal scale provided in targetdate.

For example "2020-04" will be taken to mean the month of April in 2020, and the enddate will internally be set to "2020-05-01".

Author

Francis Windram

Examples

Run this code
if (FALSE) { # interactive()
vtdf <- search_hub("Aedes aegypti", "vt") |>
  tail(20) |>
  fetch() |>
  glean(cols = c(
    "DatasetID",
    "Latitude",
    "Longitude",
    "Interactor1Genus",
    "Interactor1Species"
    ), returnunique = TRUE)
areadata <- fetch_ad(metric="temp", gid=2, use_cache=TRUE)
ad_extract_working <- assoc_ad(vtdf, areadata,
                                    targetdate = c("2021-08-04"), enddate=c("2021-08-06"),
                                    gid=2, lonlat_names = c("Longitude", "Latitude"))
}

Run the code above in your browser using DataLab