run_Demo: Run Demographic Data

View source: R/modDemo.R

run_DemoR Documentation

Run Demographic Data

Description

This module will load and modify demographic data.

Usage

run_Demo(demo.path, demo.columns = list(), toexclude, demo.mod.list)

Arguments

demo.path

filename of demographic file (CSV, RData, RDS) or data.frame

demo.columns

a named list that should specify columns in demo data; ‘id’, is required.

toexclude

expression that should evaluate to a logical, indicating if the observation should be excluded

demo.mod.list

list of expressions, giving modifications to make

Details

See EHR Vignette for Structured Data.

Value

list with two components

demo

demographic data

exclude

vector of excluded visit IDs

Examples

set.seed(2525)
dateSeq <- seq(as.Date('2019/01/01'), as.Date('2020/01/01'), by="day")
demo <- data.frame(mod_id_visit = 1:10,
                   weight.lbs = rnorm(10,160,20),
                   age = rnorm(10, 50, 10),
                   enroll.date = sample(dateSeq, 10))
tmpfile <- paste0(tempfile(), '.rds')
saveRDS(demo, file = tmpfile)

# exclusion functions
exclude_wt <- function(x) x < 150
exclude_age <- function(x) x > 60
ind.risk <- function(wt, age) wt>170 & age>55
exclude_enroll <- function(x) x < as.Date('2019/04/01')

# make demographic data that:
# (1) excludes ids with weight.lbs < 150, age > 60, or enroll.date before 2019/04/01
# (2) creates new 'highrisk' variable for subjects with weight.lbs>170 and age>55
out <- run_Demo(demo.path = tmpfile, demo.columns = list(id = 'mod_id_visit'),
               toexclude = expression(
                 exclude_wt(weight.lbs)|exclude_age(age)|exclude_enroll(enroll.date)
               ),
               demo.mod.list = list(highrisk = expression(ind.risk(weight.lbs, age))))

out



EHR documentation built on Dec. 28, 2022, 1:31 a.m.