Skip to content

Commit

Permalink
Update process.R
Browse files Browse the repository at this point in the history
Have substitutions process work on individual strings, not entire values.

For austraits this will require a bit of playing around with substitutions, but is well worth it for the long-term gains/simplicity.

solves issue #21
  • Loading branch information
ehwenk committed Aug 29, 2023
1 parent 1222fb6 commit b97126c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions R/process.R
Original file line number Diff line number Diff line change
Expand Up @@ -1184,11 +1184,13 @@ process_parse_data <- function(data, dataset_id, metadata, contexts) {

for (i in seq_len(nrow(substitutions_table))) {
j <- which(out[["trait_name"]] == substitutions_table[["trait_name"]][i] &
out[["value"]] == substitutions_table[["find"]][i])
stringr::str_detect(out[["value"]], paste0("(^|\\s)", substitutions_table[["find"]][i], "(\\s|$)")))

if (length(j) > 0) {
out[["value"]][j] <- substitutions_table[["replace"]][i]
out[["value"]][j] <- stringr::str_replace_all(out[["value"]][j], substitutions_table[["find"]][i], substitutions_table[["replace"]][i]) %>% stringr::str_squish()
}
}

}

list(
Expand Down

0 comments on commit b97126c

Please sign in to comment.