darwin-eu-dev / omopgenerics

https://darwin-eu-dev.github.io/omopgenerics/
Apache License 2.0
1 stars 1 forks source link

names with curly brackets cause uninformative error #389

Closed edward-burn closed 1 month ago

edward-burn commented 2 months ago

from @MimiYuchenGuo - badly formatted names can result in an uninformative error

library(CDMConnector)
library(DrugUtilisation)

cdm <- mockDrugUtilisation()

generateDrugUtilisationCohortSet(
  cdm = cdm,
  name = "drug_cohorts",
  conceptSet = list("this doesn't break" = c(1125315, 1125360,
                          2905077, 43135274))
)
#> Warning: A cohort with this name already exist in the cdm object. It will be
#> overwritten.
#> Warning: cohort_name must be snake case, the following cohorts will be renamed:
#> • this doesn't break -> this_doesn_t_break
#> 
#> ── # OMOP CDM reference (duckdb) of DUS MOCK ───────────────────────────────────
#> • omop tables: person, observation_period, concept, concept_ancestor,
#> drug_strength, drug_exposure, condition_occurrence, visit_occurrence,
#> observation, concept_relationship
#> • cohort tables: cohort1, cohort2, drug_cohorts
#> • achilles tables: -
#> • other tables: -
generateDrugUtilisationCohortSet(
  cdm = cdm,
  name = "drug_cohorts",
  conceptSet = list("{this breaks}" = c(1125315, 1125360,
                                              2905077, 43135274))
)
#> Warning: A cohort with this name already exist in the cdm object. It will be
#> overwritten.
#> Error in "lapply(text, glue_cmd, .envir = .envir)": ! Could not parse cli `{}` expression: `this breaks`.
#> Caused by error in `parse(text = code, keep.source = FALSE)`:
#> ! <text>:1:6: unexpected symbol
#> 1: this breaks
#>          ^

Created on 2024-06-28 with reprex v2.0.2

catalamarti commented 2 months ago

shouldnt this be a problem for omopgenerics::newCodelist() ? @edward-burn

edward-burn commented 2 months ago

@catalamarti but is omopgenerics::newCodelist() being used in generateDrugUtilisationCohortSet? I suppose that is the first step is that and then the next would be reviewing the validation in omopgenerics. At the moment DUS allows for most special characters, it is just the curly brackets that seem to cause a problem for cli messages

library(DrugUtilisation)

cdm <- mockDrugUtilisation()
#> ■■■■■■■■■■■■■■■■■■■■■■ 70% | ETA: 1s■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 90% | ETA: 1s

generateDrugUtilisationCohortSet(
  cdm = cdm,
  name = "drug_cohorts",
  conceptSet = list("my (-*: new cohort" = c(1125315, 1125360,
                                             2905077, 43135274))
)
#> Warning: cohort_name must be snake case, the following cohorts will be renamed:
#> • my (-*: new cohort -> my_new_cohort
#> 
#> ── # OMOP CDM reference (duckdb) of DUS MOCK ───────────────────────────────────
#> • omop tables: person, observation_period, concept, concept_ancestor,
#> drug_strength, drug_exposure, condition_occurrence, visit_occurrence,
#> observation, concept_relationship
#> • cohort tables: cohort1, cohort2, drug_cohorts
#> • achilles tables: -
#> • other tables: -

generateDrugUtilisationCohortSet(
  cdm = cdm,
  name = "drug_cohorts",
  conceptSet = list("my {-*: new cohort" = c(1125315, 1125360,
                                             2905077, 43135274))
)
#> Error in glue(str, .envir = .envir, .transformer = transformer, .cli = TRUE, : Expecting '}'

Created on 2024-07-01 with reprex v2.1.0

catalamarti commented 2 months ago

darwin-eu-dev/DrugUtilisation#474

catalamarti commented 1 month ago

this should be fixed in validateConceptSetArgument():

list("my {-*: new cohort" = c(1125315, 1125360, 2905077, 43135274)) |>
    omopgenerics::validateConceptSetArgument()
#> 
#> ── 1 codelist ──────────────────────────────────────────────────────────────────
#> 
#> - my {-*: new cohort (4 codes)

Created on 2024-08-05 with reprex v2.1.1