context("ml_logs")
ml_connect()
participants <- ml_participants()
responses <- ml_responses(participants, update = TRUE)
logs <- ml_logs(participants, responses)
test_that("ml_responses columns are the right classes", {
expect_true(is.character(logs$id))
expect_true(is.character(logs$id_exp))
expect_true(is.character(logs$id_db))
expect_true(is.character(logs$code))
expect_true(is.numeric(logs$time))
expect_true(is.character(logs$study))
expect_true(is.character(logs$version))
expect_true(lubridate::is.Date(logs$date_sent))
expect_true(lubridate::is.Date(logs$time_stamp))
expect_true(is.numeric(logs$days_from_sent))
expect_true(lubridate::is.Date(logs$date_birth))
expect_true(is.numeric(logs$age))
expect_true(is.numeric(logs$age_today))
expect_true(is.numeric(logs$months_from_last_response))
expect_true(is.character(logs$sex))
expect_true(is.character(logs$postcode))
expect_true(is.character(logs$edu_parent1))
expect_true(is.character(logs$edu_parent2))
expect_true(is.character(logs$dominance))
expect_true(is.character(logs$lp))
expect_true(is.numeric(logs$doe_spanish))
expect_true(is.numeric(logs$doe_catalan))
expect_true(is.numeric(logs$doe_others))
expect_true(is.character(logs$progress))
expect_true(is.logical(logs$completed))
})
test_that("variables contains possible values", {
# expect_true(all(logs$id %in% participants$id))
# expect_true(all(logs$id_exp %in% participants$id_exp))
# expect_true(all(logs$id_db %in% participants$id_db))
expect_true(all(logs$code %in% participants$code))
expect_true(all(logs$time > 0))
expect_true(all(logs$study %in% participants$study))
expect_true(all(logs$version %in% responses$version))
expect_true(all(logs$time_stamp <= today()))
expect_true(all(logs$days_from_sent[!is.na(logs$days_from_sent)] >= 0))
expect_true(all(logs$date_birth <= today()))
expect_true(all(logs$age >= 0))
expect_true(all(logs$age_today >= 0))
expect_true(all(logs$age >= 0))
expect_true(all(logs$months_from_last_response >= 0))
expect_true(all(logs$sex %in% c("Female", "Male", NA)))
expect_true(all(logs$edu_parent1 %in% c("complementary", "noeducation", "primary", "secondary", "university", "vocational", NA)))
expect_true(all(logs$edu_parent2 %in% c("complementary", "noeducation", "primary", "secondary", "university", "vocational", NA)))
expect_true(all(logs$lp %in% c("Monolingual", "Bilingual", "Other")))
expect_true(all(between(logs$doe_catalan, 0, 1)))
expect_true(all(between(logs$doe_spanish, 0, 1)))
expect_true(all(between(logs$doe_others, 0, 1)))
})
test_that("missing values are only where expected", {
expect_false(any(is.na(logs$id)))
expect_false(any(is.na(logs$id_exp)))
expect_false(any(is.na(logs$id_db)))
expect_false(any(is.na(logs$time)))
expect_false(any(is.na(logs$study)))
expect_false(any(is.na(logs$version)))
expect_false(any(is.na(logs$date_birth)))
expect_false(any(is.na(logs$age)))
expect_false(any(is.na(logs$age_today)))
expect_false(any(is.na(logs$lp)))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.