mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2026-06-19 05:07:30 +02:00
Major update. New functions and improvements. See NEWS.md.
This commit is contained in:
parent
b57e130395
commit
9f68e27f5a
20 changed files with 443 additions and 97 deletions
|
|
@ -1,4 +1,4 @@
|
|||
library(testthat)
|
||||
library(REDCapRITS)
|
||||
library(REDCapCAST)
|
||||
|
||||
test_check("REDCapRITS")
|
||||
test_check("REDCapCAST")
|
||||
|
|
|
|||
BIN
tests/testthat/.DS_Store
vendored
Normal file
BIN
tests/testthat/.DS_Store
vendored
Normal file
Binary file not shown.
|
|
@ -1,19 +1,19 @@
|
|||
"Variable / Field Name","Form Name","Section Header","Field Type","Field Label","Choices, Calculations, OR Slider Labels","Field Note","Text Validation Type OR Show Slider Number","Text Validation Min","Text Validation Max",Identifier?,"Branching Logic (Show field only if...)","Required Field?","Custom Alignment","Question Number (surveys only)","Matrix Group Name","Matrix Ranking?","Field Annotation"
|
||||
field_name,form_name,section_header,field_type,field_label,select_choices_or_calculations,field_note,text_validation_type_or_show_slider_number,text_validation_min,text_validation_max,identifier,branching_logic,required_field,custom_alignment,question_number,matrix_group_name,matrix_ranking,field_annotation
|
||||
row,motor_trend_cars,,text,Name,,,,,,,,,,,,,
|
||||
mpg,motor_trend_cars,,text,"Miles/(US) gallon",,,number,,,,,,,,,,
|
||||
cyl,motor_trend_cars,,radio,"Number of cylinders","3, 3 | 4, 4 | 5, 5 | 6, 6 | 7, 7 | 8, 8",,,,,,,,,,,,
|
||||
mpg,motor_trend_cars,,text,Miles/(US) gallon,,,number,,,,,,,,,,
|
||||
cyl,motor_trend_cars,,radio,Number of cylinders,"3, 3 | 4, 4 | 5, 5 | 6, 6 | 7, 7 | 8, 8",,,,,,,,,,,,
|
||||
disp,motor_trend_cars,,text,Displacement,,(cu.in.),number,,,,,,,,,,
|
||||
hp,motor_trend_cars,,text,"Gross horsepower",,,number,,,,,,,,,,
|
||||
drat,motor_trend_cars,,text,"Rear axle ratio",,,number,,,,,,,,,,
|
||||
wt,motor_trend_cars,,text,Weight,,"(1000 lbs)",number,,,,,,,,,,
|
||||
qsec,motor_trend_cars,,text,"1/4 mile time",,,number,,,,,,,,,,
|
||||
vs,motor_trend_cars,,yesno,"V engine?",,,,,,,,,,,,,
|
||||
hp,motor_trend_cars,,text,Gross horsepower,,,number,,,,,,,,,,
|
||||
drat,motor_trend_cars,,text,Rear axle ratio,,,number,,,,,,,,,,
|
||||
wt,motor_trend_cars,,text,Weight,,(1000 lbs),number,,,,,,,,,,
|
||||
qsec,motor_trend_cars,,text,1/4 mile time,,,number,,,,,,,,,,
|
||||
vs,motor_trend_cars,,yesno,V engine?,,,,,,,,,,,,,
|
||||
am,motor_trend_cars,,dropdown,Transmission,"0, Automatic | 1, Manual"," (0 = automatic, 1 = manual)",,,,,,,,,,,
|
||||
gear,motor_trend_cars,,radio,"Number of forward gears","3, 3 | 4, 4 | 5, 5",,,,,,,,,,,,
|
||||
carb,motor_trend_cars,,radio,"Number of carburetors","1, 1 | 2, 2 | 3, 3 | 4, 4 | 5, 5 | 6, 6 | 7, 7 | 8, 8",,,,,,,,,,,,
|
||||
color_available,motor_trend_cars,,checkbox,"Colors Available","red, Red | green, Green | blue, Blue | black, Black",,,,,,,,,,,,
|
||||
letter_group,grouping,,checkbox,"Which group?","a, A | b, B | c, C",,,,,,,,,,,,
|
||||
choice,grouping,,radio,"Choose one","choice1, Choice 1 | choice2, Choice 2",,,,,,,,,,,,
|
||||
price,sale,,text,"Sale price",,,number_2dp,,,,,,,,,,
|
||||
gear,motor_trend_cars,,radio,Number of forward gears,"3, 3 | 4, 4 | 5, 5",,,,,,,,,,,,
|
||||
carb,motor_trend_cars,,radio,Number of carburetors,"1, 1 | 2, 2 | 3, 3 | 4, 4 | 5, 5 | 6, 6 | 7, 7 | 8, 8",,,,,,,,,,,,
|
||||
color_available,motor_trend_cars,,checkbox,Colors Available,"red, Red | green, Green | blue, Blue | black, Black",,,,,,,,,,,,
|
||||
letter_group,grouping,,checkbox,Which group?,"a, A | b, B | c, C",,,,,,,,,,,,
|
||||
choice,grouping,,radio,Choose one,"choice1, Choice 1 | choice2, Choice 2",,,,,,,,,,,,
|
||||
price,sale,,text,Sale price,,,number_2dp,,,,,,,,,,
|
||||
color,sale,,dropdown,Color,"1, red | 2, green | 3, blue | 4, black",,,,,,,,,,,,
|
||||
customer,sale,,text,"Customer Name",,,,,,,,,RH,,,,
|
||||
customer,sale,,text,Customer Name,,,,,,,,,RH,,,,
|
||||
|
|
|
|||
|
|
|
@ -2,7 +2,7 @@
|
|||
# system.file(
|
||||
# "testdata",
|
||||
# x,
|
||||
# package = "REDCapRITS"
|
||||
# package = "REDCapCAST"
|
||||
# )
|
||||
# }
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,22 @@ test_that("CSV export matches reference", {
|
|||
expect_known_hash(redcap_output_csv1, "f74558d1939c17d9ff0e08a19b956e26")
|
||||
})
|
||||
|
||||
# Test that REDCap_split can handle a focused dataset
|
||||
|
||||
records_red <- records[!records$redcap_repeat_instrument == "sale",
|
||||
!names(records) %in% metadata$field_name[metadata$form_name == "sale"] &
|
||||
!names(records) == "sale_complete"]
|
||||
records_red$redcap_repeat_instrument <- as.character(records_red$redcap_repeat_instrument)
|
||||
|
||||
redcap_output_red <- REDCap_split(records_red, metadata)
|
||||
|
||||
|
||||
test_that("REDCap_split handles subset dataset",
|
||||
{
|
||||
testthat::expect_length(redcap_output_red,1)
|
||||
})
|
||||
|
||||
|
||||
# Test that R code enhanced CSV export matches reference --------------------
|
||||
if (requireNamespace("Hmisc", quietly = TRUE)) {
|
||||
test_that("R code enhanced export matches reference", {
|
||||
|
|
@ -53,3 +69,5 @@ if (requireNamespace("readr", quietly = TRUE)) {
|
|||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
# Unit Test
|
||||
|
||||
# Test that the function throws an error when uri and token are not provided
|
||||
test_that("read_redcap_tables throws error when uri and token are not provided",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,30 @@ test_that("redcap_wider() returns expected output", {
|
|||
|
||||
expect_equal(redcap_wider(list),
|
||||
data.frame(record_id = c(1,2),
|
||||
age_baseline_long = c(25,26),
|
||||
age_followup_long = c(27,28),
|
||||
age_baseline = c(25,26),
|
||||
age_followup = c(27,28),
|
||||
gender = c("male","female")))
|
||||
})
|
||||
|
||||
|
||||
# Using test data
|
||||
|
||||
# Set up the path and data -------------------------------------------------
|
||||
file_paths <- sapply(
|
||||
c(records = "WARRIORtestForSoftwa_DATA_2018-06-21_1431.csv",
|
||||
metadata = "WARRIORtestForSoftwareUpgrades_DataDictionary_2018-06-21.csv"),
|
||||
get_data_location
|
||||
)
|
||||
|
||||
redcap <- lapply(file_paths, read.csv, stringsAsFactors = FALSE)
|
||||
redcap[["metadata"]] <- with(redcap, metadata[metadata[, 1] > "",])
|
||||
list <-
|
||||
with(redcap, REDCap_split(records, metadata, forms = "all"))
|
||||
|
||||
wide_ds <- redcap_wider(list)
|
||||
|
||||
test_that("redcap_wider() returns wide output from CSV",{
|
||||
expect_equal(ncol(wide_ds),171)
|
||||
})
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue