Skip to contents

This function allows you to convert REDCap logic into R logic. WARNING: Please note that if the REDCap logic involves smart variables, this function may not be able to transform it accurately.

Usage

rd_rlogic(..., data = NULL, dic = NULL, event_form = NULL, logic, var)

Arguments

...

List containing the data, dictionary and event mapping (if applicable) of the REDCap project. This should be the output of the `redcap_data` function.

data

Data frame containing data from REDCap. If the list is specified, this argument is not required.

dic

Data frame containing the dictionary read from REDCap. If the list is specified, this argument is not required.

event_form

Data frame containing the correspondence of each event with each form. If the list is specified, this argument is not required.

logic

String containing logic in REDCap format.

var

String with the name of the variable containing the logic.

Value

List containing the logic in R format and its evaluation.

Examples

rd_rlogic(covican,
          logic = "if([exc_1]='1' or [inc_1]='0' or [inc_2]='0' or [inc_3]='0',1,0)",
          var = "screening_fail_crit")
#> $rlogic
#> [1] "ifelse(data$exc_1=='1' | data$inc_1=='0' | data$inc_2=='0' | data$inc_3=='0',1,0)"
#> 
#> $eval
#>   [1]  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0
#>  [26] NA  0 NA  0 NA  0 NA  0 NA  0  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0
#>  [51] NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0  0  0  0 NA  0  0  0  0  0  0  0
#>  [76]  0  0  0  0  0  0  0  0  0  0  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0
#> [101] NA  0 NA  0 NA  0 NA  0 NA  1  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  1
#> [126]  0 NA  0 NA  0 NA  0 NA  0 NA  0  0 NA  0 NA  0 NA  0  0  0 NA  0 NA  0 NA
#> [151]  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA
#> [176]  0 NA  0  0 NA  0 NA  0 NA  0  0 NA  0 NA  0  0 NA  0 NA  0 NA  0 NA  0 NA
#> [201]  0 NA  0 NA  0 NA  0 NA  0  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA
#> [226]  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0
#> [251] NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA
#> [276]  0 NA  0 NA  0 NA  0 NA  0 NA  1  0 NA  1  0 NA  0 NA  0  0 NA  0  0 NA  0
#> [301] NA  0  0 NA  0  0 NA  0 NA  0  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0
#> [326] NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA  0 NA
#>