I found the current versions of bigrquery (v1.4.1) and dbplyr (v2.3.0) don’t work well together on my computer (Issue). If you encounter similar issues, you can install older versions of the these two packages.
library(devtools)install_version("bigrquery", version ="1.4.0")install_version("dbplyr", version ="2.1.1")
1 Q1. Compile the ICU cohort in HW2 from the Google BigQuery database
Below is an outline of steps.
Load the GCP BigQuery service account token. Please place the service account token (available at BruinLearn) at your MIMIC data folder: ~/mimic/biostat-203b-2022winter-3fdc2392ac39.json.
# path to the service account token satoken <-"~/mimic/biostat-203b-2023winter-3fdc2392ac39.json"# BigQuery authentication using service accountbq_auth(path = satoken,# email = "mimiciv-bigquery@biostat-203b-2023winter.iam.gserviceaccount.com",# scopes = c("https://www.googleapis.com/auth/bigquery",# "https://www.googleapis.com/auth/cloud-platform"))
Connect to BigQuery database mimic4_v1_0_203b in GCP (Google Cloud Platform), using the billing account biostat-203b-2022winter.
# Connect to the BigQuery database `biostat-203b-2022winter.mimic4_v1_0_203b`con <-dbConnect( bigrquery::bigquery(),project ="biostat-203b-2022winter",dataset ="mimic4_v1_0_203b",billing ="biostat-203b-2022winter")con
We only keep the first ICU stay. Following code is kind of a hack, using the summarise_all(min) function. It seems that slice_min(), slice_head(), distinct(, .keep_all = TRUE) don’t work with dbplyr+bigrquery at the moment.
Put things together. This step is similar to Q7 of HW2. Using one chain of pipes %>% to perform following data wrangling steps: (i) start with the icustays_tble for the first ICU stay of each unique patient, (ii) merge in admissions and patients tables, (iii) keep adults only (age at admission >= 18), (iv) merge in the labevents and chartevents tables, (v) create an indicator for 30-day mortality, (vi) save the final tibble to an icu_cohort.rds R data file in the mimiciv_shiny folder.
# make a directory mimiciv_shinyif (!dir.exists("mimiciv_shiny")) {dir.create("mimiciv_shiny")}
# # TODO# icu_cohort <- icustays_tble %>% ...
Close database connection and clear workspace.
dbDisconnect(con)rm(list =ls())
2 Q2. Shiny app
Develop a Shiny app for exploring the ICU cohort data created in Q1. The app should reside in the mimiciv_shiny folder. The app should provide easy access to the graphical and numerical summaries of variables (demographics, lab measurements, vitals) in the ICU cohort.