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"),
basereq = NA
)
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...).
- lonlat_names
a vector containing the column names of the longitude and latitude columns IN THAT ORDER!
- basereq
the url of the AREAdata database (usually generated by
ad_basereq()
). IfNA
, 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".
Examples
if (FALSE) { # \dontrun{
vt_ids <- search_vt(c("Aedes", "aegypti"))
vtdf <- fetch_vt(vt_ids[(length(vt_ids)-20):length(vt_ids)]) %>%
extract_vt(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"))
} # }