darwin-eu-dev / PatientProfiles

https://darwin-eu-dev.github.io/PatientProfiles/
Apache License 2.0
6 stars 5 forks source link

custom strata names #648

Closed edward-burn closed 3 months ago

edward-burn commented 4 months ago

In the example below I give a custom name to my strata, but seems to be lost. I'm not sure if we should even allow this though @catalamarti @nmercadeb, becasue I didn't use &&& in my name so maybe this would cause problems anyway?

library(CDMConnector)
library(CodelistGenerator)
library(CohortCharacteristics)
library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.2.3
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.2.3

con <- DBI::dbConnect(duckdb::duckdb(),
                      dbdir = CDMConnector::eunomia_dir())
cdm <- CDMConnector::cdm_from_con(con,
                                  cdm_schem = "main",
                                  write_schema = "main", 
                                  cdm_name = "Eunomia")

cdm <- generateConceptCohortSet(
  cdm = cdm,
  name = "injuries",
  conceptSet = list("ankle_sprain" = 81151,
                    "ankle_fracture" = 4059173,
                    "forearm_fracture" = 4278672,
                    "hip_fracture" = 4230399),
  end = "event_end_date",
  limit = "all"
)

chars <- cdm$injuries |>
  PatientProfiles::addDemographics(ageGroup = list(c(0,49),
                                                   c(50, Inf))) |> 
  summariseCharacteristics(strata = list("blah" = c("age_group", 
                                           "sex")))
#> ℹ adding demographics columns
#> ℹ summarising data
#> ! The following variables: result_type, package_name, package_version; were added to `settings`
#> ✔ summariseCharacteristics finished!
table(chars$strata_name)
#> 
#> age_group &&& sex           overall 
#>               560               148

Created on 2024-04-29 with reprex v2.0.2

edward-burn commented 4 months ago

As discussed, relates to PatientProfiles and summariseResult should throw a warning that, in the case of a named list, the names will be ignored