---
title: "variables worksheet"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{variables.csv}     
  %\VignetteEngine{knitr::rmarkdown} 
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
source("../R/test_data_generator.R")
```

## Introduction

The `variables` worksheet acts as a reference sheet your project(s), by listing the variables you are using. 

This vignette describes how the `variables` worksheet is organized and how to find variables that you can transform. The [How to guides](../how_to/recode_variables.html) provides examples of how to use the this. 

Read the `variables` worksheet

```{r Read variables.csv, echo=FALSE, message=FALSE, warning=FALSE}
cat("There are", nrow(variables), "variables, grouped in", sum(!duplicated(variables$section)), "sections and", sum(!duplicated(variables$subject)), "subjects that are available for transformation.")

```

```{r, echo=FALSE}
cat("You can search for variables in the table below. Try searching for the lab tests. There are", sum(variables$subject == "lab test"),
    "variables are in the lab test subject. 
    
    Try sorting the subject column by clicking the up beside the `subject` heading: the top", sum(variables$subject == "lab test"),
    "rows of the table should show the lab tests variables:") 

as.character(variables[variables$subject == "lab test", "variable"])
```

```{r echo=FALSE, results='asis', warning=FALSE}
library(DT)
datatable(variables, filter = 'top', options = list(pageLength = 5))
```

## How the `variables.csv` sheet is organized

There are 8 columns in this worksheet as follows:

1. **variable:** the name of the final transformed variable.

2. **label:** the shorthand label for the variable.

3. **labelLong:** a more detailed label for the variable.

4. **section:** the section where this variable could be found (i.e. demographic, lab test).

5. **subject:** what the variable pertains to (i.e. age, sex, cholestral concentration).

6. **variableType:** whether the final variable is categorical or continuous.

7. **units:** any units for the final variable.

8. **databaseStart:** the list of databases that contain the variable of interest

9. **variableStart:** the original names of the variables as they are listed in each respective database

## Derived Variables

Derived variables follow the same naming conventions as recoded variables when listed in `variables` worksheet. 


