Skip to content

Commit

Permalink
make more elegant
Browse files Browse the repository at this point in the history
  • Loading branch information
EhrmannS committed Jan 10, 2024
1 parent 831780f commit 68c250c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions R/get_concept.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ get_concept <- function(..., external = FALSE, matches = FALSE, ontology = NULL)
if(matches){
externalConcepts <- ontology@concepts$external %>%
separate_wider_delim(cols = id, names = c("dataseries", "nr"), delim = "_", cols_remove = FALSE) %>%
rowwise() %>%
mutate(label = paste0(label, " [", dataseries, "]")) %>%
# rowwise() %>%
# mutate(label = paste0(label, " [", dataseries, "]")) %>%
select(extID = id, extLabel = label)

toOut <- ontology@concepts$harmonised %>%
Expand All @@ -69,10 +69,12 @@ get_concept <- function(..., external = FALSE, matches = FALSE, ontology = NULL)
separate_rows(external, sep = " \\| ") %>%
separate_wider_delim(cols = external, names = "extID", delim = ".", too_many = "drop") %>%
left_join(externalConcepts, by = "extID") %>%
group_by(across(all_of(c("id", "label", "class", "has_broader", "description", "match")))) %>%
summarise(extLabel = paste0(na.omit(extLabel), collapse = " | ")) %>%
ungroup() %>%
pivot_wider(id_cols = c("id", "label", "class", "has_broader", "description"), names_from = match, values_from = extLabel, values_fill = NA_character_)
# group_by(across(all_of(c("id", "label", "class", "has_broader", "description", "match")))) %>%
# summarise(extLabel = paste0(na.omit(extLabel), collapse = " | ")) %>%
# ungroup() %>%
pivot_wider(id_cols = c("id", "label", "class", "has_broader", "description"), names_from = match,
values_from = extLabel, values_fn = ~paste0(na.omit(.x), collapse = " | ")) %>%
mutate(across(where(is.character), ~na_if(x = ., y = "")))
} else {
toOut <- ontology@concepts$harmonised
}
Expand Down

0 comments on commit 68c250c

Please sign in to comment.