apply_macro_dict | R Documentation |
The variable label attribute will be applied to the data frame from the DLU file.
apply_macro_dict(
data,
dlu,
clu = NULL,
date_format = "%d/%m/%Y",
clean_names = TRUE,
rm_empty = getOption("cctu_rm_empty", default = "both"),
check_catvar = FALSE
)
data |
Data frame to be applied. |
dlu |
Data frame of DLU, see |
clu |
Data frame of CLU, see details for the requirements of CLU. |
date_format |
Date format to be converted, default is '%d/%m/%Y'. |
clean_names |
Conver variable name to lower case (default), this will also change the
values in the DLU as well. See |
rm_empty |
Remove empty |
check_catvar |
Check values of the category variable (defined in the DLU file) contain any non-numeric values before converting variables to numeric. |
This function first convert the data to a data.table
.
This is to avoid the variable attributes dropped by base R functions. Then it will use
the dlu file to convert the data into corresponding variable types. After the conversion
of the data, variable and value label attribute will be created for the variable,
see var_lab
) and val_lab
.
User can use lab2val
to conver value labels of the data to values if the
value label is desired. If the clean_names
is set to TRUE
, the data name
and the dl/clu will be cleaned, including the question names in the dlu. The cleaned dlu data
will be stored in the cctu
environment. This will further be used by cttab
to populate the missing report, see report_missing
. You can change this with
set_dlu
function, but it will not have any effect on this function, see
set_dlu
more details.
Please use get_dlu
to get the dlu cleaned by apply_macro_dict
or use
tidy_dlu
to clean it, which is the same function used by apply_macro_dict
to clean the DLU.
IntegerData: Convert to numeric.
Real: Convert to numeric.
Category: If there are any non-numeric characters in the variable, no conversion will be performed, otherwise convert to numeric.
Date: Convert data date format with as.Date
. The date_format
will be used to feed the as.Date
function during the conversion.
Text: Convert to character.
The CLU file contains three columns:
ShortCode: Variable name of the downloaded data.
CatCode: Category values, it represents the numeric code for an item in the CRF.
CatValue: Label of the category values, for example.
A data.table object.
var_lab
val_lab
tidy_dlu
set_dlu
data.table
clean_names
read_data
remove_blank_rows_cols
lab2val
get_dlu
# Read MACRO data
dt <- read.csv(system.file("extdata", "pilotdata.csv", package="cctu"),
colClasses = "character")
dlu <- read.csv(system.file("extdata", "pilotdata_dlu.csv", package="cctu"))
clu <- read.csv(system.file("extdata", "pilotdata_clu.csv", package="cctu"))
# Create subjid
dt$subjid <- substr(dt$USUBJID, 8, 11)
df <- apply_macro_dict(dt, dlu = dlu, clu = clu, clean_names = FALSE)
# Following can give you the same dlu file used by apply_macro_dict
dlu <- tidy_dlu(dlu, clean_names = FALSE)
# Extract data from Lab form
lb <- extract_form(df, "Lab")
# Extract screening visit data from lab form
lb_base <- extract_form(df, "Lab", visit = "SCREENING")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.