diff --git a/R/DataSpaceStudy.R b/R/DataSpaceStudy.R index 7bb44b0..b263427 100644 --- a/R/DataSpaceStudy.R +++ b/R/DataSpaceStudy.R @@ -194,6 +194,13 @@ DataSpaceStudy <- R6Class( ... ) + ## set variable names that are returned as camel case with slash to snake case + setnames( + dataset, + names(dataset), + tolower(gsub("/[A-z]+", "", gsub("^([A-z]+)([A-Z])", "\\1_\\2", names(dataset)))) + ) + # convert to data.table setDT(dataset) } else { @@ -229,8 +236,8 @@ DataSpaceStudy <- R6Class( # update 'n' private$.availableNIDatasets[name == datasetName, n := nrow(dataset)] - # change "subject_id" to "ParticipantId" to be consistent with other datasets - setnames(dataset, c("subject_id", "prot"), c("ParticipantId", "study_prot"), skip_absent = TRUE) + # change "subject_id" to "participant_id" to be consistent with other datasets + setnames(dataset, c("subject_id", "prot"), c("participant_id", "study_prot"), skip_absent = TRUE) } # merge extra information @@ -243,11 +250,11 @@ DataSpaceStudy <- R6Class( if (!identical(datasetName, "Demographics")) { dem <- self$getDataset("Demographics") - subj <- ifelse(private$.study == "", "Subject", "Participant") - cols <- c(paste0(subj, "Visit/Visit"), "study_prot") + subj <- ifelse(private$.study == "", "subject", "participant") + cols <- c(paste0(subj, "_visit"), "study_prot") dem <- dem[, -cols, with = FALSE] - key <- paste0(subj, "Id") + key <- paste0(subj, "_id") setkeyv(dem, key) setkeyv(dataset, key) diff --git a/README.md b/README.md index fa9c9a2..da9597e 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,7 @@ NAb <- cvd408$getDataset("NAb") dim(NAb) #> [1] 540 33 colnames(NAb) -#> [1] "ParticipantId" "ParticipantVisit/Visit" "visit_day" +#> [1] "participant_id" "participant_visit" "visit_day" #> [4] "assay_identifier" "summary_level" "specimen_type" #> [7] "antigen" "antigen_type" "virus" #> [10] "virus_type" "virus_insert_name" "clade" diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index b01a287..9397a59 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -1,2 +1,3 @@ +## Set STAGING to TRUE in .Renviron to run tests against staging server. assign("onStaging", identical(tolower(Sys.getenv("STAGING")), "true")) assign("baseUrl", ifelse(onStaging, "https://dataspace-staging.cavd.org", "https://dataspace.cavd.org")) diff --git a/tests/testthat/test-study.R b/tests/testthat/test-study.R index 71743c8..1acba63 100644 --- a/tests/testthat/test-study.R +++ b/tests/testthat/test-study.R @@ -35,8 +35,8 @@ test_study <- function(study, datasets, niDatasets = c(), groupId = NULL, groupL } test_that("can connect to studies", { - expect_is(cavd, "DataSpaceStudy") - expect_is(cavd, "R6") + expect_is(cavd, "DataSpaceStudy", info=cavd[1]) + expect_is(cavd, "R6", info=cavd[1]) }) if ("DataSpaceStudy" %in% class(cavd)) { @@ -200,7 +200,7 @@ test_study <- function(study, datasets, niDatasets = c(), groupId = NULL, groupL test_that("`getDataset`", { for (datasetName in cavd$availableDatasets$name) { dataset <- try(cavd$getDataset(datasetName), silent = TRUE) - expect_is(dataset, "data.table", info = datasetName) + expect_is(dataset, "data.table", info = paste(datasetName, study, groupId)) expect_gt(nrow(dataset), 0) } }) @@ -208,7 +208,7 @@ test_study <- function(study, datasets, niDatasets = c(), groupId = NULL, groupL test_that("`getDataset` (label)", { for (datasetLabel in cavd$availableDatasets$label) { dataset <- try(cavd$getDataset(datasetLabel), silent = TRUE) - expect_is(dataset, "data.table", info = datasetLabel) + expect_is(dataset, "data.table", info = paste(datasetLabel, study, groupId)) expect_gt(nrow(dataset), 0) } }) @@ -217,7 +217,7 @@ test_study <- function(study, datasets, niDatasets = c(), groupId = NULL, groupL for (i in seq_len(nrow(cavd$availableDatasets))) { datasetName <- cavd$availableDatasets$name[i] dataset <- try(cavd$getDataset(datasetName), silent = TRUE) - expect_is(dataset, "data.table", info = datasetName) + expect_is(dataset, "data.table", info = paste(datasetName, study, groupId)) if (cavd$availableDatasets$integrated[i]) { datasetN <- cavd$availableDatasets$n[i]