mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2026-06-19 13:17:30 +02:00
Completed working test suite and added CI
This commit is contained in:
parent
0aed5bb118
commit
a0a482abef
10 changed files with 153 additions and 55 deletions
|
|
@ -1,3 +1,49 @@
|
|||
# Setup -------------------------------------------------------------------
|
||||
|
||||
devtools::load_all()
|
||||
|
||||
library(digest)
|
||||
library(magrittr)
|
||||
library(jsonlite)
|
||||
|
||||
|
||||
ref_data_location <- function(x) file.path("tests","testthat","data", x)
|
||||
|
||||
# RCurl -------------------------------------------------------------------
|
||||
|
||||
REDCap_split(
|
||||
ref_data_location("ExampleProject_records.json") %>% fromJSON,
|
||||
ref_data_location("ExampleProject_metadata.json") %>% fromJSON
|
||||
) %>% digest
|
||||
|
||||
|
||||
# Basic CSV ---------------------------------------------------------------
|
||||
|
||||
REDCap_split(
|
||||
ref_data_location("ExampleProject_DATA_2018-06-07_1129.csv") %>% read.csv,
|
||||
ref_data_location("ExampleProject_DataDictionary_2018-06-07.csv") %>% read.csv
|
||||
) %>% digest
|
||||
|
||||
# REDCap R Export ---------------------------------------------------------
|
||||
|
||||
source("tests/testthat/helper-ExampleProject_R_2018-06-07_1129.r")
|
||||
|
||||
REDCap_split(
|
||||
ref_data_location("ExampleProject_DATA_2018-06-07_1129.csv") %>%
|
||||
read.csv %>%
|
||||
REDCap_process_csv,
|
||||
ref_data_location("ExampleProject_DataDictionary_2018-06-07.csv") %>% read.csv
|
||||
) %>% digest
|
||||
|
||||
# Longitudinal data from @pbchase; Issue #7 -------------------------------
|
||||
|
||||
# Something will go here.
|
||||
file_paths <- sapply(
|
||||
c(
|
||||
records = "WARRIORtestForSoftwa_DATA_2018-06-21_1431.csv",
|
||||
metadata = "WARRIORtestForSoftwareUpgrades_DataDictionary_2018-06-21.csv"
|
||||
), ref_data_location
|
||||
)
|
||||
|
||||
redcap <- lapply(file_paths, read.csv, stringsAsFactors = FALSE)
|
||||
redcap[["metadata"]] <- with(redcap, metadata[metadata[,1] > "",])
|
||||
with(redcap, REDCap_split(records, metadata)) %>% digest
|
||||
|
|
|
|||
|
|
@ -1,36 +1,37 @@
|
|||
REDCap_process_csv <- function(data) {
|
||||
#Load Hmisc library
|
||||
if (!require(Hmisc))
|
||||
if (!requireNamespace("Hmisc", quietly = TRUE)) {
|
||||
stop("This test requires the 'Hmisc' package")
|
||||
}
|
||||
|
||||
label(data$row)="Name"
|
||||
label(data$redcap_repeat_instrument)="Repeat Instrument"
|
||||
label(data$redcap_repeat_instance)="Repeat Instance"
|
||||
label(data$mpg)="Miles/(US) gallon"
|
||||
label(data$cyl)="Number of cylinders"
|
||||
label(data$disp)="Displacement"
|
||||
label(data$hp)="Gross horsepower"
|
||||
label(data$drat)="Rear axle ratio"
|
||||
label(data$wt)="Weight"
|
||||
label(data$qsec)="1/4 mile time"
|
||||
label(data$vs)="V engine?"
|
||||
label(data$am)="Transmission"
|
||||
label(data$gear)="Number of forward gears"
|
||||
label(data$carb)="Number of carburetors"
|
||||
label(data$color_available___red)="Colors Available (choice=Red)"
|
||||
label(data$color_available___green)="Colors Available (choice=Green)"
|
||||
label(data$color_available___blue)="Colors Available (choice=Blue)"
|
||||
label(data$color_available___black)="Colors Available (choice=Black)"
|
||||
label(data$motor_trend_cars_complete)="Complete?"
|
||||
label(data$letter_group___a)="Which group? (choice=A)"
|
||||
label(data$letter_group___b)="Which group? (choice=B)"
|
||||
label(data$letter_group___c)="Which group? (choice=C)"
|
||||
label(data$choice)="Choose one"
|
||||
label(data$grouping_complete)="Complete?"
|
||||
label(data$price)="Sale price"
|
||||
label(data$color)="Color"
|
||||
label(data$customer)="Customer Name"
|
||||
label(data$sale_complete)="Complete?"
|
||||
Hmisc::label(data$row)="Name"
|
||||
Hmisc::label(data$redcap_repeat_instrument)="Repeat Instrument"
|
||||
Hmisc::label(data$redcap_repeat_instance)="Repeat Instance"
|
||||
Hmisc::label(data$mpg)="Miles/(US) gallon"
|
||||
Hmisc::label(data$cyl)="Number of cylinders"
|
||||
Hmisc::label(data$disp)="Displacement"
|
||||
Hmisc::label(data$hp)="Gross horsepower"
|
||||
Hmisc::label(data$drat)="Rear axle ratio"
|
||||
Hmisc::label(data$wt)="Weight"
|
||||
Hmisc::label(data$qsec)="1/4 mile time"
|
||||
Hmisc::label(data$vs)="V engine?"
|
||||
Hmisc::label(data$am)="Transmission"
|
||||
Hmisc::label(data$gear)="Number of forward gears"
|
||||
Hmisc::label(data$carb)="Number of carburetors"
|
||||
Hmisc::label(data$color_available___red)="Colors Available (choice=Red)"
|
||||
Hmisc::label(data$color_available___green)="Colors Available (choice=Green)"
|
||||
Hmisc::label(data$color_available___blue)="Colors Available (choice=Blue)"
|
||||
Hmisc::label(data$color_available___black)="Colors Available (choice=Black)"
|
||||
Hmisc::label(data$motor_trend_cars_complete)="Complete?"
|
||||
Hmisc::label(data$letter_group___a)="Which group? (choice=A)"
|
||||
Hmisc::label(data$letter_group___b)="Which group? (choice=B)"
|
||||
Hmisc::label(data$letter_group___c)="Which group? (choice=C)"
|
||||
Hmisc::label(data$choice)="Choose one"
|
||||
Hmisc::label(data$grouping_complete)="Complete?"
|
||||
Hmisc::label(data$price)="Sale price"
|
||||
Hmisc::label(data$color)="Color"
|
||||
Hmisc::label(data$customer)="Customer Name"
|
||||
Hmisc::label(data$sale_complete)="Complete?"
|
||||
#Setting Units
|
||||
|
||||
|
||||
9
R/tests/testthat/helper-paths.R
Normal file
9
R/tests/testthat/helper-paths.R
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# get_data_location <- function(x) {
|
||||
# system.file(
|
||||
# "testdata",
|
||||
# x,
|
||||
# package = "REDCapRITS"
|
||||
# )
|
||||
# }
|
||||
|
||||
get_data_location <- function(x) file.path("data", x)
|
||||
|
|
@ -1,22 +1,16 @@
|
|||
context("Reading in JSON")
|
||||
|
||||
# Set up the path ----------------------------------------------------------
|
||||
|
||||
data_dir <- system.file("tests", "testthat", "data", package = "REDCapRITS")
|
||||
|
||||
# Check the RCurl export ---------------------------------------------------
|
||||
test_that("JSON character vector from RCurl matches reference", {
|
||||
|
||||
metadata <- jsonlite::fromJSON(
|
||||
file.path(
|
||||
data_dir,
|
||||
get_data_location(
|
||||
"ExampleProject_metadata.json"
|
||||
)
|
||||
)
|
||||
|
||||
records <- jsonlite::fromJSON(
|
||||
file.path(
|
||||
data_dir,
|
||||
get_data_location(
|
||||
"ExampleProject_records.json"
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,19 +1,14 @@
|
|||
context("CSV Exports")
|
||||
|
||||
# Set up the path and data -------------------------------------------------
|
||||
|
||||
data_dir <- system.file("tests", "testthat", "data", package = "REDCapRITS")
|
||||
|
||||
metadata <- read.csv(
|
||||
file.path(
|
||||
data_dir,
|
||||
get_data_location(
|
||||
"ExampleProject_DataDictionary_2018-06-07.csv"
|
||||
)
|
||||
)
|
||||
|
||||
records <- read.csv(
|
||||
file.path(
|
||||
data_dir,
|
||||
get_data_location(
|
||||
"ExampleProject_DATA_2018-06-07_1129.csv"
|
||||
)
|
||||
)
|
||||
|
|
@ -26,10 +21,11 @@ test_that("CSV export matches reference", {
|
|||
})
|
||||
|
||||
# Test that R code enhanced CSV export matches reference --------------------
|
||||
test_that("R code enhanced export matches reference", {
|
||||
source(file.path(data_dir, "ExampleProject_R_2018-06-07_1129.r"))
|
||||
if (requireNamespace("Hmisc", quietly = TRUE)) {
|
||||
test_that("R code enhanced export matches reference", {
|
||||
redcap_output_csv2 <- REDCap_split(REDCap_process_csv(records), metadata)
|
||||
|
||||
redcap_output_csv2 <- REDCap_split(REDCap_process_csv(records), metadata)
|
||||
expect_known_hash(redcap_output_csv2, "34f82cab35bf8aae47d08cd96f743e6b")
|
||||
})
|
||||
}
|
||||
|
||||
expect_known_hash(redcap_output_csv2, "34f82cab35bf8aae47d08cd96f743e6b")
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
context("Longitudinal data")
|
||||
|
||||
test_that("CSV export matches reference", {
|
||||
# Reading in the files
|
||||
file_paths <- file.path(
|
||||
system.file("tests", "testthat", "data", package = "REDCapRITS"),
|
||||
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)
|
||||
names(redcap) <- c("records", "metadata")
|
||||
redcap[["metadata"]] <- with(redcap, metadata[metadata[,1] > "",])
|
||||
redcap_output <- with(redcap, REDCap_split(records, metadata))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue