## ----results='hide', message=FALSE, warning=FALSE-----------------------------
library(chmsflow)


## ----eval=FALSE---------------------------------------------------------------
# # Install release version from CRAN
# install.packages("chmsflow")
# 
# # Install the most recent version from GitHub
# devtools::install_github("Big-Life-Lab/chmsflow")


## ----warning=FALSE------------------------------------------------------------
library(recodeflow)

# Recode a source variable (age)
cycle4_ages <- rec_with_table(
  cycle4, "clc_age",
  variable_details = variable_details, log = TRUE
)
head(cycle4_ages)


## ----warning=FALSE------------------------------------------------------------
# Recode sex (same variable name across all cycles)
cycle4_sexes <- rec_with_table(
  cycle4, "clc_sex",
  variable_details = variable_details, log = TRUE
)
head(cycle4_sexes)


## ----warning=FALSE------------------------------------------------------------
# Recode age into 4 groups
cycle4_categorical_ages <- rec_with_table(
  cycle4, "agegroup4",
  variable_details = variable_details, log = TRUE
)
head(cycle4_categorical_ages)


## ----warning=FALSE------------------------------------------------------------
# Derive adjusted systolic blood pressure
# bpmdpbps (raw SBP) must be in the data for sbp_adj_mmhg to be computed
cycle4_adjusted_SBPs <- rec_with_table(
  cycle4, c("bpmdpbps", "sbp_adj_mmhg"),
  variable_details = variable_details, log = TRUE
)
head(cycle4_adjusted_SBPs)

