Skip to content

Commit

Permalink
Merge pull request #104 from OuhscBbmc/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
wibeasley committed Dec 10, 2019
2 parents 015124a + 315844b commit 4a789ff
Show file tree
Hide file tree
Showing 53 changed files with 258 additions and 127 deletions.
7 changes: 3 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ Package: OuhscMunge
Title: Data Manipulation Operations
Description: Data manipulation operations frequently used in OUHSC BBMC
projects.
Version: 0.1.9.9010
Date: 2019-02-27
Version: 0.1.9.9011
Authors@R: person("Will", "Beasley", email="wibeasley@hotmail.com", role=c("aut", "cre"),
comment = c(ORCID = "0000-0002-5613-5006"))
URL: https://github.com/OuhscBbmc/OuhscMunge, http://ouhsc.edu/bbmc/
Expand All @@ -28,10 +27,10 @@ Imports:
testit,
tibble,
Suggests:
odbc (>= 1.1.6),
odbc (>= 1.2.0),
RODBC,
RODBCext,
testthat
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
21 changes: 19 additions & 2 deletions R/execute-sql-file.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#' (which typically returns a scalar). Otherwise, `DBI::dbGetQuery()` is used,
#' (which will return a `tibble::tibble`). Required `logical`.
#' @param minimum_row_count If `execute` is false, the returned dataset should have at least this many rows, or an error will be thrown. Default of 0. Required integer.
#' @param timezone The server time zone. Passed to [DBI::dbConnect()].
#' @param timezone_out The time zone returned to R. Passed to [DBI::dbConnect()]. See https://www.tidyverse.org/blog/2019/12/odbc-1-2-0/.
#'
#' @return A vector of converted names.
#'
Expand All @@ -22,17 +24,32 @@
#' execute_sql_file("inst/condense-date.sql", "cdw_cache_staging")
#' }

execute_sql_file <- function( path_sql, dsn, execute=TRUE, minimum_row_count=0L ) {
execute_sql_file <- function(
path_sql,
dsn,
execute = TRUE,
minimum_row_count = 0L,
timezone = "UTC",
timezone_out = "UTC"
) {
checkmate::expect_file_exists(path_sql)
checkmate::assert_character(path_sql, min.chars=2, min.len=1, max.len=1, any.missing=F)
checkmate::assert_character(dsn , min.chars=2, min.len=1, max.len=1, any.missing=F)
checkmate::assert_logical( execute , len=1, any.missing=F)
checkmate::assert_character(timezone , len=1L, any.missing=F)
checkmate::assert_character(timezone_out , len=1L, any.missing=F)

sql <- readr::read_file(path_sql)
checkmate::assert_character(sql , min.chars=2, min.len=1, max.len=1, any.missing=F)

tryCatch({
channel <- odbc::dbConnect(odbc::odbc(), dsn)
channel <- odbc::dbConnect(
odbc::odbc(),
dsn,
timezone = timezone,
timezone_out = timezone_out
)

if( execute ) {
returned_value <- DBI::dbExecute(channel, sql)
} else {
Expand Down
3 changes: 2 additions & 1 deletion R/snake-case.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#' @return A vector of converted names.
#'
#' @note This series of regexes has an advantages over the current
#' implementations of [lettercase::str_snake_case()] and [`snakecase::to_snake_case()`].
#' implementations of [`lettercase::str_snake_case()`](https://github.com/decisionpatterns/lettercase)
#' and [`snakecase::to_snake_case()`].
#' The former converts "PatientDOB" to "patientdob" and the latter converts
#' "patient.dob" to "patient_._dob". I'll keep an eye on these packages
#' (*i.e.*, [lettercase #1](https://github.com/decisionpatterns/lettercase/issues/1) for 'camelCase'
Expand Down
17 changes: 14 additions & 3 deletions R/upload-sqls-odbc.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#' @param create_table If the table structure has not yet been defined in the database, it will be created if `create_table` is `TRUE`.
#' @param convert_logical_to_integer Convert all `logical` columns to `integer`. This helps the database store the values as bits.
#' @param transaction Should the clear and upload steps be wrapped in a rollback transaction?
#' @param timezone The server time zone. Passed to [DBI::dbConnect()].
#' @param timezone_out The time zone returned to R. Passed to [DBI::dbConnect()]. See https://www.tidyverse.org/blog/2019/12/odbc-1-2-0/.
#' @param verbose Write a message about the status of a successful upload.
#'
#' @details
Expand All @@ -33,7 +35,9 @@
#' clear_table = TRUE,
#' transaction = TRUE,
#' verbose = TRUE,
#' convert_logical_to_integer = TRUE
#' convert_logical_to_integer = TRUE,
#' timezone = "America/Chicago",
#' timezone_out = "America/Chicago"
#' )
#' }

Expand All @@ -46,7 +50,10 @@ upload_sqls_odbc <- function(
clear_table = FALSE,
create_table = FALSE,
convert_logical_to_integer = FALSE,
timezone = "UTC",
timezone_out = "UTC",
transaction = FALSE,

verbose = TRUE
) {

Expand All @@ -59,6 +66,8 @@ upload_sqls_odbc <- function(
checkmate::assert_logical( create_table , len=1L, any.missing=F)
checkmate::assert_logical( convert_logical_to_integer , len=1L, any.missing=F)
checkmate::assert_logical( transaction , len=1L, any.missing=F)
checkmate::assert_character(timezone , len=1L, any.missing=F)
checkmate::assert_character(timezone_out , len=1L, any.missing=F)
checkmate::assert_logical( verbose , len=1L, any.missing=F)

start_time <- base::Sys.time()
Expand Down Expand Up @@ -95,8 +104,10 @@ upload_sqls_odbc <- function(


channel <- DBI::dbConnect(
drv = odbc::odbc(),
dsn = dsn_name
drv = odbc::odbc(),
dsn = dsn_name,
timezone = timezone,
timezone_out = timezone_out
)

if( create_table) {
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/code-of-conduct.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/license.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pandoc: 2.3.1
pandoc: 2.7.2
pkgdown: 1.4.1
pkgdown_sha: ~
articles: []
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/OuhscMunge.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/assert.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/clump_date.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/cut_with_nas.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/reference/date_range.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/reference/deterge.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions docs/reference/execute_sql_file.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/first_nonmissing.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4a789ff

Please sign in to comment.