-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
135 lines (107 loc) · 3.95 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
output: github_document
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
eval = TRUE,
echo = TRUE,
message = TRUE,
warning = TRUE,
fig.width = 8,
fig.height = 6,
dpi = 200,
fig.align = "center",
fig.path = "man/figures/README-"
)
library(magrittr)
library(cohortBuilder)
library(shinyCohortBuilder)
library(cohortBuilder.db)
set.seed(123)
options(tibble.width = Inf)
iris <- tibble::as.tibble(iris)
options("tibble.print_max" = 5)
options("tibble.print_min" = 5)
```
# cohortBuilder.db <img src="man/figures/logo.png" align="right" width="120" />
cohortBuilder.db is database layer for [cohortBuilder](https://r-world-devs.github.io/cohortBuilder/) and [shinyCohortBuilder](https://r-world-devs.github.io/shinyCohortBuilder/).
The package allows you to operate with `cohortBuilder` API on remote tables stores within a database.
All of the operations are performed directly on the database server side!
[![version](https://img.shields.io/static/v1.svg?label=github.com&message=v.0.0.0.9026&color=ff69b4)](https://github.io/r-world-devs/cohortBuilder.db/)
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
## Installation
```{r, eval = FALSE}
# CRAN version
install.packages("cohortBuilder.db")
# Latest development version
remotes::install_github("https://github.com/r-world-devs/cohortBuilder.db")
```
## Overview
`cohortBuilder.db` allows you to use `cohortBuilder` and `shinyCohortBuilder` features working with database connection.
Comparing to the standard workflow (working on list of tables) you just need to create database tables configuration using `dbtables` where you provide database connection, schema name and table names.
Than pass the created object to `set_source` method:
```{r, eval = FALSE}
library(cohortBuilder)
library(cohortBuilder.db)
db_tables_conf <- dbtables(
connection = <db-connection>,
schema = <schema-name>,
tables = <vector-of-table-names-to-use>
)
librarian_db_source <- set_source(
db_tables_conf
)
```
and configure Cohort using the same rules known from `cohortBuilder`:
```{r, eval = FALSE}
librarian_db_cohort <- cohort(
librarian_source,
filter(
"discrete", id = "author", dataset = "books",
variable = "author", value = "Dan Brown"
),
filter(
"range", id = "copies", dataset = "books",
variable = "copies", range = c(5, 10)
),
filter(
"date_range", id = "registered", dataset = "borrowers",
variable = "registered", range = c(as.Date("2010-01-01"), Inf)
)
)
```
Now feel free to use all the known `cohortBuilder` features.
You can also use `shinyCohortBuilder` to use `cohortBuilder` features in shiny.
Just use db-based Cohort with the known approach:
```{r, eval = FALSE}
library(shiny)
library(shinyCohortBuilder)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
cb_ui("librarian")
),
mainPanel(
verbatimTextOutput("cohort_data")
)
)
)
server <- function(input, output, session) {
cb_server("librarian", librarian_db_cohort)
output$cohort_data <- renderPrint({
input[["librarian-data-updated"]]
get_data(librarian_cohort)
})
}
shinyApp(ui, server)
```
## Acknowledgement
Special thanks to:
- [Kamil Wais](mailto:[email protected]) for highlighting the need for the package and its relevance to real-world applications.
- [Adam Foryś](mailto:[email protected]) for technical support, numerous suggestions for the current and future implementation of the package.
- [Paweł Kawski](mailto:[email protected]) for indication of initial assumptions about the package based on real-world medical data.
## Getting help
In a case you found any bugs, have feature request or general question please file an issue at the package [Github](https://github.com/r-world-devs/cohortBuilder.db/issues).
You may also contact the package author directly via email at [[email protected]]([email protected]).