Skip to content

Commit 1e46b67

Browse files
authored
add examples to all functions (#202)
* add examples to functions
1 parent bb1c9ff commit 1e46b67

36 files changed

+784
-5
lines changed

R/Aggregation.R

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
#' @return
2424
#' An object of class \code{covariateData}.
2525
#'
26+
#' @examples
27+
#' \dontrun{
28+
#' covariateData <- FeatureExtraction:::createEmptyCovariateData(cohortId = 1,
29+
#' aggregated = FALSE,
30+
#' temporal = FALSE)
31+
#' aggregatedCovariateData <- aggregateCovariates(covariateData)
32+
#' }
33+
#'
2634
#' @export
2735
aggregateCovariates <- function(covariateData) {
2836
if (!isCovariateData(covariateData))

R/CompareCohorts.R

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
#' A data frame with means and standard deviations per cohort as well as the standardized difference
3232
#' of mean.
3333
#'
34+
#' @examples
35+
#' \dontrun{
36+
#' binaryCovDataFile <- system.file("testdata/binaryCovariateData.zip",
37+
#' package = "FeatureExtraction")
38+
#' covariateData1 <- loadCovariateData(binaryCovDataFile)
39+
#' covariateData2 <- loadCovariateData(binaryCovDataFile)
40+
#' covDataDiff <- computeStandardizedDifference(covariateData1, covariateData2, cohortId1 = 1, cohortId2 = 2)
41+
#' }
3442
#' @export
3543
computeStandardizedDifference <- function(covariateData1, covariateData2, cohortId1 = NULL, cohortId2 = NULL) {
3644
if (!isCovariateData(covariateData1))

R/CovariateData.R

+53-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@ setClass("CovariateData", contains = "Andromeda")
5353
#' The data will be written to a set of files in the folder specified by the user.
5454
#'
5555
#' @examples
56-
#' # todo
56+
#' \dontrun{
57+
#' covariateData <- FeatureExtraction:::createEmptyCovariateData(cohortId = 1,
58+
#' aggregated = FALSE,
59+
#' temporal = FALSE)
60+
#' # For this example we'll use a temporary file location:
61+
#' fileName <- tempfile()
62+
#' saveCovariateData(covariateData = covariateData, file = fileName)
63+
#' # Cleaning up the file used in this example:
64+
#' unlink(fileName)
65+
#' }
5766
#'
5867
#' @export
5968
saveCovariateData <- function(covariateData, file) {
@@ -82,7 +91,11 @@ saveCovariateData <- function(covariateData, file) {
8291
#' An object of class \code{CovariateData}.
8392
#'
8493
#' @examples
85-
#' # todo
94+
#' \dontrun{
95+
#' binaryCovDataFile <- system.file("testdata/binaryCovariateData.zip",
96+
#' package = "FeatureExtraction")
97+
#' covData <- loadCovariateData(binaryCovDataFile)
98+
#' }
8699
#'
87100
#' @export
88101
loadCovariateData <- function(file, readOnly) {
@@ -151,11 +164,19 @@ print.summary.CovariateData <- function(x, ...) {
151164

152165
#' Check whether an object is a CovariateData object
153166
#'
154-
#' @param x The object to check.
167+
#' @param x The object to check.
155168
#'
156169
#' @return
157170
#' A logical value.
158171
#'
172+
#' @examples
173+
#' \dontrun{
174+
#' binaryCovDataFile <- system.file("testdata/binaryCovariateData.zip",
175+
#' package = "FeatureExtraction")
176+
#' covData <- loadCovariateData(binaryCovDataFile)
177+
#' isCovData <- isCovariateData(covData)
178+
#' }
179+
#'
159180
#' @export
160181
isCovariateData <- function(x) {
161182
return(inherits(x, "CovariateData"))
@@ -168,6 +189,14 @@ isCovariateData <- function(x) {
168189
#' @return
169190
#' A logical value.
170191
#'
192+
#' @examples
193+
#' \dontrun{
194+
#' covariateData <- FeatureExtraction:::createEmptyCovariateData(cohortId = 1,
195+
#' aggregated = FALSE,
196+
#' temporal = FALSE)
197+
#' isAggrCovData <- isAggregatedCovariateData(covariateData)
198+
#' }
199+
#'
171200
#' @export
172201
isAggregatedCovariateData <- function(x) {
173202
if (!isCovariateData(x))
@@ -184,6 +213,14 @@ isAggregatedCovariateData <- function(x) {
184213
#' @return
185214
#' A logical value.
186215
#'
216+
#' @examples
217+
#' \dontrun{
218+
#' covariateData <- FeatureExtraction:::createEmptyCovariateData(cohortId = 1,
219+
#' aggregated = FALSE,
220+
#' temporal = FALSE)
221+
#' isTempCovData <- isTemporalCovariateData(covariateData)
222+
#' }
223+
#'
187224
#' @export
188225
isTemporalCovariateData <- function(x) {
189226
if (!isCovariateData(x))
@@ -193,6 +230,19 @@ isTemporalCovariateData <- function(x) {
193230
return("timeId" %in% colnames(x$covariates))
194231
}
195232

233+
#' Creates an empty covariate data object
234+
#'
235+
#' @param cohortId cohort number
236+
#' @param aggregated if the data should be aggregated
237+
#' @param temporal if the data is temporary
238+
#'
239+
#' @examples
240+
#' \dontrun{
241+
#' covariateData <- FeatureExtraction:::createEmptyCovariateData(cohortId = 1,
242+
#' aggregated = FALSE,
243+
#' temporal = FALSE)
244+
#' }
245+
#'
196246
createEmptyCovariateData <- function(cohortId, aggregated, temporal) {
197247
dummy <- tibble(covariateId = 1,
198248
covariateValue = 1)

R/DetailedCovariateSettings.R

+56
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727
#'
2828
#' @return
2929
#' An object of type \code{covariateSettings}, to be used in other functions.
30+
#'
31+
#' @examples
32+
#' \dontrun{
33+
#' analysisDetails <- createAnalysisDetails(analysisId = 1,
34+
#' sqlFileName = "DemographicsGender.sql",
35+
#' parameters = list(analysisId = 1,
36+
#' analysisName = "Gender",
37+
#' domainId = "Demographics"),
38+
#' includedCovariateConceptIds = c(),
39+
#' addDescendantsToInclude = FALSE,
40+
#' excludedCovariateConceptIds = c(),
41+
#' addDescendantsToExclude = FALSE,
42+
#' includedCovariateIds = c())
43+
#' covSettings <- createDetailedCovariateSettings(analyses = analysisDetails)
44+
#' }
3045
#'
3146
#' @export
3247
createDetailedCovariateSettings <- function(analyses = list()) {
@@ -57,6 +72,23 @@ createDetailedCovariateSettings <- function(analyses = list()) {
5772
#' @return
5873
#' An object of type \code{covariateSettings}, to be used in other functions.
5974
#'
75+
#' @examples
76+
#' \dontrun{
77+
#' analysisDetails <- createAnalysisDetails(analysisId = 1,
78+
#' sqlFileName = "DemographicsGender.sql",
79+
#' parameters = list(analysisId = 1,
80+
#' analysisName = "Gender",
81+
#' domainId = "Demographics"),
82+
#' includedCovariateConceptIds = c(),
83+
#' addDescendantsToInclude = FALSE,
84+
#' excludedCovariateConceptIds = c(),
85+
#' addDescendantsToExclude = FALSE,
86+
#' includedCovariateIds = c())
87+
#' covSettings <- createDetailedTemporalCovariateSettings(analyses = analysisDetails,
88+
#' temporalStartDays = -365:-1,
89+
#' temporalEndDays = -365:-1)
90+
#' }
91+
#'
6092
#' @export
6193
createDetailedTemporalCovariateSettings <- function(analyses = list(),
6294
temporalStartDays = -365:-1,
@@ -144,6 +176,12 @@ createAnalysisDetails <- function(analysisId,
144176
#' @return
145177
#' An object of type \code{covariateSettings}, to be used in other functions.
146178
#'
179+
#' @examples
180+
#' \dontrun{
181+
#' covSettings <- createDefaultCovariateSettings()
182+
#' detailedSettings <- convertPrespecSettingsToDetailedSettings(covariateSettings = covSettings)
183+
#' }
184+
#'
147185
#' @export
148186
convertPrespecSettingsToDetailedSettings <- function(covariateSettings) {
149187
json <- .toJson(covariateSettings)
@@ -170,6 +208,15 @@ convertPrespecSettingsToDetailedSettings <- function(covariateSettings) {
170208
#' @return
171209
#' An object of type \code{covariateSettings}, to be used in other functions.
172210
#'
211+
#' @examples
212+
#' \dontrun{
213+
#' covSettings <- createDefaultCovariateSettings(includedCovariateConceptIds = c(1),
214+
#' addDescendantsToInclude = FALSE,
215+
#' excludedCovariateConceptIds = c(2),
216+
#' addDescendantsToExclude = FALSE,
217+
#' includedCovariateIds = c(1))
218+
#' }
219+
#'
173220
#' @export
174221
createDefaultCovariateSettings <- function(includedCovariateConceptIds = c(),
175222
addDescendantsToInclude = FALSE,
@@ -207,6 +254,15 @@ createDefaultCovariateSettings <- function(includedCovariateConceptIds = c(),
207254
#' @return
208255
#' An object of type \code{covariateSettings}, to be used in other functions.
209256
#'
257+
#' @examples
258+
#' \dontrun{
259+
#' covSettings <- createDefaultTemporalCovariateSettings(includedCovariateConceptIds = c(1),
260+
#' addDescendantsToInclude = FALSE,
261+
#' excludedCovariateConceptIds = c(2),
262+
#' addDescendantsToExclude = FALSE,
263+
#' includedCovariateIds = c(1))
264+
#' }
265+
#'
210266
#' @export
211267
createDefaultTemporalCovariateSettings <- function(includedCovariateConceptIds = c(),
212268
addDescendantsToInclude = FALSE,

R/GetCovariates.R

+21
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@
6060
#' @return
6161
#' Returns an object of type \code{covariateData}, containing information on the covariates.
6262
#'
63+
#' @examples
64+
#' \dontrun{
65+
#' eunomiaConnectionDetails <- Eunomia::getEunomiaConnectionDetails()
66+
#' covSettings <- createDefaultCovariateSettings()
67+
#' Eunomia::createCohorts(connectionDetails = eunomiaConnectionDetails,
68+
#' cdmDatabaseSchema = "main",
69+
#' cohortDatabaseSchema = "main",
70+
#' cohortTable = "cohort")
71+
#' covData <- getDbCovariateData(connectionDetails = eunomiaConnectionDetails,
72+
#' oracleTempSchema = NULL,
73+
#' cdmDatabaseSchema = "main",
74+
#' cdmVersion = "5",
75+
#' cohortTable = "cohort",
76+
#' cohortDatabaseSchema = "main",
77+
#' cohortTableIsTemp = FALSE,
78+
#' cohortId = -1,
79+
#' rowIdField = "subject_id",
80+
#' covariateSettings = covSettings,
81+
#' aggregated = FALSE)
82+
#' }
83+
#'
6384
#' @export
6485
getDbCovariateData <- function(connectionDetails = NULL,
6586
connection = NULL,

R/GetCovariatesFromCohortAttributes.R

+43
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,38 @@
2323
#' \code{\link{createCohortAttrCovariateSettings}} function.
2424
#'
2525
#' @template GetCovarParams
26+
#'
27+
#' @examples
28+
#' \dontrun{
29+
#' connectionDetails <- Eunomia::getEunomiaConnectionDetails()
30+
#' Eunomia::createCohorts(connectionDetails = connectionDetails,
31+
#' cdmDatabaseSchema = "main",
32+
#' cohortDatabaseSchema = "main",
33+
#' cohortTable = "cohort")
34+
#' connection <- DatabaseConnector::connect(connectionDetails)
35+
#' sql <- "SELECT 1 AS attribute_definition_id, 'Length of observation in days' AS attribute_name
36+
#' INTO @cohort_database_schema.@attribute_definition_table;"
37+
#' sql <- SqlRender::render(sql, cohort_database_schema = "main", attribute_definition_table = "attribute_definition")
38+
#' sql <- SqlRender::translate(sql = sql,
39+
#' targetDialect = attr(connection, "dbms"))
40+
#' DatabaseConnector::executeSql(connection, sql)
41+
#' covariateSettings <- createCohortAttrCovariateSettings(attrDatabaseSchema = "main",
42+
#' cohortAttrTable = "cohort_attribute",
43+
#' attrDefinitionTable = "attribute_definition",
44+
#' includeAttrIds = c(1),
45+
#' isBinary = FALSE,
46+
#' missingMeansZero = FALSE)
47+
#'
48+
#' covData <- getDbCohortAttrCovariatesData(connection = connection,
49+
#' oracleTempSchema = NULL,
50+
#' cdmDatabaseSchema = "main",
51+
#' cdmVersion = "5",
52+
#' cohortTable = "cohort",
53+
#' cohortId = 1,
54+
#' rowIdField = "subject_id",
55+
#' covariateSettings = covariateSettings,
56+
#' aggregated = FALSE)
57+
#' }
2658
#'
2759
#' @export
2860
getDbCohortAttrCovariatesData <- function(connection,
@@ -135,6 +167,17 @@ getDbCohortAttrCovariatesData <- function(connection,
135167
#' @return
136168
#' An object of type \code{covariateSettings}, to be used in other functions.
137169
#'
170+
#' @examples
171+
#' \dontrun{
172+
#' covariateSettings <- createCohortAttrCovariateSettings(analysisId = 1,
173+
#' attrDatabaseSchema = "main",
174+
#' attrDefinitionTable = "attribute_definition",
175+
#' cohortAttrTable = "cohort_attribute",
176+
#' includeAttrIds = c(1),
177+
#' isBinary = FALSE,
178+
#' missingMeansZero = FALSE)
179+
#' }
180+
#'
138181
#' @export
139182
createCohortAttrCovariateSettings <- function(analysisId = -1,
140183
attrDatabaseSchema,

R/GetDefaultCovariates.R

+15
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@
3333
#' @param targetAnalysisRefTable (Optional) The name of the table where the analysis reference will be stored.
3434
#'
3535
#' @template GetCovarParams
36+
#'
37+
#' @examples
38+
#' \dontrun{
39+
#' connection <- DatabaseConnector::connect(connectionDetails)
40+
#' Eunomia::createCohorts(connectionDetails)
41+
#'
42+
#' results <- getDbDefaultCovariateData(connection = connection,
43+
#' cdmDatabaseSchema = "main",
44+
#' cohortTable = "cohort",
45+
#' covariateSettings = createDefaultCovariateSettings(),
46+
#' targetDatabaseSchema = "main",
47+
#' targetCovariateTable = "ut_cov",
48+
#' targetCovariateRefTable = "ut_cov_ref",
49+
#' targetAnalysisRefTable = "ut_cov_analysis_ref")
50+
#' }
3651
#'
3752
#' @export
3853
getDbDefaultCovariateData <- function(connection,

R/HelperFunctions.R

+22
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121
#'
2222
#' @return
2323
#' An object of type \code{covariateData}.
24+
#'
25+
#' @examples
26+
#' \dontrun{
27+
#' covariateData <- FeatureExtraction:::createEmptyCovariateData(cohortId = 1,
28+
#' aggregated = FALSE,
29+
#' temporal = FALSE)
30+
#'
31+
#' covData <- filterByRowId(covariateData = covariateData,
32+
#' rowIds = 1)
33+
#' }
34+
#'
2435
#' @export
2536
filterByRowId <- function(covariateData, rowIds) {
2637
if (!isCovariateData(covariateData))
@@ -49,6 +60,17 @@ filterByRowId <- function(covariateData, rowIds) {
4960
#'
5061
#' @return
5162
#' An object of type \code{covariateData}.
63+
#'
64+
#' @examples
65+
#' \dontrun{
66+
#' covariateData <- FeatureExtraction:::createEmptyCovariateData(cohortId = 1,
67+
#' aggregated = FALSE,
68+
#' temporal = FALSE)
69+
#'
70+
#' covData <- filterByCohortDefinitionId(covariateData = covariateData,
71+
#' cohortId = 1)
72+
#' }
73+
#'
5274
#' @export
5375
filterByCohortDefinitionId <- function(covariateData, cohortId) {
5476
if (!isCovariateData(covariateData))

R/Normalization.R

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
#' frequency.
2828
#' @param normalize Normalize the covariates? (dividing by the max).
2929
#' @param removeRedundancy Should redundant covariates be removed?
30+
#'
31+
#' @examples
32+
#' \dontrun{
33+
#' covariateData <- FeatureExtraction:::createEmptyCovariateData(cohortId = 1,
34+
#' aggregated = FALSE,
35+
#' temporal = FALSE)
36+
#'
37+
#' covData <- tidyCovariateData(covariateData = covariateData,
38+
#' minFraction = 0.001,
39+
#' normalize = TRUE,
40+
#' removeRedundancy = TRUE)
41+
#' }
3042
#'
3143
#' @export
3244
tidyCovariateData <- function(covariateData,

0 commit comments

Comments
 (0)