tests/testthat/test-organize-data.R

context("organize-data.R")

test_that("make_tidier_table returns tidier table", {
  data <- data.frame(
    variables = c("s1.a", "s1.b.1", "s2.a.1", "s2.b.1.apple"),
    sub1 = c(NA, "yes", "no", "jane"),
    sub2 = c("jimothy", "pb", NA, NA),
    stringsAsFactors = FALSE
  )
  tidy_data <- data.frame(
    form_data_id = c(
      "sub1", "sub1", "sub1", "sub1",
      "sub2", "sub2", "sub2", "sub2"
    ),
    section = c(
      "s1", "s1", "s2", "s2",
      "s1", "s1", "s2", "s2"
    ),
    variable = c(
      "a", "b.1", "a.1", "b.1.apple",
      "a", "b.1", "a.1", "b.1.apple"
    ),
    response = c(
      NA, "yes", "no", "jane",
      "jimothy", "pb", NA, NA
    ),
    stringsAsFactors = FALSE
  )
  res <- make_tidier_table(data)
  expect_equal(res, tidy_data)
})
Sage-Bionetworks/synapseforms documentation built on June 16, 2020, 8:35 a.m.