darwin-eu / omopgenerics

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

logPrefix argument in compute #544

Closed edward-burn closed 1 week ago

edward-burn commented 1 week ago

Although it is nice that we can easily log SQL through compute, it can sometimes be difficult to know which function the SQL comes from (example below shows how we have a couple of files created, but in practice study code would have many more). @catalamarti would you be happy for me to add the agrument logPrefix (or something similar) so that if logPrefix = "PatientProfilesaddSex" then this would be used as a prefix and it would be easy to see where the SQL came from (if NULL, the default, the behaviour would be unchanged)? If so I'd be happy to work on the pr

library(PatientProfiles)
#> Warning: package 'PatientProfiles' was built under R version 4.4.1
library(CohortCharacteristics)
cdm <- mockPatientProfiles(numberIndividuals = 1000)
dir <- file.path(tempdir(), "sql_folder")
dir.create(dir)

options("omopgenerics.log_sql_path" = dir)
result <- cdm$cohort1 |> 
  addSex() |> 
  summariseCharacteristics(strata = "sex")
#> SQL query saved to C:\Users\eburn\AppData\Local\Temp\RtmpS6B088/sql_folder
#> ℹ adding demographics columns
#> 
#> SQL query saved to C:\Users\eburn\AppData\Local\Temp\RtmpS6B088/sql_folder
#> ℹ summarising data
#> 
#> ✔ summariseCharacteristics finished!
list.files(dir, full.names = T)
#> [1] "C:\\Users\\eburn\\AppData\\Local\\Temp\\RtmpS6B088/sql_folder/logged_query_ran_on_2024_10_23_at_14_30_41.sql"
#> [2] "C:\\Users\\eburn\\AppData\\Local\\Temp\\RtmpS6B088/sql_folder/logged_query_ran_on_2024_10_23_at_14_30_42.sql"

Created on 2024-10-23 with reprex v2.1.0

catalamarti commented 1 week ago

yep happy with that