ctsit / redcapcustodian

Simplified, automated data management on REDCap systems
Other
12 stars 6 forks source link

Allow custom params in function that use `get_package_scope_var`, default to said `package_scope_var` #121

Closed ChemiKyle closed 12 months ago

ChemiKyle commented 1 year ago

We should give users (and ourselves) the ability to override function variables that use get_package_scope_var, namely DB connection objects so that we can easily use in-memory databases while testing, rather than having to load a separate .env file for testing.

Updates would follow this template:

foo <- function(
...,
+db_conn = NULL
) {
- db_conn <- get_package_scope_var("db_conn")
+  if (is.null(db_conn)) {
+    db_conn <- get_package_scope_var("db_conn")
+  }
...
}

Relevant places that get_package_scope_var is called:

https://github.com/search?q=repo%3Actsit/redcapcustodian%20get_package_scope_var&type=code

I think this one makes the most sense to update:

Its use in logging.R might be more suited to overriding the package scoped log_con, we wouldn't typically be running log_job_* functions during testing.