Skip to content

Commit

Permalink
Use recode() and lookup table to map values
Browse files Browse the repository at this point in the history
Rather than hardcoding via case_when.

See tidyverse/dplyr#2505 (comment) for understanding the !!! notation
  • Loading branch information
peterdesmet committed Jun 28, 2017
1 parent 874e12e commit 849d2cb
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/dwc_mapping.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,11 @@ Map the source data to [Species Distribution](http://rs.gbif.org/extension/gbif/
distribution %>%
mutate(
id = ID,
locationID = paste0("ISO3166-2:", case_when(
.$presence_area == "Presence_Be" ~ "BE",
.$presence_area == "Presence_Br" ~ "BE-BRU",
.$presence_area == "Presence_Fl" ~ "BE-VLG",
.$presence_area == "Presence_Wa" ~ "BE-WAL"
)),
locality = case_when(
.$presence_area == "Presence_Be" ~ "Belgium",
.$presence_area == "Presence_Br" ~ "Brussels-Capital Region",
.$presence_area == "Presence_Fl" ~ "Flemish Region",
.$presence_area == "Presence_Wa" ~ "Walloon Region"
locationID = paste0(
"ISO3166-2:",
recode(.$presence_area, !!!term_lookup(lookup_table, "locationID"))
),
locality = recode(.$presence_area, !!!term_lookup(lookup_table, "locality")),
countryCode = "BE",
# lifeStage
occurrenceStatus = case_when(
Expand Down

0 comments on commit 849d2cb

Please sign in to comment.