Commit 69abd6dc authored by Kevin Kunzmann's avatar Kevin Kunzmann

Got rid of automatic downlaod - database is not stable; switched to renv...

Got rid of automatic downlaod - database is not stable; switched to renv instead of containers; reconciled all remaining code in single .Rmd; fixed minor data cleaning issues related to exclusion of individuals dying pre - 6 months and exclusion of observations past 18 months.
parent 85cc70c8
source("renv/activate.R")
......@@ -5,3 +5,7 @@ output
container.sif
*.Rproj
*.Rhistory
*_cache
*_files
*.csv
singularity: "container.sif"
configfile: "config/snakemake.yml"
rule download:
input:
config = "config/snakemake.yml",
links = "config/tbl_download_links.csv",
script = "scripts/download-data-table.R"
output:
csv = expand("{datapath}/tbl_gose_imputation.csv",
datapath = config["datapath"])
shell:
"""
mkdir -p {config[datapath]}
Rscript scripts/download-data-table.R $NEUROBOT_USR $NEUROBOT_API {config[neurobot_staging_version]} gose_imputation
mv tbl_gose_imputation.csv {output.csv}
"""
rule check_inputs:
input:
csv = expand("{datapath}/tbl_gose_imputation.csv",
datapath = config["datapath"]
),
script = "scripts/check-inputs.R"
shell:
"""
Rscript scripts/check-inputs.R {config[datapath]}/tbl_gose_imputation.csv
"""
rule impute:
input:
config = "config/snakemake.yml",
csv = expand("{datapath}/tbl_gose_imputation.csv",
datapath = config["datapath"]
),
rmd = "imputation-report.Rmd"
output:
html = "output/imputation-report.html",
csv = "output/tbl_imputed_gose.csv"
shell:
"""
Rscript scripts/check-inputs.R {config[datapath]}/tbl_gose_imputation.csv
mkdir -p output
Rscript -e "rmarkdown::render(\\"{input.rmd}\\")"
mv tbl_imputed_gose.csv {output.csv}
mv imputation-report.html {output.html}
"""
neurobot_staging_version: "1.2"
datapath: "data"
seed: 42
age_range: [0.0, 999.0] # years
per_protocol_window: [150.0, 240] # 5-8 months post injury, in days
version,tbl_name,download_link
1.2,gose_imputation,_5cd57b826b34316c8c728416
Bootstrap: docker
From: rocker/verse:latest
%labels
Maintainer Kevin Kunzmann kevin.kunzmann@mrc-bsu.cam.ac.uk
%help
CENTER-TBI 6 months GOSe outcome imputation,
cf. https://git.center-tbi.eu/kunzmann/gose-6mo-imputation for details.
%post
apt-get update
apt-get -y install curl python3-pip
pip3 install snakemake
R -e "devtools::install_github('tidyverse/tidyr')"
R -e "install.packages('diagram')"
R -e "install.packages('caret')"
R -e "install.packages('e1071')"
R -e "install.packages('msm')"
---
title: "Extract and prepare data"
title: "Impute 6-months GOSe for CENTER-TBI"
date: "`r Sys.time()`"
author: "Kevin Kunzmann (kevin.kunzmann@mrc-bsu.cam.ac.uk)"
output: html_document
output:
html_document:
code_folding: hide
params:
config: "config/snakemake.yml"
seed: 42
age_range: !r c(0, Inf)
per_protocol_window: !r c(150.0, 240)
---
The markdown file requires the recorded GOSe values in a .csv file
names `tbl_gose.csv` in the same folder.
The .csv file must contain the Neurobot variables
```
subjectId
Outcomes.DerivedCompositeGOSE
Outcomes.DerivedCompositeGOSEDaysPostInjury
Subject.Age
Subject.PatientType
Subject.DeathDate
```
in exactly that order.
At the time of writing this report the newest staging data set could be
accessed via the saved link `https://neurobot-stage.incf.org/_5f476d41eedb867816a10376`.
```{r setup}
options(tidyverse.quiet = TRUE)
library(tidyverse)
The required R environment can be installed by
```
install.packages("renv")
renv::restore(clean = TRUE, prompt = FALSE)
```
config <- yaml::read_yaml(params$config)
print(config)
```{r setup}
suppressPackageStartupMessages({
library(tidyverse)
library(msm)
})
knitr::opts_chunk$set(
echo = TRUE
# cache = TRUE, # uncomment this line to activate caching of the report
echo = TRUE
)
set.seed(config$seed)
set.seed(params$seed)
```
```{r print-params}
print(params)
```
```{r load-data}
tbl_combined <- readr::read_csv(
sprintf('%s/tbl_gose_imputation.csv', config$datapath),
# check data
varnames <- c(
"subjectId",
"Outcomes.DerivedCompositeGOSE",
"Outcomes.DerivedCompositeGOSEDaysPostInjury",
"Subject.Age",
"Subject.PatientType",
"Subject.DeathDate"
)
colnames <- readr::read_csv(
"tbl_gose.csv",
n_max = 1,
col_types = "cinncD"
) %>%
) %>%
names
if (!all(colnames == varnames))
stop("colnames do not match varnames, check order!")
tbl_combined <- readr::read_csv("tbl_gose.csv", col_types = "cinncD") %>%
rename(gupi = subjectId) %>%
filter(
# throw out all rows with missing GOSE
!is.na(Outcomes.DerivedCompositeGOSE),
# throw out all observations without a precise timestamp
!is.na(Outcomes.DerivedCompositeGOSEDaysPostInjury)
!is.na(Outcomes.DerivedCompositeGOSEDaysPostInjury),
# throw out all observations after 18 months
# (for 12 months imputation!)
Outcomes.DerivedCompositeGOSEDaysPostInjury < 18*30
) %>%
mutate(
Subject.PatientType = case_when(
......@@ -56,8 +107,7 @@ tbl_combined <- tbl_combined %>%
) %>%
ungroup() %>%
filter(
!is.na(death_days),
death_days > 180
!is.na(death_days)
) %>%
mutate(
Outcomes.DerivedCompositeGOSEDaysPostInjury = death_days,
......@@ -85,11 +135,11 @@ tbl_combined <- tbl_combined %>%
tbl_combined <- tbl_combined %>%
group_by(gupi) %>%
filter(
# all GOSEs before 180 dayspost injury must be > 1 (dead)
# all GOSEs before 180 days post injury must be > 1 (dead)
all(Outcomes.DerivedCompositeGOSE[Outcomes.DerivedCompositeGOSEDaysPostInjury <= 180] > 1),
# ensure age-bracket
Subject.Age >= config$age_range[1],
Subject.Age <= config$age_range[2],
Subject.Age >= params$age_range[1],
Subject.Age <= params$age_range[2],
# censor at first GOSE == 1
all(Outcomes.DerivedCompositeGOSE > 1) | (row_number() <= which(Outcomes.DerivedCompositeGOSE == 1)[1])
) %>%
......@@ -106,7 +156,7 @@ tbl_combined$Outcomes.DerivedCompositeGOSE %>% table
# Impute
```{r impute}
```{r impute, results='hide', warning=FALSE}
tbl_gose_msm <- tbl_combined %>%
select(
gupi,
......@@ -123,7 +173,7 @@ tbl_gose_msm <- tbl_combined %>%
)
) %>%
mutate(
# all deaths are excatly observed time - tell MSM!
# all deaths are excactly observed time - tell MSM!
observation_type = ifelse(gose == 1, 3, 1),
# recode levels to 1:7, 99 (needed for MSM!)
gose = factor(gose,
......@@ -162,7 +212,7 @@ fit <- msm::msm(
censor.states = 2:7, # cannot be dead since these were filtered previously
control = list(
fnscale = 12000,
maxit = 10^4,
maxit = 10,# 10^4,
trace = 2
)
)
......@@ -204,9 +254,10 @@ tbl_posteriors <- tibble(
```{r final-imputations}
# start by adding confirmed <= 180d deaths back in
tbl_final_imputations <- readr::read_csv(
sprintf('%s/tbl_gose_imputation.csv', config$datapath),
"tbl_gose.csv",
col_types = "cinncD"
) %>%
rename(gupi = subjectId) %>%
select(gupi, Subject.DeathDate) %>%
distinct %>%
transmute(
......@@ -245,9 +296,10 @@ tbl_final_imputations <- readr::read_csv(
left_join(
# add new column giving priority to per-protocol gose
readr::read_csv(
sprintf('%s/tbl_gose_imputation.csv', config$datapath),
"tbl_gose.csv",
col_types = "cinncD"
) %>%
rename(gupi = subjectId) %>%
transmute(
gupi = gupi,
gose = Outcomes.DerivedCompositeGOSE,
......@@ -255,13 +307,14 @@ tbl_final_imputations <- readr::read_csv(
) %>%
filter(
complete.cases(.),
days >= config$per_protocol_window[1],
days <= config$per_protocol_window[2]
days >= params$per_protocol_window[1],
days <= params$per_protocol_window[2]
) %>%
group_by(gupi) %>%
summarize(
gose = gose[which.min(abs(days - 180))],
days = days[which.min(abs(days - 180))]
days = days[which.min(abs(days - 180))],
.groups = "drop"
) %>%
transmute(
gupi,
......@@ -275,7 +328,7 @@ tbl_final_imputations <- readr::read_csv(
) %>%
mutate(
# gose_map_imputed is only 1 when we know that the individual died before
# 6 months, i.e. in these cases the per-protocol gose shoul also be 1
# 6 months, i.e. in these cases the per-protocol gose should also be 1
gose_per_protocol = ifelse(gose_map_imputed == "1", "1", gose_per_protocol),
gose_map_per_protocol_combined = ifelse(
is.na(gose_per_protocol),
......@@ -310,7 +363,7 @@ tbl_final_imputations %>%
data = .$gose_map_imputed,
reference = .$gose_per_protocol
)$table} %>%
broom::tidy() %>%
as_tibble() %>%
rename(
`GOSe, MAP imputed` = Prediction,
`GOSe, closest per-protocol` = Reference
......@@ -324,10 +377,6 @@ tbl_final_imputations %>%
ggtitle("Confusion matrix: imputed vs. per-protocol")
```
# Save
```{r save-imputed-values}
tbl_final_imputations %>% {
tmp <- .
......@@ -336,7 +385,7 @@ tbl_final_imputations %>% {
rename(
"Subject.GOSE6monthEndpointDerived" = "Subject.DerivedImputed180DaysGOSE_map_per_protocol_combined"
) %>%
write_csv("tbl_imputed_gose.csv")
write_csv("tbl_gose_imputed.csv")
```
......@@ -344,5 +393,6 @@ tbl_final_imputations %>% {
# Session Info
```{r session-info}
sessionInfo()
sessionInfo() %>%
knitr::kable()
```
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"R": {
"Version": "4.0.2",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cran.rstudio.com"
}
]
},
"Packages": {
"BH": {
"Package": "BH",
"Version": "1.72.0-3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "8f9ce74c6417d61f0782cbae5fd2b7b0"
},
"DBI": {
"Package": "DBI",
"Version": "1.1.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "4744be45519d675af66c28478720fce5"
},
"KernSmooth": {
"Package": "KernSmooth",
"Version": "2.23-17",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "bbff70c8c0357b5b88238c83f680fcd3"
},
"MASS": {
"Package": "MASS",
"Version": "7.3-51.6",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "1dad32ac9dbd8057167b2979fb932ff7"
},
"Matrix": {
"Package": "Matrix",
"Version": "1.2-18",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "08588806cba69f04797dab50627428ed"
},
"ModelMetrics": {
"Package": "ModelMetrics",
"Version": "1.2.2.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "40a55bd0b44719941d103291ac5e9d74"
},
"R6": {
"Package": "R6",
"Version": "2.4.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "292b54f8f4b94669b08f94e5acce6be2"
},
"RColorBrewer": {
"Package": "RColorBrewer",
"Version": "1.1-2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "e031418365a7f7a766181ab5a41a5716"
},
"Rcpp": {
"Package": "Rcpp",
"Version": "1.0.5",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "125dc7a0ed375eb68c0ce533b48d291f"
},
"SQUAREM": {
"Package": "SQUAREM",
"Version": "2020.3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "e08d8c8eec7eb52ff6c12bd2cd0897b6"
},
"askpass": {
"Package": "askpass",
"Version": "1.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "e8a22846fff485f0be3770c2da758713"
},
"assertthat": {
"Package": "assertthat",
"Version": "0.2.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "50c838a310445e954bc13f26f26a6ecf"
},
"backports": {
"Package": "backports",
"Version": "1.1.8",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "3ef0eac19317fd03c0c854aed581d473"
},
"base64enc": {
"Package": "base64enc",
"Version": "0.1-3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "543776ae6848fde2f48ff3816d0628bc"
},
"blob": {
"Package": "blob",
"Version": "1.2.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "9addc7e2c5954eca5719928131fed98c"
},
"broom": {
"Package": "broom",
"Version": "0.7.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "2ca5ae42f3bfd149504d63c833c2be26"
},
"callr": {
"Package": "callr",
"Version": "3.4.3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "643163a00cb536454c624883a10ae0bc"
},
"caret": {
"Package": "caret",
"Version": "6.0-86",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "77b0545e2c16b4e57c8da2d14042b28d"
},
"cellranger": {
"Package": "cellranger",
"Version": "1.1.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "f61dbaec772ccd2e17705c1e872e9e7c"
},
"class": {
"Package": "class",
"Version": "7.3-17",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "9267f5dab59a4ef44229858a142bded1"
},
"cli": {
"Package": "cli",
"Version": "2.0.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "ff0becff7bfdfe3f75d29aff8f3172dd"
},
"clipr": {
"Package": "clipr",
"Version": "0.7.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "08cf4045c149a0f0eaf405324c7495bd"
},
"codetools": {
"Package": "codetools",
"Version": "0.2-16",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "89cf4b8207269ccf82fbeb6473fd662b"
},
"colorspace": {
"Package": "colorspace",
"Version": "1.4-1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "6b436e95723d1f0e861224dd9b094dfb"
},
"cpp11": {
"Package": "cpp11",
"Version": "0.1.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "07ac25dbe65bfa02deac8ec3bf74fdd2"
},
"crayon": {
"Package": "crayon",
"Version": "1.3.4",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "0d57bc8e27b7ba9e45dba825ebc0de6b"
},
"curl": {
"Package": "curl",
"Version": "4.3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "2b7d10581cc730804e9ed178c8374bd6"
},
"data.table": {
"Package": "data.table",
"Version": "1.12.8",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "cd711af60c47207a776213a368626369"
},
"dbplyr": {
"Package": "dbplyr",
"Version": "1.4.4",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "2ba60a82dd9b6ca3cee0d8e2574cdf0e"
},
"desc": {
"Package": "desc",
"Version": "1.2.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "6c8fe8fa26a23b79949375d372c7b395"
},
"digest": {
"Package": "digest",
"Version": "0.6.25",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "f697db7d92b7028c4b3436e9603fb636"
},
"dplyr": {
"Package": "dplyr",
"Version": "1.0.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "018b2fc43cb25d9f07241986c53fbf8e"
},
"ellipsis": {
"Package": "ellipsis",
"Version": "0.3.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "fd2844b3a43ae2d27e70ece2df1b4e2a"
},
"evaluate": {
"Package": "evaluate",
"Version": "0.14",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "ec8ca05cffcc70569eaaad8469d2a3a7"
},
"expm": {
"Package": "expm",
"Version": "0.999-5",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "6da939036c445e851f7ef690e349cc2c"
},
"fansi": {
"Package": "fansi",
"Version": "0.4.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "7fce217eaaf8016e72065e85c73027b5"
},
"farver": {
"Package": "farver",
"Version": "2.0.3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "dad6793a5a1f73c8e91f1a1e3e834b05"
},
"forcats": {
"Package": "forcats",
"Version": "0.5.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "1cb4279e697650f0bd78cd3601ee7576"
},
"foreach": {
"Package": "foreach",
"Version": "1.5.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "8fb3ff01ee7d85893f56df8d77213381"
},
"fs": {
"Package": "fs",
"Version": "1.4.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "8c04112383ca1988e96f429255f95675"
},
"generics": {
"Package": "generics",
"Version": "0.0.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "b8cff1d1391fd1ad8b65877f4c7f2e53"
},
"ggplot2": {
"Package": "ggplot2",
"Version": "3.3.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "4ded8b439797f7b1693bd3d238d0106b"
},
"glue": {
"Package": "glue",
"Version": "1.4.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "f43e0d5e85ccb0a4045670c0607ee504"
},
"gower": {
"Package": "gower",
"Version": "0.2.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "be6a2b3529928bd803d1c437d1d43152"
},
"gtable": {
"Package": "gtable",
"Version": "0.3.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "ac5c6baf7822ce8732b343f14c072c4d"
},
"haven": {
"Package": "haven",
"Version": "2.3.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "221d0ad75dfa03ebf17b1a4cc5c31dfc"
},
"highr": {
"Package": "highr",
"Version": "0.8",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "4dc5bb88961e347a0f4d8aad597cbfac"
},
"hms": {
"Package": "hms",
"Version": "0.5.3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "726671f634529d470545f9fd1a9d1869"
},
"htmltools": {
"Package": "htmltools",
"Version": "0.5.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "7d651b7131794fe007b1ad6f21aaa401"
},
"httr": {
"Package": "httr",
"Version": "1.4.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "7146fea4685b4252ebf478978c75f597"
},
"ipred": {
"Package": "ipred",
"Version": "0.9-9",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "816a7f746179f159f8faa87af730f3c1"
},
"isoband": {
"Package": "isoband",
"Version": "0.2.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "6e58bd3d6b3dd82a944cd6f05ade228f"
},
"iterators": {
"Package": "iterators",
"Version": "1.0.12",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "117128f48662573ff4c4e72608b9e202"
},
"jsonlite": {
"Package": "jsonlite",
"Version": "1.7.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "2657f20b9a74c996c602e74ebe540b06"
},
"knitr": {
"Package": "knitr",
"Version": "1.29",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "e5f4c41c17df8cdf7b0df12117c0d99a"
},
"labeling": {
"Package": "labeling",
"Version": "0.3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "73832978c1de350df58108c745ed0e3e"
},
"lattice": {
"Package": "lattice",
"Version": "0.20-41",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "fbd9285028b0263d76d18c95ae51a53d"
},
"lava": {
"Package": "lava",
"Version": "1.6.7",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "e9a046d514942f36bf8ae2a5e3ded35f"
},
"lifecycle": {
"Package": "lifecycle",
"Version": "0.2.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "361811f31f71f8a617a9a68bf63f1f42"
},
"lubridate": {
"Package": "lubridate",
"Version": "1.7.9",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "fc1c91e2e8d9e1fc932e75aa1ed989b7"
},
"magrittr": {
"Package": "magrittr",
"Version": "1.5",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "1bb58822a20301cee84a41678e25d9b7"
},
"markdown": {
"Package": "markdown",
"Version": "1.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "61e4a10781dd00d7d81dd06ca9b94e95"
},
"mgcv": {
"Package": "mgcv",
"Version": "1.8-31",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "4bb7e0c4f3557583e1e8d3c9ffb8ba5c"
},
"mime": {
"Package": "mime",
"Version": "0.9",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "e87a35ec73b157552814869f45a63aa3"
},
"modelr": {
"Package": "modelr",
"Version": "0.1.8",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "9fd59716311ee82cba83dc2826fc5577"
},
"msm": {
"Package": "msm",
"Version": "1.6.8",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "5458188099f0deae645462e550345c8b"
},
"munsell": {
"Package": "munsell",
"Version": "0.5.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "6dfe8bf774944bd5595785e3229d8771"
},
"mvtnorm": {
"Package": "mvtnorm",
"Version": "1.1-1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "69fa7331e7410c2a2cb3f9868513904f"
},
"nlme": {
"Package": "nlme",
"Version": "3.1-148",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "662f52871983ff3e3ef042c62de126df"
},
"nnet": {
"Package": "nnet",
"Version": "7.3-14",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "0d87e50e11394a7151a28873637d799a"
},
"numDeriv": {
"Package": "numDeriv",
"Version": "2016.8-1.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "df58958f293b166e4ab885ebcad90e02"
},
"openssl": {
"Package": "openssl",
"Version": "1.4.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "b3209c62052922b6c629544d94c8fa8a"
},
"pROC": {
"Package": "pROC",
"Version": "1.16.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "285ca01e793958ac6f2c264c84dbb16b"
},
"pillar": {
"Package": "pillar",
"Version": "1.4.6",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "bdf26e55ccb7df3e49a490150277f002"
},
"pkgbuild": {
"Package": "pkgbuild",
"Version": "1.0.8",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "8d8b5e29223aabb829246397299f0592"
},
"pkgconfig": {
"Package": "pkgconfig",
"Version": "2.0.3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "01f28d4278f15c76cddbea05899c5d6f"
},
"pkgload": {
"Package": "pkgload",
"Version": "1.1.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "b6b150cd4709e0c0c9b5d51ac4376282"
},
"plyr": {
"Package": "plyr",
"Version": "1.8.6",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "ec0e5ab4e5f851f6ef32cd1d1984957f"
},
"praise": {
"Package": "praise",
"Version": "1.0.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "a555924add98c99d2f411e37e7d25e9f"
},
"prettyunits": {
"Package": "prettyunits",
"Version": "1.1.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "95ef9167b75dde9d2ccc3c7528393e7e"
},
"processx": {
"Package": "processx",
"Version": "3.4.3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "f4f13345fcb00c51ace12f65dd18749f"
},
"prodlim": {
"Package": "prodlim",
"Version": "2019.11.13",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "c243bf70db3a6631a0c8783152fb7db9"
},
"progress": {
"Package": "progress",
"Version": "1.2.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "14dc9f7a3c91ebb14ec5bb9208a07061"
},
"ps": {
"Package": "ps",
"Version": "1.3.3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "425d938eb9c02906a8ac98c0c2a306b5"
},
"purrr": {
"Package": "purrr",
"Version": "0.3.4",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "97def703420c8ab10d8f0e6c72101e02"
},
"readr": {
"Package": "readr",
"Version": "1.3.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "af8ab99cd936773a148963905736907b"
},
"readxl": {
"Package": "readxl",
"Version": "1.3.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "63537c483c2dbec8d9e3183b3735254a"
},
"recipes": {
"Package": "recipes",
"Version": "0.1.13",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "f3ce68cd2bd38e508cbdcbec44c15d46"
},
"rematch": {
"Package": "rematch",
"Version": "1.0.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "c66b930d20bb6d858cd18e1cebcfae5c"
},
"renv": {
"Package": "renv",
"Version": "0.11.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "1c3ef87cbb81c23ac96797781ec7aecc"
},
"reprex": {
"Package": "reprex",
"Version": "0.3.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "b06bfb3504cc8a4579fd5567646f745b"
},
"reshape2": {
"Package": "reshape2",
"Version": "1.4.4",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "bb5996d0bd962d214a11140d77589917"
},
"rlang": {
"Package": "rlang",
"Version": "0.4.7",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "c06d2a6887f4b414f8e927afd9ee976a"
},
"rmarkdown": {
"Package": "rmarkdown",
"Version": "2.3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "202260e1b2c410edc086d5b8f1ed946e"
},
"rpart": {
"Package": "rpart",
"Version": "4.1-15",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "9787c1fcb680e655d062e7611cadf78e"
},
"rprojroot": {
"Package": "rprojroot",
"Version": "1.3-2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "f6a407ae5dd21f6f80a6708bbb6eb3ae"
},
"rstudioapi": {
"Package": "rstudioapi",
"Version": "0.11",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "33a5b27a03da82ac4b1d43268f80088a"
},
"rvest": {
"Package": "rvest",
"Version": "0.3.5",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "6a20c2cdf133ebc7ac45888c9ccc052b"
},
"scales": {
"Package": "scales",
"Version": "1.1.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "6f76f71042411426ec8df6c54f34e6dd"
},
"selectr": {
"Package": "selectr",
"Version": "0.4-2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "3838071b66e0c566d55cc26bd6e27bf4"
},
"stringi": {
"Package": "stringi",
"Version": "1.4.6",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "e99d8d656980d2dd416a962ae55aec90"
},
"stringr": {
"Package": "stringr",
"Version": "1.4.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "0759e6b6c0957edb1311028a49a35e76"
},
"survival": {
"Package": "survival",
"Version": "3.1-12",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "1c5bb53bd428f3c42a25b7aeb983d8c7"
},
"sys": {
"Package": "sys",
"Version": "3.3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "507f3116a38d37ad330a038b3be07b66"
},
"testthat": {
"Package": "testthat",
"Version": "2.3.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "0829b987b8961fb07f3b1b64a2fbc495"
},
"tibble": {
"Package": "tibble",
"Version": "3.0.3",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "08bd36bd34b20d4f7971d49e81deaab0"
},
"tidyr": {
"Package": "tidyr",
"Version": "1.1.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "a0d8d887f9887f668e3d54d1b820c2a2"
},
"tidyselect": {
"Package": "tidyselect",
"Version": "1.1.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "6ea435c354e8448819627cf686f66e0a"
},
"tidyverse": {
"Package": "tidyverse",
"Version": "1.3.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "bd51be662f359fa99021f3d51e911490"
},
"timeDate": {
"Package": "timeDate",
"Version": "3043.102",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "fde4fc571f5f61978652c229d4713845"
},
"tinytex": {
"Package": "tinytex",
"Version": "0.24",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "8f24b65b86f4d6d7b1e2d8a4ce2c02fb"
},
"utf8": {
"Package": "utf8",
"Version": "1.1.4",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "4a5081acfb7b81a572e4384a7aaf2af1"
},
"vctrs": {
"Package": "vctrs",
"Version": "0.3.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "5ba3006888ac62fd5e97b208d00d3317"
},
"viridisLite": {
"Package": "viridisLite",
"Version": "0.3.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "ce4f6271baa94776db692f1cb2055bee"
},
"whisker": {
"Package": "whisker",
"Version": "0.4",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "ca970b96d894e90397ed20637a0c1bbe"
},
"withr": {
"Package": "withr",
"Version": "2.2.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "ecd17882a0b4419545691e095b74ee89"
},
"xfun": {
"Package": "xfun",
"Version": "0.15",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "ddeca7650052ff9131ac7c41a9a77b3b"
},
"xml2": {
"Package": "xml2",
"Version": "1.3.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "d4d71a75dd3ea9eb5fa28cc21f9585e2"
},
"yaml": {
"Package": "yaml",
"Version": "2.2.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "2826c5d9efb0a88f657c7a679c7106db"
}
}
}
library/
python/
staging/
local({
# the requested version of renv
version <- "0.11.0"
# the project directory
project <- getwd()
# avoid recursion
if (!is.na(Sys.getenv("RENV_R_INITIALIZING", unset = NA)))
return(invisible(TRUE))
# signal that we're loading renv during R startup
Sys.setenv("RENV_R_INITIALIZING" = "true")
on.exit(Sys.unsetenv("RENV_R_INITIALIZING"), add = TRUE)
# signal that we've consented to use renv
options(renv.consent = TRUE)
# load the 'utils' package eagerly -- this ensures that renv shims, which
# mask 'utils' packages, will come first on the search path
library(utils, lib.loc = .Library)
# check to see if renv has already been loaded
if ("renv" %in% loadedNamespaces()) {
# if renv has already been loaded, and it's the requested version of renv,
# nothing to do
spec <- .getNamespaceInfo(.getNamespace("renv"), "spec")
if (identical(spec[["version"]], version))
return(invisible(TRUE))
# otherwise, unload and attempt to load the correct version of renv
unloadNamespace("renv")
}
# load bootstrap tools
bootstrap <- function(version, library) {
# read repos (respecting override if set)
repos <- Sys.getenv("RENV_CONFIG_REPOS_OVERRIDE", unset = NA)
if (is.na(repos))
repos <- getOption("repos")
# fix up repos
on.exit(options(repos = repos), add = TRUE)
repos[repos == "@CRAN@"] <- "https://cloud.r-project.org"
options(repos = repos)
# attempt to download renv
tarball <- tryCatch(renv_bootstrap_download(version), error = identity)
if (inherits(tarball, "error"))
stop("failed to download renv ", version)
# now attempt to install
status <- tryCatch(renv_bootstrap_install(version, tarball, library), error = identity)
if (inherits(status, "error"))
stop("failed to install renv ", version)
}
renv_bootstrap_download_impl <- function(url, destfile) {
mode <- "wb"
# https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17715
fixup <-
Sys.info()[["sysname"]] == "Windows" &&
substring(url, 1L, 5L) == "file:"
if (fixup)
mode <- "w+b"
download.file(
url = url,
destfile = destfile,
mode = mode,
quiet = TRUE
)
}
renv_bootstrap_download <- function(version) {
methods <- list(
renv_bootstrap_download_cran_latest,
renv_bootstrap_download_cran_archive,
renv_bootstrap_download_github
)
for (method in methods) {
path <- tryCatch(method(version), error = identity)
if (is.character(path) && file.exists(path))
return(path)
}
stop("failed to download renv ", version)
}
renv_bootstrap_download_cran_latest <- function(version) {
# check for renv on CRAN matching this version
db <- as.data.frame(available.packages(), stringsAsFactors = FALSE)
entry <- db[db$Package %in% "renv" & db$Version %in% version, ]
if (nrow(entry) == 0) {
fmt <- "renv %s is not available from your declared package repositories"
stop(sprintf(fmt, version))
}
message("* Downloading renv ", version, " from CRAN ... ", appendLF = FALSE)
info <- tryCatch(
download.packages("renv", destdir = tempdir()),
condition = identity
)
if (inherits(info, "condition")) {
message("FAILED")
return(FALSE)
}
message("OK")
info[1, 2]
}
renv_bootstrap_download_cran_archive <- function(version) {
name <- sprintf("renv_%s.tar.gz", version)
repos <- getOption("repos")
urls <- file.path(repos, "src/contrib/Archive/renv", name)
destfile <- file.path(tempdir(), name)
message("* Downloading renv ", version, " from CRAN archive ... ", appendLF = FALSE)
for (url in urls) {
status <- tryCatch(
renv_bootstrap_download_impl(url, destfile),
condition = identity
)
if (identical(status, 0L)) {
message("OK")
return(destfile)
}
}
message("FAILED")
return(FALSE)
}
renv_bootstrap_download_github <- function(version) {
enabled <- Sys.getenv("RENV_BOOTSTRAP_FROM_GITHUB", unset = "TRUE")
if (!identical(enabled, "TRUE"))
return(FALSE)
# prepare download options
pat <- Sys.getenv("GITHUB_PAT")
if (nzchar(Sys.which("curl")) && nzchar(pat)) {
fmt <- "--location --fail --header \"Authorization: token %s\""
extra <- sprintf(fmt, pat)
saved <- options("download.file.method", "download.file.extra")
options(download.file.method = "curl", download.file.extra = extra)
on.exit(do.call(base::options, saved), add = TRUE)
} else if (nzchar(Sys.which("wget")) && nzchar(pat)) {
fmt <- "--header=\"Authorization: token %s\""
extra <- sprintf(fmt, pat)
saved <- options("download.file.method", "download.file.extra")
options(download.file.method = "wget", download.file.extra = extra)
on.exit(do.call(base::options, saved), add = TRUE)
}
message("* Downloading renv ", version, " from GitHub ... ", appendLF = FALSE)
url <- file.path("https://api.github.com/repos/rstudio/renv/tarball", version)
name <- sprintf("renv_%s.tar.gz", version)
destfile <- file.path(tempdir(), name)
status <- tryCatch(
renv_bootstrap_download_impl(url, destfile),
condition = identity
)
if (!identical(status, 0L)) {
message("FAILED")
return(FALSE)
}
message("Done!")
return(destfile)
}
renv_bootstrap_install <- function(version, tarball, library) {
# attempt to install it into project library
message("* Installing renv ", version, " ... ", appendLF = FALSE)
dir.create(library, showWarnings = FALSE, recursive = TRUE)
# invoke using system2 so we can capture and report output
bin <- R.home("bin")
exe <- if (Sys.info()[["sysname"]] == "Windows") "R.exe" else "R"
r <- file.path(bin, exe)
args <- c("--vanilla", "CMD", "INSTALL", "-l", shQuote(library), shQuote(tarball))
output <- system2(r, args, stdout = TRUE, stderr = TRUE)
message("Done!")
# check for successful install
status <- attr(output, "status")
if (is.numeric(status) && !identical(status, 0L)) {
header <- "Error installing renv:"
lines <- paste(rep.int("=", nchar(header)), collapse = "")
text <- c(header, lines, output)
writeLines(text, con = stderr())
}
status
}
renv_bootstrap_prefix <- function() {
# construct version prefix
version <- paste(R.version$major, R.version$minor, sep = ".")
prefix <- paste("R", numeric_version(version)[1, 1:2], sep = "-")
# include SVN revision for development versions of R
# (to avoid sharing platform-specific artefacts with released versions of R)
devel <-
identical(R.version[["status"]], "Under development (unstable)") ||
identical(R.version[["nickname"]], "Unsuffered Consequences")
if (devel)
prefix <- paste(prefix, R.version[["svn rev"]], sep = "-r")
# build list of path components
components <- c(prefix, R.version$platform)
# include prefix if provided by user
prefix <- Sys.getenv("RENV_PATHS_PREFIX")
if (nzchar(prefix))
components <- c(prefix, components)
# build prefix
paste(components, collapse = "/")
}
renv_bootstrap_library_root <- function(project) {
path <- Sys.getenv("RENV_PATHS_LIBRARY", unset = NA)
if (!is.na(path))
return(path)
path <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT", unset = NA)
if (!is.na(path))
return(file.path(path, basename(project)))
file.path(project, "renv/library")
}
renv_bootstrap_validate_version <- function(version) {
loadedversion <- utils::packageDescription("renv", fields = "Version")
if (version == loadedversion)
return(TRUE)
# assume four-component versions are from GitHub; three-component
# versions are from CRAN
components <- strsplit(loadedversion, "[.-]")[[1]]
remote <- if (length(components) == 4L)
paste("rstudio/renv", loadedversion, sep = "@")
else
paste("renv", loadedversion, sep = "@")
fmt <- paste(
"renv %1$s was loaded from project library, but renv %2$s is recorded in lockfile.",
"Use `renv::record(\"%3$s\")` to record this version in the lockfile.",
"Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.",
sep = "\n"
)
msg <- sprintf(fmt, loadedversion, version, remote)
warning(msg, call. = FALSE)
FALSE
}
renv_bootstrap_load <- function(project, libpath, version) {
# try to load renv from the project library
if (!requireNamespace("renv", lib.loc = libpath, quietly = TRUE))
return(FALSE)
# warn if the version of renv loaded does not match
renv_bootstrap_validate_version(version)
# load the project
renv::load(project)
TRUE
}
# construct path to library root
root <- renv_bootstrap_library_root(project)
# construct library prefix for platform
prefix <- renv_bootstrap_prefix()
# construct full libpath
libpath <- file.path(root, prefix)
# attempt to load
if (renv_bootstrap_load(project, libpath, version))
return(TRUE)
# load failed; attempt to bootstrap
bootstrap(version, libpath)
# exit early if we're just testing bootstrap
if (!is.na(Sys.getenv("RENV_BOOTSTRAP_INSTALL_ONLY", unset = NA)))
return(TRUE)
# try again to load
if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) {
message("Successfully installed and loaded renv ", version, ".")
return(renv::load())
}
# failed to download or load renv; warn the user
msg <- c(
"Failed to find an renv installation: the project will not be loaded.",
"Use `renv::activate()` to re-initialize the project."
)
warning(paste(msg, collapse = "\n"), call. = FALSE)
})
external.libraries:
ignored.packages:
package.dependency.fields: Imports, Depends, LinkingTo
snapshot.type: implicit
use.cache: TRUE
vcs.ignore.library: TRUE
#!/bin/bash
sudo singularity build container.sif container-recipe
#!/usr/bin/env Rscript
library(readr)
library(dplyr, warn.conflicts = FALSE)
options(warn = 2) # warnings are errors
args <- commandArgs(trailingOnly = TRUE)
input_csv <- args[[1]]
varnames <- c(
"gupi",
"Outcomes.DerivedCompositeGOSE",
"Outcomes.DerivedCompositeGOSEDaysPostInjury",
"Subject.Age",
"Subject.PatientType",
"Subject.DeathDate"
)
colnames <- readr::read_csv(
input_csv,
n_max = 1, ,
col_types = "cinncD"
) %>%
names
if (!all(colnames == varnames))
stop("colnames do not match varnames, check order!")
#!/bin/bash
set -e
wget https://zenodo.org/record/2641161/files/container.sif
checksum=($(md5sum container.sif))
if [ $checksum != 4d7edd4ff6ba7c8ff7639c53e7c6daf9 ]; then
echo md5 mismatch!
exit 1
fi
#!/usr/bin/env Rscript
library(readr)
library(dplyr, warn.conflicts = FALSE)
library(httr)
args <- commandArgs(trailingOnly = TRUE)
user <- args[[1]]
token <- args[[2]]
version <- args[[3]]
tbl_name <- args[[4]]
# load download links
tbl_download_links <- read_csv(
"config/tbl_download_links.csv",
col_types = c(
col_character(),
col_character(),
col_character()
)
)
# check uniqueness
tbl_download_links %>%
group_by(version, tbl_name) %>%
{
if (n_groups(.) < nrow(.))
stop("download links not unique, check file")
}
# extract link for query
tbl_download_link <- tbl_download_links %>%
filter(
version == get("version", envir = .GlobalEnv),
tbl_name == get("tbl_name", envir = .GlobalEnv)
) %>%
pull(download_link)
if (length(tbl_download_link) == 0)
stop("no neurobot download link for table 'tbl_%s.csv' version '%s' found", tbl_name, version)
# download csv file via neurobot api call
res <- GET(
sprintf("https://neurobot-stage.incf.org/api/data/%s.csv", tbl_download_link),
authenticate(user, token, type = "digest")
)
# check for success and save
if (res$status_code != 200)
stop(sprintf("error downloading tbl_%s.csv, http status code: %s", tbl_name, res$status_code))
writeBin(content(res, "raw"), sprintf("tbl_%s.csv", tbl_name))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment