| lookup | R Documentation |
Resolves columns from dimension tables registered in a vtr_schema(),
automatically building the necessary join tree. Reports unmatched keys
as a diagnostic message.
lookup(.schema, ..., .join = "left", .report = TRUE)
.schema |
A |
... |
Column references: bare names for fact columns, or
|
.join |
Join type: |
.report |
Logical. If |
Column references use dimension$column syntax (e.g., species$name).
Columns from the fact table can be referenced by name directly.
When .report = TRUE, each needed dimension is checked for unmatched keys
by opening fresh scans of the fact and dimension tables. This adds one
extra read pass per dimension but does not affect the lazy result node.
Only dimensions referenced in ... are joined. Unreferenced dimensions
are never scanned.
A vectra_node with the selected columns.
f_obs <- tempfile(fileext = ".vtr")
f_sp <- tempfile(fileext = ".vtr")
f_ct <- tempfile(fileext = ".vtr")
write_vtr(data.frame(sp_id = 1:4, ct_code = c("AT", "DE", "FR", "XX"),
value = 10:13), f_obs)
write_vtr(data.frame(sp_id = 1:3,
name = c("Oak", "Beech", "Pine")), f_sp)
write_vtr(data.frame(ct_code = c("AT", "DE", "FR"),
gdp = c(400, 3800, 2700)), f_ct)
s <- vtr_schema(
fact = tbl(f_obs),
species = link("sp_id", tbl(f_sp)),
country = link("ct_code", tbl(f_ct))
)
# Pull columns from any linked dimension
result <- lookup(s, value, species$name, country$gdp)
collect(result)
unlink(c(f_obs, f_sp, f_ct))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.