knitr::opts_chunk$set(echo = TRUE)
library(epiuf)

checkDico compares a number list to the contents of a variable, and flags a warning if the variable contains numbers not specified in the list Works with numeric, character and multi-input variables.

# create example dataset for testing
df <- data.frame(checkbox_var = c("0|2", "1|2|3", "3|1|2", "0", "2", "3", "0|1", "2|3", NA_character_)
                 ,number_var = c(0,1,2,3,0,1,2,3,NA_real_)
                 ,character_var = c("0","1","nd","3","","1","2","3",NA_character_)
)

Test correct dico numbers

checkDico(df, checkbox_var, c(0,1,2,3))
checkDico(df, number_var, c(0,1,2,3))
checkDico(df, character_var, c(0,1,2,3))

Expected output: nothing

Test extra dico numbers

checkDico(df, checkbox_var, c(0,1,2,3,4))
checkDico(df, number_var, c(0,1,2,3,4))
checkDico(df, character_var, c(0,1,2,3,4))

Expected output: nothing

Test missing dico numbers

checkDico(df, checkbox_var, c(0,1,2))
checkDico(df, number_var, c(0,1,2))
checkDico(df, character_var, c(0,1,2))

Expected output: [variable name] contains: 0 1 2 3 , Code is: 0 1 2



Epiconcept-Paris/STRAP-epiuf documentation built on Aug. 5, 2024, 3:41 a.m.