Skip to content

Commit 4c8ee82

Browse files
authored
Merge pull request #108 from OHDSI/develop
update to v2.0.9
2 parents c25f736 + 14c557d commit 4c8ee82

145 files changed

Lines changed: 469 additions & 377 deletions

File tree

Some content is hidden

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

.github/workflows/R_CMD_check_Hades.yaml

Lines changed: 33 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
config:
23-
- {os: windows-latest, r: 'release'} # Does not appear to have Java 32-bit, hence the --no-multiarch
23+
- {os: windows-latest, r: 'release'}
2424
- {os: macOS-latest, r: 'release'}
2525
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
2626

27-
2827
env:
2928
GITHUB_PAT: ${{ secrets.GH_TOKEN }}
29+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3030
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
3131
RSPM: ${{ matrix.config.rspm }}
3232
CDM5_ORACLE_CDM_SCHEMA: ${{ secrets.CDM5_ORACLE_CDM_SCHEMA }}
@@ -44,85 +44,64 @@ jobs:
4444
CDM5_SQL_SERVER_PASSWORD: ${{ secrets.CDM5_SQL_SERVER_PASSWORD }}
4545
CDM5_SQL_SERVER_SERVER: ${{ secrets.CDM5_SQL_SERVER_SERVER }}
4646
CDM5_SQL_SERVER_USER: ${{ secrets.CDM5_SQL_SERVER_USER }}
47+
CDM5_REDSHIFT_CDM_SCHEMA: ${{ secrets.CDM5_REDSHIFT_CDM_SCHEMA }}
48+
CDM5_REDSHIFT_OHDSI_SCHEMA: ${{ secrets.CDM5_REDSHIFT_OHDSI_SCHEMA }}
49+
CDM5_REDSHIFT_PASSWORD: ${{ secrets.CDM5_REDSHIFT_PASSWORD }}
50+
CDM5_REDSHIFT_SERVER: ${{ secrets.CDM5_REDSHIFT_SERVER }}
51+
CDM5_REDSHIFT_USER: ${{ secrets.CDM5_REDSHIFT_USER }}
52+
CDM5_SPARK_USER: ${{ secrets.CDM5_SPARK_USER }}
53+
CDM5_SPARK_PASSWORD: ${{ secrets.CDM5_SPARK_PASSWORD }}
54+
CDM5_SPARK_CONNECTION_STRING: ${{ secrets.CDM5_SPARK_CONNECTION_STRING }}
55+
WEBAPI_TEST_WEBAPI_URL: ${{ secrets.WEBAPI_TEST_WEBAPI_URL }}
56+
WEBAPI_TEST_SECURE_WEBAPI_URL: ${{ secrets.WEBAPI_TEST_SECURE_WEBAPI_URL }}
57+
WEBAPI_TEST_ADMIN_USER_NAME: ${{ secrets.WEBAPI_TEST_ADMIN_USER_NAME }}
58+
WEBAPI_TEST_ADMIN_USER_PASSWORD: ${{ secrets.WEBAPI_TEST_ADMIN_USER_PASSWORD }}
4759

4860
steps:
4961
- uses: actions/checkout@v3
5062

5163
- uses: r-lib/actions/setup-r@v2
5264
with:
5365
r-version: ${{ matrix.config.r }}
54-
use-public-rspm: true
5566

5667
- uses: r-lib/actions/setup-tinytex@v2
5768

5869
- uses: r-lib/actions/setup-pandoc@v2
5970

60-
- name: Query dependencies
61-
run: |
62-
install.packages('remotes')
63-
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
64-
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
65-
shell: Rscript {0}
66-
67-
- name: Cache R packages
68-
if: runner.os != 'Windows'
69-
uses: actions/cache@v2
70-
with:
71-
path: ${{ env.R_LIBS_USER }}
72-
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
73-
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
74-
75-
- name: Install system dependencies
71+
- name: Install system requirements
7672
if: runner.os == 'Linux'
7773
run: |
74+
sudo apt-get install -y libssh-dev
75+
Rscript -e 'install.packages("remotes")'
7876
while read -r cmd
7977
do
8078
eval sudo $cmd
8179
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
8280
83-
- name: Install libssh
84-
if: runner.os == 'Linux'
85-
run: |
86-
sudo apt-get install libssh-dev
87-
88-
- name: Install dependencies
89-
run: |
90-
install.packages("curl")
91-
remotes::install_deps(dependencies = TRUE, INSTALL_opts=c("--no-multiarch"))
92-
remotes::install_cran("rcmdcheck")
93-
shell: Rscript {0}
94-
95-
- name: Install covr
96-
if: runner.os == 'macOS'
97-
run: |
98-
remotes::install_cran("covr")
99-
shell: Rscript {0}
100-
101-
- name: Remove check folder if exists
102-
if: runner.os == 'macOS'
103-
run: unlink("check", recursive = TRUE)
104-
shell: Rscript {0}
105-
106-
- name: Check
107-
env:
108-
_R_CHECK_CRAN_INCOMING_REMOTE_: false
109-
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran", "--no-multiarch"), error_on = "warning", check_dir = "check")
110-
shell: Rscript {0}
81+
- uses: r-lib/actions/setup-r-dependencies@v2
82+
with:
83+
extra-packages: any::rcmdcheck
84+
needs: check
11185

112-
- name: Upload check results
113-
if: failure()
114-
uses: actions/upload-artifact@v2
86+
- uses: r-lib/actions/check-r-package@v2
11587
with:
116-
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
117-
path: check
88+
args: 'c("--no-manual", "--as-cran")'
89+
error-on: '"warning"'
90+
check-dir: '"check"'
11891

11992
- name: Upload source package
12093
if: success() && runner.os == 'macOS' && github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
121-
uses: actions/upload-artifact@v2
94+
uses: actions/upload-artifact@v4
12295
with:
12396
name: package_tarball
12497
path: check/*.tar.gz
12598

99+
- name: Install covr
100+
if: runner.os == 'macOS'
101+
run: |
102+
install.packages("covr")
103+
shell: Rscript {0}
104+
126105
- name: Test coverage
127106
if: runner.os == 'macOS'
128107
run: covr::codecov()
@@ -182,7 +161,7 @@ jobs:
182161
183162
- name: Download package tarball
184163
if: ${{ env.new_version != '' }}
185-
uses: actions/download-artifact@v2
164+
uses: actions/download-artifact@v4.1.7
186165
with:
187166
name: package_tarball
188167

DESCRIPTION

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
Package: Capr
22
Title: Cohort Definition Application Programming
3-
Version: 2.0.8
3+
Version: 2.0.9
44
Authors@R: c(
55
person("Martin", "Lavallee", , "martin.lavallee@boehringer-ingelheim.com", role = c("aut", "cre")),
6-
person("Adam", "Black", , "black@ohdsi.org", role = c("aut"))
6+
person("Adam", "Black", , "black@ohdsi.org", role = c("aut")),
7+
person("Katy", "Sadowski", , "sadowski@ohdsi.org", role = c("ctb"))
78
)
89
Description: Provides a programming language for defining cohort definitions in R to use in studies for Observational
910
Health Data Sciences and Informatics (OHDSI). The functions in 'Capr' allow for the programmatic creation of
@@ -16,11 +17,10 @@ License: Apache License (>= 2)
1617
URL: https://ohdsi.github.io/Capr/, https://github.com/OHDSI/Capr/
1718
BugReports: https://github.com/OHDSI/Capr/issues/
1819
Encoding: UTF-8
19-
RoxygenNote: 7.3.1
20+
RoxygenNote: 7.3.2
2021
Depends:
21-
R (>= 3.5.0)
22+
R (>= 4.2.0)
2223
Imports:
23-
magrittr (>= 1.5.0),
2424
jsonlite,
2525
methods,
2626
purrr (>= 1.0.1),
@@ -61,4 +61,3 @@ Collate:
6161
'exit.R'
6262
'cohort.R'
6363
'collectCodesetId.R'
64-
'utils.R'

NAMESPACE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

33
S3method(compile,Cohort)
4-
export("%>%")
54
export(age)
65
export(as.json)
76
export(atLeast)
@@ -76,10 +75,10 @@ export(withAtMost)
7675
export(writeCohort)
7776
export(writeConceptSet)
7877
exportMethods("==")
78+
exportMethods(as.data.frame)
7979
exportMethods(compile)
8080
import(dplyr)
8181
importFrom(generics,compile)
82-
importFrom(magrittr,"%>%")
8382
importFrom(methods,"slot<-")
8483
importFrom(rlang,"%||%")
8584
importFrom(rlang,":=")

NEWS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Capr 2.0.9
2+
==========
3+
- convert duplicate concept ids to a warning instead of error #107
4+
- add as.json function for cohorts #97
5+
- fix vignette for nested cohort example #106
6+
- add type to `startDate` and `endDate` attributes to make Era dates #103
7+
- remove magrittr pipe dependency #100
8+
- export as.data.frame #104
9+
110
Capr 2.0.8
211
==========
312
- add conceptTypes to determine data provenance #93

R/Capr.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Observational Health Data Sciences and Informatics
1+
# Copyright 2025 Observational Health Data Sciences and Informatics
22
#
33
# This file is part of Capr
44
#

R/attributes-op.R

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ setClass("opAttributeDate",
8383

8484
opToPrint <- function(x) {
8585
tibble::tibble(symbol = c("<", "<=", ">", ">=", "==", "-", "!-"), op = c("lt", "lte", "gt", "gte",
86-
"eq", "bt", "!bt")) %>%
87-
dplyr::filter(.data$op == x) %>%
86+
"eq", "bt", "!bt")) |>
87+
dplyr::filter(.data$op == x) |>
8888
dplyr::pull(.data$symbol)
8989
}
9090

@@ -485,45 +485,75 @@ drugQuantity <- function(op) {
485485
#' Function that creates a start date attribute
486486
#' @param op an opAttribute object must be a date that defines the logical operation used to
487487
#' determine eligible start dates
488+
#' @param type specify the type of date to use either occurrence or era. default as occurrence
488489
#' @return An attribute that can be used in a cohort definition
489490
#' @export
490-
startDate <- function(op) {
491+
startDate <- function(op, type = "occurrence") {
492+
493+
type <- match.arg(type, choices = c("occurrence", "era"))
491494

492495
check <- all(grepl("opAttribute(Date|Super)", methods::is(op)))
493496
if (!check) {
494497
stop("Input must be an opAttributeDate.")
495498
}
496499

497-
methods::new("opAttributeDate",
498-
name = "OccurrenceStartDate",
499-
op = op@op,
500-
value = op@value,
501-
extent = op@extent)
500+
if (type == "occurrence") {
501+
sd <- methods::new("opAttributeDate",
502+
name = "OccurrenceStartDate",
503+
op = op@op,
504+
value = op@value,
505+
extent = op@extent)
506+
}
507+
508+
if (type == "era") {
509+
sd <- methods::new("opAttributeDate",
510+
name = "EraStartDate",
511+
op = op@op,
512+
value = op@value,
513+
extent = op@extent)
514+
}
515+
return(sd)
516+
502517
}
503518

504519
#' Function that creates a end date attribute
505520
#' @param op an opAttribute object must be a date that defines the logical operation used to
506521
#' determine eligible end dates
522+
#' @param type specify the type of date to use either occurrence or era. default as occurrence
507523
#' @return An attribute that can be used in a cohort definition
508524
#' @export
509-
endDate <- function(op) {
525+
endDate <- function(op, type = "occurrence") {
526+
527+
type <- match.arg(type, choices = c("occurrence", "era"))
510528

511529
check <- all(grepl("opAttribute(Date|Super)", methods::is(op)))
512530
if (!check) {
513531
stop("Input must be an opAttributeDate.")
514532
}
515533

516-
methods::new("opAttributeDate",
517-
name = "OccurrenceEndDate",
518-
op = op@op,
519-
value = op@value,
520-
extent = op@extent)
534+
if (type == "occurrence") {
535+
ed <- methods::new("opAttributeDate",
536+
name = "OccurrenceEndDate",
537+
op = op@op,
538+
value = op@value,
539+
extent = op@extent)
540+
}
541+
542+
if (type == "era") {
543+
ed <- methods::new("opAttributeDate",
544+
name = "EraEndDate",
545+
op = op@op,
546+
value = op@value,
547+
extent = op@extent)
548+
}
549+
return(ed)
550+
521551
}
522552

523553
# Coercion ------------
524554
#' @importFrom rlang :=
525555
listOpAttribute <- function(x) {
526-
atr <- list(Op = x@op, Value = x@value, Extent = x@extent) %>%
556+
atr <- list(Op = x@op, Value = x@value, Extent = x@extent) |>
527557
purrr::discard(is.na)
528558

529559
tibble::lst(`:=`(!!x@name, atr))

R/cohort.R

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ setMethod("as.list", "CohortEntry", function(x) {
224224
'QualifiedLimit' = list('Type' = x@qualifiedLimit)
225225
)
226226

227-
ll <- list('PrimaryCriteria' = pc) %>%
227+
ll <- list('PrimaryCriteria' = pc) |>
228228
append(ac)
229229

230230
if (is.na(ll$AdditionalCriteria$Type)) {
@@ -290,10 +290,10 @@ setMethod("as.list", "CohortEra", function(x) {
290290
## Coerce Cohort ----------
291291
setMethod("as.list", "Cohort", function(x) {
292292

293-
ll <- as.list(x@entry) %>%
294-
append(as.list(x@attrition)) %>%
295-
append(as.list(x@exit)) %>%
296-
append(as.list(x@era)) %>%
293+
ll <- as.list(x@entry) |>
294+
append(as.list(x@attrition)) |>
295+
append(as.list(x@exit)) |>
296+
append(as.list(x@era)) |>
297297
append(list("cdmVersionRange" = ">=5.0.0"))
298298

299299
return(ll)
@@ -313,7 +313,7 @@ toCirce <- function(cd) {
313313
cdCirce <- list(
314314
#start with getting concept set structure
315315
'ConceptSets' = listConceptSets(cd2)
316-
) %>%
316+
) |>
317317
#append cohort structure
318318
append(as.list(cd2))
319319

@@ -334,6 +334,16 @@ compile.Cohort <- function(object, ...) {
334334
as.character(jsonlite::toJSON(toCirce(object), auto_unbox = TRUE, ...))
335335
}
336336

337+
338+
#' @rdname as.json
339+
#' @aliases as.json,Cohort-method
340+
setMethod("as.json", "Cohort", function(x, pretty = TRUE, ...) {
341+
# Use the existing toCirce function to get the proper structure
342+
circe_data <- toCirce(x)
343+
# Convert to JSON using jsonlite and ensure it's a character string
344+
as.character(jsonlite::toJSON(x = circe_data, pretty = pretty, auto_unbox = TRUE, ...))
345+
})
346+
337347
#' Compile a Capr cohort to json
338348
#'
339349
#' @param object A Capr cohort or list of Capr cohorts
@@ -392,7 +402,7 @@ writeCohort <- function(x, path) {
392402
checkmate::assertClass(x, "Cohort")
393403
checkmate::assertCharacter(path, len = 1, min.chars = 1, pattern = "\\.json$")
394404

395-
toCirce(x) %>%
405+
toCirce(x) |>
396406
jsonlite::write_json(
397407
path = path,
398408
auto_unbox = TRUE,
@@ -432,8 +442,8 @@ writeCohort <- function(x, path) {
432442

433443
# capr_to_circe <- function(cd) {
434444
#
435-
# circeJson <- toCirce(cd) %>%
436-
# jsonlite::toJSON(auto_unbox = TRUE, pretty = TRUE) %>%
445+
# circeJson <- toCirce(cd) |>
446+
# jsonlite::toJSON(auto_unbox = TRUE, pretty = TRUE) |>
437447
# as.character()
438448
#
439449
# return(circeJson)

0 commit comments

Comments
 (0)