Skip to content

Commit f653152

Browse files
authored
Merge pull request #102 from darwin-eu-dev/issue_96
Fix r-cmd check
2 parents 3800d7f + b5e940d commit f653152

File tree

60 files changed

+707
-637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+707
-637
lines changed

.Rbuildignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ compare_versions
3131
^Meta$
3232
inst/shiny/DiagnosticsExplorer/renv
3333
work/
34-
sql/
34+
^sql/$

DESCRIPTION

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Suggests:
5151
shiny,
5252
OhdsiShinyModules,
5353
rsconnect,
54-
yaml
54+
yaml,
55+
ggplot2
5556
Remotes:
5657
ohdsi/OhdsiShinyModules
5758
License: Apache License

NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export(getCdmDataSourceInformation)
1010
export(getCohortCounts)
1111
export(getConceptCountsTableName)
1212
export(getDataMigrator)
13+
export(getDefaultCovariateSettings)
1314
export(getDefaultVocabularyTableNames)
1415
export(getResultsDataModelSpecifications)
1516
export(launchDiagnosticsExplorer)
@@ -22,6 +23,7 @@ export(runIncidenceRate)
2223
export(runIncludedSourceConcepts)
2324
export(runInclusionStatistics)
2425
export(runOrphanConcepts)
26+
export(runResolvedConceptSets)
2527
export(runTimeSeries)
2628
export(runVisitContext)
2729
export(uploadResults)

R/ConceptSetUtils.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ exportConceptSets <- function(cohortDefinitionSet, exportFolder, minCellCount, d
301301
minCellCount = minCellCount,
302302
databaseId = databaseId,
303303
incremental = FALSE,
304-
cohortId = conceptSetsExport$cohortId
304+
cohortId = cohortDefinitionSet$cohortId
305305
)
306306
}
307307

R/ResultsDataModel.R

+16-13
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,22 @@ uploadResults <- function(connectionDetails,
141141

142142
ParallelLogger::logInfo("Unzipping ", zipFileName)
143143
zip::unzip(zipFileName, exdir = unzipFolder)
144-
145-
ResultModelManager::uploadResults(
146-
connectionDetails = connectionDetails,
147-
schema = schema,
148-
resultsFolder = unzipFolder,
149-
tablePrefix = tablePrefix,
150-
forceOverWriteOfSpecifications = forceOverWriteOfSpecifications,
151-
purgeSiteDataBeforeUploading = purgeSiteDataBeforeUploading,
152-
runCheckAndFixCommands = TRUE,
153-
databaseIdentifierFile = "database.csv",
154-
specifications = getResultsDataModelSpecifications(),
155-
warnOnMissingTable = FALSE,
156-
...
144+
145+
# suppressing warning for reserved keywords in SQL
146+
suppressWarnings(
147+
ResultModelManager::uploadResults(
148+
connectionDetails = connectionDetails,
149+
schema = schema,
150+
resultsFolder = unzipFolder,
151+
tablePrefix = tablePrefix,
152+
forceOverWriteOfSpecifications = forceOverWriteOfSpecifications,
153+
purgeSiteDataBeforeUploading = purgeSiteDataBeforeUploading,
154+
runCheckAndFixCommands = TRUE,
155+
databaseIdentifierFile = "database.csv",
156+
specifications = getResultsDataModelSpecifications(),
157+
warnOnMissingTable = FALSE,
158+
...
159+
)
157160
)
158161
}
159162

R/executeDiagnostics.R

+18-43
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#' Get default covariate settings
1818
#' @description
1919
#' Default covariate settings for cohort diagnostics execution
20+
#'
21+
#' @return Default covariate settings
2022
#' @export
2123
getDefaultCovariateSettings <- function() {
2224
FeatureExtraction::createTemporalCovariateSettings(
@@ -94,27 +96,27 @@ getDefaultCovariateSettings <- function() {
9496
#' using \code{RFeatureExtraction::createTemporalCovariateSettings}
9597
#' Alternatively, a covariate setting object may be created using the above as an example.
9698
#'
97-
#' @template Connection
99+
#' @template connectionDetails
98100
#' @template CdmDatabaseSchema
99101
#' @template VocabularyDatabaseSchema
100102
#' @template CohortDatabaseSchema
101103
#' @template TempEmulationSchema
102104
#' @template CohortTable
103105
#' @template CohortSetReference
104106
#' @template exportFolder
105-
#' @template cohortIds
107+
#' @template CohortIds
106108
#' @template cohortDefinitionSet
107109
#' @template MinCellCount
108110
#' @template Incremental
109111
#' @template cdmVersion
110112
#' @template databaseId
111113
#' @template minCharacterizationMean
112114
#'
113-
#' @param cohortTableNames Cohort Table names used by CohortGenerator package
115+
#' @param cohortTableNames Cohort Table names used by CohortGenerator package.
114116
#' @param conceptCountsTable Concepts count table name. The default is "#concept_counts" to create a temporal concept counts table.
115-
#' If an external concept counts table is used, provide the name in character, e.g. "concept_counts" without a hash
116-
#' @param databaseName The full name of the database. If NULL, defaults to value in cdm_source table
117-
#' @param databaseDescription A short description (several sentences) of the database. If NULL, defaults to value in cdm_source table
117+
#' If an external concept counts table is used, provide the name in character, e.g. "concept_counts" without a hash.
118+
#' @param databaseName The full name of the database. If NULL, defaults to value in cdm_source table.
119+
#' @param databaseDescription A short description (several sentences) of the database. If NULL, defaults to value in cdm_source table.
118120
#' @param runInclusionStatistics Generate and export statistic on the cohort inclusion rules?
119121
#' @param runIncludedSourceConcepts Generate and export the source concepts included in the cohorts?
120122
#' @param runOrphanConcepts Generate and export potential orphan concepts?
@@ -130,9 +132,6 @@ getDefaultCovariateSettings <- function() {
130132
#' the createTemporalCovariateSettings function in the FeatureExtraction package, or a list
131133
#' of such objects.
132134
#' @param irWashoutPeriod Number of days washout to include in calculation of incidence rates - default is 0
133-
#' @param incrementalFolder If \code{incremental = TRUE}, specify a folder where records are kept
134-
#' of which cohort diagnostics has been executed.
135-
#' @param useExternalConceptCountsTable If TRUE an external table for the cohort concept counts will be used.
136135
#' @param runFeatureExtractionOnSample Logical. If TRUE, the function will operate on a sample of the data.
137136
#' Default is FALSE, meaning the function will operate on the full data set.
138137
#'
@@ -144,20 +143,6 @@ getDefaultCovariateSettings <- function() {
144143
#'
145144
#' @param seedArgs List. Additional arguments to pass to the sampling function.
146145
#' This can be used to control aspects of the sampling process beyond the seed and sample size.
147-
#'
148-
#' @param sampleIdentifierExpression Character. An expression that generates unique identifiers for each sample.
149-
#' This expression can use the variables 'cohortId' and 'seed'.
150-
#' Default is "cohortId * 1000 + seed", which ensures unique identifiers
151-
#' as long as there are fewer than 1000 cohorts.
152-
#'
153-
#' @param useAchilles Logical. Should the pre-computed Achilles analyses be used to get concept counts? TRUE or FALSE (default)
154-
#'
155-
#' @param achillesDatabaseSchema Character. The name of the schema where the Achilles results tables are located.
156-
#' Require if `useAchilles` is TRUE and ignored otherwise.
157-
#'
158-
#' @param workDatabaseSchema Character. The name of a schema where the user has write access. Intermediate tables for concept counts
159-
#' and orphan concepts will be created in this schema if supplied. If NULL (default) intermediate tables will
160-
#' be created as temporary tables.
161146
#' @examples
162147
#' \dontrun{
163148
#' # Load cohorts (assumes that they have already been instantiated)
@@ -364,19 +349,9 @@ executeDiagnostics <- function(cohortDefinitionSet,
364349
}
365350

366351
# Create output and incremental folders. check that we have write access.
367-
if (!file.exists(gsub("/$", "", exportFolder))) {
368-
dir.create(name, recursive = TRUE)
369-
ParallelLogger::logInfo("Created export folder", exportFolder)
370-
}
371-
checkmate::assertDirectory(exportFolder, access = "w", add = errorMessage)
372-
373-
if (incremental) {
374-
if (!file.exists(gsub("/$", "", exportFolder))) {
375-
dir.create(name, recursive = TRUE)
376-
ParallelLogger::logInfo("Created incremental folder", incrementalFolder)
377-
}
378-
checkmate::assertDirectory(incrementalFolder, access = "w", add = errorMessage)
379-
}
352+
checkArg(exportFolder, add = errorMessage)
353+
checkArg(incremental, add = errorMessage)
354+
checkArg(incrementalFolder, add = errorMessage)
380355

381356
if (is(temporalCovariateSettings, "covariateSettings")) {
382357
temporalCovariateSettings <- list(temporalCovariateSettings)
@@ -676,7 +651,7 @@ executeDiagnostics <- function(cohortDefinitionSet,
676651
minCellCount = minCellCount,
677652
databaseId = databaseId,
678653
incremental = FALSE,
679-
cohortId = cohorts$cohortId
654+
cohortId = cohortDefinitionSet$cohortId
680655
)
681656
}
682657
)
@@ -926,6 +901,8 @@ executeDiagnostics <- function(cohortDefinitionSet,
926901
)
927902

928903
feCohortTable <- cohortTableNames$cohortSampleTable
904+
# work around for cohortGenerator 0.11.1
905+
cohortDefinitionSet$cohortIds <- cohortDefinitionSet$cohortId
929906
feCohortDefinitionSet <-
930907
CohortGenerator::sampleCohortDefinitionSet(
931908
connection = connection,
@@ -941,15 +918,13 @@ executeDiagnostics <- function(cohortDefinitionSet,
941918
incrementalFolder = incrementalFolder
942919
)
943920

944-
feCohortCounts <- computeCohortCounts(
921+
feCohortCounts <- CohortGenerator::getCohortCounts(
945922
connection = connection,
946923
cohortDatabaseSchema = cohortDatabaseSchema,
947924
cohortTable = cohortTableNames$cohortSampleTable,
948-
cohorts = feCohortDefinitionSet,
949-
exportFolder = exportFolder,
950-
minCellCount = minCellCount,
951-
databaseId = databaseId,
952-
writeResult = FALSE
925+
cohortDefinitionSet = feCohortDefinitionSet,
926+
cohortIds = cohortDefinitionSet$cohortId,
927+
databaseId = databaseId
953928
)
954929
}
955930

R/getCdmDataSourceInformation.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#' Returns CDM source name, description, release date, CDM release date, version
2323
#' and vocabulary version, where available.
2424
#'
25-
#' @template Connection
25+
#' @template connectionDetails
2626
#'
2727
#' @template CdmDatabaseSchema
2828
#'

R/plotLogFile.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
readLog <- function(path) {
2-
df <- read.csv(path, sep = "\t", header = FALSE)
2+
df <- utils::read.csv(path, sep = "\t", header = FALSE)
33
names(df) <- c("time", "thread", "level", "package", "task", "message")
44

55
df %>%

R/runCohortCharacterization.R

+14-16
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ getCohortCharacteristics <- function(connection = NULL,
311311
return(results)
312312
}
313313

314-
#' runCohortCharacterization
314+
#' Generate and export the temporal cohort characterization
315315
#'
316316
#' @description
317317
#' This function takes cohorts as input and generates the covariates for these cohorts.
@@ -324,32 +324,30 @@ getCohortCharacteristics <- function(connection = NULL,
324324
#' * temporal_covariate_value_dist.csv
325325
#' * temporal_time_ref.csv
326326
#'
327-
#' @template connection
327+
#' @template Connection
328328
#' @template databaseId
329-
#' @template exportFolder
330-
#' @template cdmDatabaseSchema
331-
#' @template cohortDatabaseSchema
332-
#' @template cohortTable
333-
#' @template tempEmulationSchema
329+
#' @template ExportFolder
330+
#' @template CdmDatabaseSchema
331+
#' @template CohortDatabaseSchema
332+
#' @template CohortTable
333+
#' @template TempEmulationSchema
334334
#' @template cdmVersion
335-
#' @template minCellCount
336-
#' @template instantiatedCohorts
335+
#' @template MinCellCount
336+
#' @template InstantiatedCohorts
337337
#' @template Incremental
338-
#' @template batchSize
338+
#' @template BatchSize
339339
#'
340-
#' @param cohorts The cohorts for which the covariates need to be obtained
341-
#' @param cohortCounts A dataframe with the cohort counts
340+
#' @param cohorts The cohorts for which the covariates need to be obtained.
341+
#' @param cohortCounts A dataframe with the cohort counts.
342342
#' @param covariateSettings Either an object of type \code{covariateSettings} as created using one of
343343
#' the createTemporalCovariateSettings function in the FeatureExtraction package, or a list
344344
#' of such objects.
345345
#' @param minCharacterizationMean The minimum mean value for characterization output. Values below this will be cut off from output. This
346346
#' will help reduce the file size of the characterization output, but will remove information
347-
#' on covariates that have very low values. The default is 0.001 (i.e. 0.1 percent)
347+
#' on covariates that have very low values. The default is 0.001 (i.e. 0.1 percent).
348348
#'
349-
#' @return None, it will write results to disk
349+
#' @return None, it will write results to disk.
350350
#' @export
351-
#'
352-
#' @examples
353351
runCohortCharacterization <- function(connection,
354352
databaseId,
355353
exportFolder,

R/runCohortRelationship.R

+5-4
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ getCohortRelationship <- function(
174174
}
175175

176176

177-
#' runCohortRelationship
177+
#' Generate and export the cohort temporal relationships
178178
#'
179179
#' @description
180-
#' Generate and export the cohort relationship. Cohort relationship checks the temporal relationship between two or more cohorts
181-
#' and derives subject counts for cohorts with different temporal relationships.
180+
#' Generate and export the cohort relationship. Cohort relationship checks the temporal relationship
181+
#' between two or more cohorts and derives subject counts for cohorts with different temporal relationships.
182182
#'
183183
#' @template Connection
184184
#' @template cohortDefinitionSet
@@ -192,7 +192,8 @@ getCohortRelationship <- function(
192192
#' @template MinCellCount
193193
#' @template Incremental
194194
#' @template BatchSize
195-
#'
195+
#'
196+
#' @return None, it will write the results to a csv file.
196197
#' @export
197198
runCohortRelationship <- function(
198199
connection,

R/runIncidenceRate.R

+13-10
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,23 @@ aggregateIr <- function(ratesSummary, aggregateList) {
199199
}
200200

201201
#' Run the incidence rate cohort diagnostic
202-
#'
202+
#' @description
203203
#' runIncidenceRate computes incidence rates for cohorts in the CDM population stratified
204204
#' by age, sex, and calendar year.
205205
#'
206-
#' @template connection
207-
#' @template cohortDefinitionSet
206+
#' @template Connection
207+
#' @template CohortDefinitionSet
208208
#' @param washoutPeriod Then minimum number of required observation days prior to
209-
#' cohort index to be included in the numerator of the incidence rate
210-
#' @template tempEmulationSchema
211-
#' @template cdmDatabaseSchema
209+
#' cohort index to be included in the numerator of the incidence rate.
210+
#' @template TempEmulationSchema
211+
#' @template CdmDatabaseSchema
212212
#' @template CohortTable
213213
#' @template databaseId
214-
#' @template exportFolder
215-
#' @template minCellCount
214+
#' @template ExportFolder
215+
#' @template MinCellCount
216216
#' @template Incremental
217217
#'
218-
#' @return
218+
#' @return None, it will write the results to a csv file.
219219
#' @export
220220
runIncidenceRate <- function(connection,
221221
cohortDefinitionSet,
@@ -299,7 +299,10 @@ runIncidenceRate <- function(connection,
299299

300300
data <- lapply(split(subset, subset$cohortId), runOneIncidenceRate)
301301
data <- dplyr::bind_rows(data)
302-
302+
data <- dplyr::mutate(data, databaseId = databaseId)
303+
304+
data <- data %>% dplyr::select("cohortCount", "personYears", "gender", "gender", "ageGroup",
305+
"calendarYear", "incidenceRate", "cohortId", "databaseId")
303306
exportDataToCsv(
304307
data = data,
305308
tableName = "incidence_rate",

0 commit comments

Comments
 (0)