Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support tidyselect when passing cohort names to cohortId argument #322

Open
edward-burn opened this issue Sep 21, 2024 · 2 comments · May be fixed by #419
Open

support tidyselect when passing cohort names to cohortId argument #322

edward-burn opened this issue Sep 21, 2024 · 2 comments · May be fixed by #419
Assignees
Labels
enhancement New feature or request

Comments

@edward-burn
Copy link
Collaborator

library(omopgenerics)
#> 
#> Attaching package: 'omopgenerics'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library(CDMConnector)
#> 
#> Attaching package: 'CDMConnector'
#> The following objects are masked from 'package:omopgenerics':
#> 
#>     cdmName, recordCohortAttrition, uniqueTableName
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(CohortConstructor)
#> 
#> Attaching package: 'CohortConstructor'
#> The following objects are masked from 'package:CDMConnector':
#> 
#>     intersectCohorts, unionCohorts

con <- DBI::dbConnect(duckdb::duckdb(), dbdir = eunomia_dir())
cdm <- cdm_from_con(con, cdm_schema = "main", 
                    write_schema = c(prefix = "my_study_", schema = "main"))
fracture_codes <- newCodelist(list("ankle_fracture" = 4059173L,
                                   "forearm_fracture" = 4278672L,
                                   "hip_fracture" = 4230399L))
cdm$fractures <- cdm |> 
  conceptCohort(conceptSet = fracture_codes,
                name = "fractures")
#> ℹ Subsetting table condition_occurrence using 3 concepts with domain:
#>   condition.
#> ℹ Combining tables.
#> ℹ Creating cohort attributes.
#> ℹ Applying cohort requirements.
#> ℹ Collapsing records.
#> ✔ Cohort fractures created.


cdm$fractures_2 <- cdm$fractures |> 
  subsetCohorts(cohortId = "forearm_fracture", 
                name = "fractures_2")

cdm$fractures_2 <- cdm$fractures |> 
  subsetCohorts(cohortId = dplyr::starts_with("forearm"), 
                name = "fractures_2")
#> Error:
#> ! `starts_with()` must be used within a *selecting* function.
#> ℹ See <https://tidyselect.r-lib.org/reference/faq-selection-context.html> for
#>   details.
#> Backtrace:
#>     ▆
#>  1. ├─CohortConstructor::subsetCohorts(...)
#>  2. │ └─CohortConstructor:::validateCohortId(cohortId, settings(cohort)) at CohortConstructor/R/subsetCohorts.R:29:3
#>  3. └─dplyr::starts_with("forearm") at CohortConstructor/R/subsetCohorts.R:29:3
#>  4.   ├─vars %||% peek_vars(fn = "starts_with")
#>  5.   └─tidyselect::peek_vars(fn = "starts_with")
#>  6.     └─cli::cli_abort(...)
#>  7.       └─rlang::abort(...)

Created on 2024-09-21 with reprex v2.0.2

@catalamarti
Copy link
Collaborator

I would implement this in:

  • omopgenerics::validateCohortIdArgument()
  • omopgenerics::getCohortId()

So it can be also used by other packages and we ensure consistency.

what do you think @edward-burn ?

@edward-burn
Copy link
Collaborator Author

yes @catalamarti, that would be great!

@edward-burn edward-burn added the enhancement New feature or request label Oct 17, 2024
@nmercadeb nmercadeb self-assigned this Dec 17, 2024
@nmercadeb nmercadeb linked a pull request Dec 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants