mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2024-11-22 13:30:23 +01:00
Completed working test suite and added CI
This commit is contained in:
parent
0aed5bb118
commit
a0a482abef
@ -1,2 +1,4 @@
|
|||||||
^.*\.Rproj$
|
^.*\.Rproj$
|
||||||
^\.Rproj\.user$
|
^\.Rproj\.user$
|
||||||
|
^\.travis\.yml$
|
||||||
|
^appveyor\.yml$
|
||||||
|
5
R/.travis.yml
Normal file
5
R/.travis.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
|
||||||
|
|
||||||
|
language: R
|
||||||
|
sudo: false
|
||||||
|
cache: packages
|
45
R/appveyor.yml
Normal file
45
R/appveyor.yml
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# DO NOT CHANGE the "init" and "install" sections below
|
||||||
|
|
||||||
|
# Download script file from GitHub
|
||||||
|
init:
|
||||||
|
ps: |
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1"
|
||||||
|
Import-Module '..\appveyor-tool.ps1'
|
||||||
|
|
||||||
|
install:
|
||||||
|
ps: Bootstrap
|
||||||
|
|
||||||
|
cache:
|
||||||
|
- C:\RLibrary
|
||||||
|
|
||||||
|
# Adapt as necessary starting from here
|
||||||
|
|
||||||
|
build_script:
|
||||||
|
- travis-tool.sh install_deps
|
||||||
|
|
||||||
|
test_script:
|
||||||
|
- travis-tool.sh run_tests
|
||||||
|
|
||||||
|
on_failure:
|
||||||
|
- 7z a failure.zip *.Rcheck\*
|
||||||
|
- appveyor PushArtifact failure.zip
|
||||||
|
|
||||||
|
artifacts:
|
||||||
|
- path: '*.Rcheck\**\*.log'
|
||||||
|
name: Logs
|
||||||
|
|
||||||
|
- path: '*.Rcheck\**\*.out'
|
||||||
|
name: Logs
|
||||||
|
|
||||||
|
- path: '*.Rcheck\**\*.fail'
|
||||||
|
name: Logs
|
||||||
|
|
||||||
|
- path: '*.Rcheck\**\*.Rout'
|
||||||
|
name: Logs
|
||||||
|
|
||||||
|
- path: '\*_*.tar.gz'
|
||||||
|
name: Bits
|
||||||
|
|
||||||
|
- path: '\*_*.zip'
|
||||||
|
name: Bits
|
@ -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 -------------------------------
|
# 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) {
|
REDCap_process_csv <- function(data) {
|
||||||
#Load Hmisc library
|
#Load Hmisc library
|
||||||
if (!require(Hmisc))
|
if (!requireNamespace("Hmisc", quietly = TRUE)) {
|
||||||
stop("This test requires the 'Hmisc' package")
|
stop("This test requires the 'Hmisc' package")
|
||||||
|
}
|
||||||
|
|
||||||
label(data$row)="Name"
|
Hmisc::label(data$row)="Name"
|
||||||
label(data$redcap_repeat_instrument)="Repeat Instrument"
|
Hmisc::label(data$redcap_repeat_instrument)="Repeat Instrument"
|
||||||
label(data$redcap_repeat_instance)="Repeat Instance"
|
Hmisc::label(data$redcap_repeat_instance)="Repeat Instance"
|
||||||
label(data$mpg)="Miles/(US) gallon"
|
Hmisc::label(data$mpg)="Miles/(US) gallon"
|
||||||
label(data$cyl)="Number of cylinders"
|
Hmisc::label(data$cyl)="Number of cylinders"
|
||||||
label(data$disp)="Displacement"
|
Hmisc::label(data$disp)="Displacement"
|
||||||
label(data$hp)="Gross horsepower"
|
Hmisc::label(data$hp)="Gross horsepower"
|
||||||
label(data$drat)="Rear axle ratio"
|
Hmisc::label(data$drat)="Rear axle ratio"
|
||||||
label(data$wt)="Weight"
|
Hmisc::label(data$wt)="Weight"
|
||||||
label(data$qsec)="1/4 mile time"
|
Hmisc::label(data$qsec)="1/4 mile time"
|
||||||
label(data$vs)="V engine?"
|
Hmisc::label(data$vs)="V engine?"
|
||||||
label(data$am)="Transmission"
|
Hmisc::label(data$am)="Transmission"
|
||||||
label(data$gear)="Number of forward gears"
|
Hmisc::label(data$gear)="Number of forward gears"
|
||||||
label(data$carb)="Number of carburetors"
|
Hmisc::label(data$carb)="Number of carburetors"
|
||||||
label(data$color_available___red)="Colors Available (choice=Red)"
|
Hmisc::label(data$color_available___red)="Colors Available (choice=Red)"
|
||||||
label(data$color_available___green)="Colors Available (choice=Green)"
|
Hmisc::label(data$color_available___green)="Colors Available (choice=Green)"
|
||||||
label(data$color_available___blue)="Colors Available (choice=Blue)"
|
Hmisc::label(data$color_available___blue)="Colors Available (choice=Blue)"
|
||||||
label(data$color_available___black)="Colors Available (choice=Black)"
|
Hmisc::label(data$color_available___black)="Colors Available (choice=Black)"
|
||||||
label(data$motor_trend_cars_complete)="Complete?"
|
Hmisc::label(data$motor_trend_cars_complete)="Complete?"
|
||||||
label(data$letter_group___a)="Which group? (choice=A)"
|
Hmisc::label(data$letter_group___a)="Which group? (choice=A)"
|
||||||
label(data$letter_group___b)="Which group? (choice=B)"
|
Hmisc::label(data$letter_group___b)="Which group? (choice=B)"
|
||||||
label(data$letter_group___c)="Which group? (choice=C)"
|
Hmisc::label(data$letter_group___c)="Which group? (choice=C)"
|
||||||
label(data$choice)="Choose one"
|
Hmisc::label(data$choice)="Choose one"
|
||||||
label(data$grouping_complete)="Complete?"
|
Hmisc::label(data$grouping_complete)="Complete?"
|
||||||
label(data$price)="Sale price"
|
Hmisc::label(data$price)="Sale price"
|
||||||
label(data$color)="Color"
|
Hmisc::label(data$color)="Color"
|
||||||
label(data$customer)="Customer Name"
|
Hmisc::label(data$customer)="Customer Name"
|
||||||
label(data$sale_complete)="Complete?"
|
Hmisc::label(data$sale_complete)="Complete?"
|
||||||
#Setting Units
|
#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")
|
context("Reading in JSON")
|
||||||
|
|
||||||
# Set up the path ----------------------------------------------------------
|
|
||||||
|
|
||||||
data_dir <- system.file("tests", "testthat", "data", package = "REDCapRITS")
|
|
||||||
|
|
||||||
# Check the RCurl export ---------------------------------------------------
|
# Check the RCurl export ---------------------------------------------------
|
||||||
test_that("JSON character vector from RCurl matches reference", {
|
test_that("JSON character vector from RCurl matches reference", {
|
||||||
|
|
||||||
metadata <- jsonlite::fromJSON(
|
metadata <- jsonlite::fromJSON(
|
||||||
file.path(
|
get_data_location(
|
||||||
data_dir,
|
|
||||||
"ExampleProject_metadata.json"
|
"ExampleProject_metadata.json"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
records <- jsonlite::fromJSON(
|
records <- jsonlite::fromJSON(
|
||||||
file.path(
|
get_data_location(
|
||||||
data_dir,
|
|
||||||
"ExampleProject_records.json"
|
"ExampleProject_records.json"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -1,19 +1,14 @@
|
|||||||
context("CSV Exports")
|
context("CSV Exports")
|
||||||
|
|
||||||
# Set up the path and data -------------------------------------------------
|
# Set up the path and data -------------------------------------------------
|
||||||
|
|
||||||
data_dir <- system.file("tests", "testthat", "data", package = "REDCapRITS")
|
|
||||||
|
|
||||||
metadata <- read.csv(
|
metadata <- read.csv(
|
||||||
file.path(
|
get_data_location(
|
||||||
data_dir,
|
|
||||||
"ExampleProject_DataDictionary_2018-06-07.csv"
|
"ExampleProject_DataDictionary_2018-06-07.csv"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
records <- read.csv(
|
records <- read.csv(
|
||||||
file.path(
|
get_data_location(
|
||||||
data_dir,
|
|
||||||
"ExampleProject_DATA_2018-06-07_1129.csv"
|
"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 CSV export matches reference --------------------
|
||||||
test_that("R code enhanced export matches reference", {
|
if (requireNamespace("Hmisc", quietly = TRUE)) {
|
||||||
source(file.path(data_dir, "ExampleProject_R_2018-06-07_1129.r"))
|
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")
|
context("Longitudinal data")
|
||||||
|
|
||||||
test_that("CSV export matches reference", {
|
test_that("CSV export matches reference", {
|
||||||
# Reading in the files
|
file_paths <- sapply(
|
||||||
file_paths <- file.path(
|
|
||||||
system.file("tests", "testthat", "data", package = "REDCapRITS"),
|
|
||||||
c(
|
c(
|
||||||
records = "WARRIORtestForSoftwa_DATA_2018-06-21_1431.csv",
|
records = "WARRIORtestForSoftwa_DATA_2018-06-21_1431.csv",
|
||||||
metadata = "WARRIORtestForSoftwareUpgrades_DataDictionary_2018-06-21.csv"
|
metadata = "WARRIORtestForSoftwareUpgrades_DataDictionary_2018-06-21.csv"
|
||||||
)
|
), get_data_location
|
||||||
)
|
)
|
||||||
|
|
||||||
redcap <- lapply(file_paths, read.csv, stringsAsFactors = FALSE)
|
redcap <- lapply(file_paths, read.csv, stringsAsFactors = FALSE)
|
||||||
names(redcap) <- c("records", "metadata")
|
|
||||||
redcap[["metadata"]] <- with(redcap, metadata[metadata[,1] > "",])
|
redcap[["metadata"]] <- with(redcap, metadata[metadata[,1] > "",])
|
||||||
redcap_output <- with(redcap, REDCap_split(records, metadata))
|
redcap_output <- with(redcap, REDCap_split(records, metadata))
|
||||||
|
|
||||||
|
@ -157,6 +157,9 @@ welcome your contributions!
|
|||||||
## Instructions
|
## Instructions
|
||||||
### R
|
### R
|
||||||
|
|
||||||
|
[![Travis-CI Build Status](https://travis-ci.org/SpectrumHealthResearch/REDCapRITS.svg?branch=master)](https://travis-ci.org/SpectrumHealthResearch/REDCapRITS)
|
||||||
|
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/SpectrumHealthResearch/REDCapRITS?branch=master&svg=true)](https://ci.appveyor.com/project/SpectrumHealthResearch/REDCapRITS)
|
||||||
|
|
||||||
#### Installation
|
#### Installation
|
||||||
|
|
||||||
First you must install the package. To do so, execute the following in your R console:
|
First you must install the package. To do so, execute the following in your R console:
|
||||||
|
Loading…
Reference in New Issue
Block a user