Skip to content

Commit

Permalink
Automating dependency handling, platform interop, R CMD check house…
Browse files Browse the repository at this point in the history
…keeping, etc (#319)

* Adding .gitattributes

* Adding OHDSI/OhdsiRTools as remote so devtools::install_github can find it

* rebuilding man pages and fixing duplicate Achilles.Rd by deleting it

Problem with duplicates was introduced by cloning repo to Windows machine

* Step 2: adding achilles.Rd back

* Changing title to title case per CRAN reco

* Changing install instructions and fixing formatting of README.md

* Moved OhdsiRTools to Suggests since it is only needed for multithreaded mode.

* Linting README.md

* Addressing some issues raised by R CMD check.

* Linting

* Since dependency OhdsiRTools was moved to Suggests, import directive was removed from the NAMESPACE

* Updating version number and date

Per @t-abdul-basser's recommendation.
  • Loading branch information
pegeler authored and t-abdul-basser committed Oct 10, 2018
1 parent 7fa4deb commit b71c4ec
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 267 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
^\.Rproj\.user$
^.travis.yml$
deploy.sh
^\.github$
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
inst/doc/* linguist-documentation
vignettes/* linguist-documentation
man/* linguist-documentation
extras/* linguist-documentation
16 changes: 9 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
Package: Achilles
Type: Package
Title: Creates descriptive statistics summary for an entire OMOP CDM instance
Version: 1.6.1
Date: 2018-10-02
Title: Creates Descriptive Statistics Summary for an Entire OMOP CDM Instance
Version: 1.6.2
Date: 2018-10-04
Author: Patrick Ryan, Martijn Schuemie, Vojtech Huser, Chris Knoll, Ajit Londhe
Maintainer: Patrick Ryan <ryan@ohdsi.org>
LazyData: true
Description: creates descriptive statistics summary for an entire OMOP CDM
Description: Creates descriptive statistics summary for an entire OMOP CDM
instance. Since Aug 2016 only CDM v5 is actively being extended. Achilles
Heel component does data quality assesment.
Depends:
SqlRender,
DatabaseConnector (>= 2.0.0),
rjson,
OhdsiRTools
rjson
Suggests:
testthat,
dplyr,
R.utils
R.utils,
OhdsiRTools
Remotes:
OHDSI/OhdsiRTools
License: Apache License
Roxygen: list(wrap = FALSE)
RoxygenNote: 6.1.0
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ export(fetchAchillesHeelResults)
export(getAnalysisDetails)
export(showReportTypes)
export(validateSchema)
import(DatabaseConnector)
import(SqlRender)
import(rjson)
importFrom(utils,compareVersion)
importFrom(utils,packageVersion)
importFrom(utils,read.csv)
importFrom(utils,zip)
22 changes: 4 additions & 18 deletions R/Achilles-package.R
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
#' Achilles
#'
#' @name Achilles
#' @docType package
NULL




#' allReports
#'
#' A list of reports
#'
#'
#' @docType data
#' @keywords datasets
#' @name allReports

#' @import DatabaseConnector
#' @import SqlRender
#' @import rjson
#' @importFrom utils compareVersion packageVersion read.csv zip
NULL
120 changes: 64 additions & 56 deletions R/Achilles.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -74,28 +74,28 @@
#' numThreads = 10)
#' }
#' @export
achilles <- function (connectionDetails,
cdmDatabaseSchema,
oracleTempSchema = cdmDatabaseSchema,
resultsDatabaseSchema = cdmDatabaseSchema,
scratchDatabaseSchema = resultsDatabaseSchema,
vocabDatabaseSchema = cdmDatabaseSchema,
sourceName = "",
analysisIds,
createTable = TRUE,
smallCellCount = 5,
cdmVersion = "5",
runHeel = TRUE,
validateSchema = FALSE,
runCostAnalysis = FALSE,
conceptHierarchy = TRUE,
createIndices = TRUE,
numThreads = 1,
tempAchillesPrefix = "tmpach",
dropScratchTables = TRUE,
sqlOnly = FALSE,
outputFolder = "output",
logMultiThreadPerformance = FALSE) {
achilles <- function(connectionDetails,
cdmDatabaseSchema,
# oracleTempSchema = cdmDatabaseSchema, # Unused arg
resultsDatabaseSchema = cdmDatabaseSchema,
scratchDatabaseSchema = resultsDatabaseSchema,
vocabDatabaseSchema = cdmDatabaseSchema,
sourceName = "",
analysisIds,
createTable = TRUE,
smallCellCount = 5,
cdmVersion = "5",
runHeel = TRUE,
validateSchema = FALSE,
runCostAnalysis = FALSE,
conceptHierarchy = TRUE,
createIndices = TRUE,
numThreads = 1,
tempAchillesPrefix = "tmpach",
dropScratchTables = TRUE,
sqlOnly = FALSE,
outputFolder = "output",
logMultiThreadPerformance = FALSE) {

achillesSql <- c()

Expand Down Expand Up @@ -190,17 +190,27 @@ achilles <- function (connectionDetails,
schemaDelim <- "."

if (numThreads == 1 || scratchDatabaseSchema == "#") {
message("Beginning single-threaded operations")

numThreads <- 1
scratchDatabaseSchema <- "#"
schemaDelim <- "s_"

# first invocation of the connection, to persist throughout to maintain temp tables
connection <- DatabaseConnector::connect(connectionDetails = connectionDetails)
} else if (!requireNamespace("OhdsiRTools", quietly = TRUE)) {
stop(
"Multi-threading support requires package 'OhdsiRTools'.",
" Consider running single-threaded by setting",
" `numThreads = 1` and `scratchDatabaseSchema = '#'`.",
" You may install it using devtools with the following code:",
"\n devtools::install_github('OHDSI/OhdsiRTools')",
"\n\nAlternately, you might want to install ALL suggested packages using:",
"\n devtools::install_github('OHDSI/Achilles', dependencies = TRUE)",
call. = FALSE
)
} else {
if (!.is_installed("OhdsiRTools")) {
writeLines("Installing OhdsiRTools for multi-threading support")
devtools::install_github("OHDSI/OhdsiRTools")
}
message("Beginning multi-threaded operations")
}

# Create analysis table -------------------------------------------------------------
Expand Down Expand Up @@ -413,15 +423,15 @@ achilles <- function (connectionDetails,

if (numThreads > 1 & !sqlOnly) {
# Drop the scratch tables
writeLines(sprintf("Dropping scratch Achilles tables from schema %s", scratchDatabaseSchema))
message(sprintf("Dropping scratch Achilles tables from schema %s", scratchDatabaseSchema))

dropAllScratchTables(connectionDetails = connectionDetails,
scratchDatabaseSchema = scratchDatabaseSchema,
tempAchillesPrefix = tempAchillesPrefix,
numThreads = numThreads,
tableTypes = c("achilles", "concept_hierarchy"))

writeLines(sprintf("Temporary Achilles tables removed from schema %s", scratchDatabaseSchema))
message(sprintf("Temporary Achilles tables removed from schema %s", scratchDatabaseSchema))
}

# Generate Main Analyses ----------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -450,7 +460,7 @@ achilles <- function (connectionDetails,
achillesSql <- c(achillesSql, lapply(mainSqls, function(s) s$sql))

if (!sqlOnly) {
writeLines("Executing multiple queries. This could take a while")
message("Executing multiple queries. This could take a while")

if (numThreads == 1) {
for (mainSql in mainSqls) {
Expand Down Expand Up @@ -503,7 +513,7 @@ achilles <- function (connectionDetails,

if (!sqlOnly) {

writeLines("Merging scratch Achilles tables")
message("Merging scratch Achilles tables")

if (numThreads == 1) {
for (sql in mergeSqls) {
Expand All @@ -523,7 +533,7 @@ achilles <- function (connectionDetails,
}

if (!sqlOnly) {
writeLines(sprintf("Done. Achilles results can now be found in schema %s", resultsDatabaseSchema))
message(sprintf("Done. Achilles results can now be found in schema %s", resultsDatabaseSchema))
}

# Clean up scratch tables -----------------------------------------------
Expand All @@ -533,15 +543,15 @@ achilles <- function (connectionDetails,
DatabaseConnector::disconnect(connection = connection)
} else if (dropScratchTables & !sqlOnly) {
# Drop the scratch tables
writeLines(sprintf("Dropping scratch Achilles tables from schema %s", scratchDatabaseSchema))
message(sprintf("Dropping scratch Achilles tables from schema %s", scratchDatabaseSchema))

dropAllScratchTables(connectionDetails = connectionDetails,
scratchDatabaseSchema = scratchDatabaseSchema,
tempAchillesPrefix = tempAchillesPrefix,
numThreads = numThreads,
tableTypes = c("achilles"))

writeLines(sprintf("Temporary Achilles tables removed from schema %s", scratchDatabaseSchema))
message(sprintf("Temporary Achilles tables removed from schema %s", scratchDatabaseSchema))
}

# Create concept hierarchy table -----------------------------------------------------------------
Expand Down Expand Up @@ -605,10 +615,10 @@ achilles <- function (connectionDetails,

if (sqlOnly) {
SqlRender::writeSql(sql = paste(achillesSql, collapse = "\n\n"), targetFile = file.path(outputFolder, "achilles.sql"))
writeLines(sprintf("All Achilles SQL scripts can be found in folder: %s", file.path(outputFolder, "achilles.sql")))
message(sprintf("All Achilles SQL scripts can be found in folder: %s", file.path(outputFolder, "achilles.sql")))
}

return (achillesResults)
achillesResults
}

#' Create the concept hierarchy
Expand Down Expand Up @@ -678,7 +688,7 @@ createConceptHierarchy <- function(connectionDetails,


if (!sqlOnly) {
writeLines("Executing Concept Hierarchy creation. This could take a while")
message("Executing Concept Hierarchy creation. This could take a while")

if (numThreads == 1) {
connection <- DatabaseConnector::connect(connectionDetails = connectionDetails)
Expand Down Expand Up @@ -709,10 +719,10 @@ createConceptHierarchy <- function(connectionDetails,
numThreads = numThreads,
tableTypes = c("concept_hierarchy"))

writeLines(sprintf("Done. Concept Hierarchy table can now be found in %s", resultsDatabaseSchema))
message(sprintf("Done. Concept Hierarchy table can now be found in %s", resultsDatabaseSchema))
}

return (c(hierarchySqls, mergeSql))
c(hierarchySqls, mergeSql)
}


Expand Down Expand Up @@ -746,7 +756,7 @@ createIndices <- function(connectionDetails,
DatabaseConnector::disconnect(connection = connection)
}

return (indicesSql)
indicesSql
}


Expand Down Expand Up @@ -797,11 +807,11 @@ validateSchema <- function(connectionDetails,
} else {
connection <- DatabaseConnector::connect(connectionDetails = connectionDetails)
tables <- DatabaseConnector::querySql(connection = connection, sql = sql)
writeLines("CDM Schema is valid")
message("CDM Schema is valid")
DatabaseConnector::disconnect(connection = connection)
}

return (sql)
sql
}

#' Get all analysis details
Expand All @@ -814,9 +824,14 @@ validateSchema <- function(connectionDetails,
#'
#' @export
getAnalysisDetails <- function() {
pathToCsv <- system.file("csv", "achilles", "achilles_analysis_details.csv", package = "Achilles")
analysisDetails <- read.csv(file = pathToCsv, header = TRUE, stringsAsFactors = FALSE)
return (analysisDetails)
read.csv( # Recommend saving as an rda file in ./data/
system.file(
"csv",
"achilles",
"achilles_analysis_details.csv",
package = "Achilles"),
stringsAsFactors = FALSE
)
}

#' Drop all possible scratch tables
Expand Down Expand Up @@ -947,15 +962,14 @@ dropAllScratchTables <- function(connectionDetails,
cdmDatabaseSchema = cdmDatabaseSchema)$sql
connection <- DatabaseConnector::connect(connectionDetails = connectionDetails)
cdmVersion <- tryCatch({
c <- DatabaseConnector::querySql(connection = connection, sql = sql)
}, error = function (e) {
c <- ""
DatabaseConnector::querySql(connection = connection, sql = sql)
}, error = function(e) {
""
}, finally = {
DatabaseConnector::disconnect(connection = connection)
connection <- NULL
})

return (c)
cdmVersion
}

.getAnalysisSql <- function(analysisId,
Expand Down Expand Up @@ -1043,9 +1057,3 @@ dropAllScratchTables <- function(connectionDetails,

saveRDS(object = newDf, file = logFile)
}

.is_installed <- function(pkg, version = 0) {
installed_version <- tryCatch(utils::packageVersion(pkg), error = function(e) NA)
!is.na(installed_version) && installed_version >= version
}

Loading

0 comments on commit b71c4ec

Please sign in to comment.