Get a concept in an ontology
get_concept(..., external = FALSE, matches = FALSE, ontology = NULL)
combination of column name and value to filter that column by.
logical(1)
whether or not to return merely
the table of external concepts.
logical(1)
whether or not to include external
concepts as label instead of id in the match columns of the harmonised
concepts; this allows querying the external concepts in the harmonised
concepts (only if external = FALSE
).
ontology(1)
either a path where the ontology is
stored, or an already loaded ontology.
A table of a subset of the ontology according to the values in
...
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics")
onto <- load_ontology(path = ontoDir)
# exact matches from a loaded ontology ...
get_concept(label = "FODDER CROPS", ontology = onto)
#> # A tibble: 1 × 9
#> id label description class has_broader has_close_match has_narrower_match
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 .05 FODDER… NA group NA NA NA
#> # ℹ 2 more variables: has_broader_match <chr>, has_exact_match <chr>
# ... or a path
get_concept(label = c("FODDER CROPS", "CEREALS"), ontology = ontoDir)
#> # A tibble: 2 × 9
#> id label description class has_broader has_close_match has_narrower_match
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 .02 CEREALS NA group NA NA NA
#> 2 .05 FODDER… NA group NA NA NA
#> # ℹ 2 more variables: has_broader_match <chr>, has_exact_match <chr>
# ignore querries that would not be valid in filter()
get_concept(label != 'Bioenergy woody' & has_broader == '.01', ontology = onto)
#> # A tibble: 2 × 9
#> id label description class has_broader has_close_match has_narrower_match
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 .01.01 Bioen… NA class .01 NA NA
#> 2 .01.03 Other… NA class .01 NA NA
#> # ℹ 2 more variables: has_broader_match <chr>, has_exact_match <chr>
# extract concepts based on regular expressions
library(stringr)
get_concept(str_detect(label, "crop") & str_detect(id, ".03$"), ontology = ontoDir)
#> # A tibble: 3 × 9
#> id label description class has_broader has_close_match has_narrower_match
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 .01.03 Other… NA class .01 NA NA
#> 2 .05.03 Other… NA class .05 NA NA
#> 3 .15.03 Other… NA class .15 NA NA
#> # ℹ 2 more variables: has_broader_match <chr>, has_exact_match <chr>