Skip to content

Commit

Permalink
Reopen #34 (#39)
Browse files Browse the repository at this point in the history
set all active binding names to snake case
  • Loading branch information
jmtaylor-fhcrc authored Jun 25, 2021
1 parent 7c99d76 commit 63bc7b3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
17 changes: 12 additions & 5 deletions R/DataSpaceStudy.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
@@ -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"))
10 changes: 5 additions & 5 deletions tests/testthat/test-study.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -200,15 +200,15 @@ 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)
}
})

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)
}
})
Expand All @@ -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]
Expand Down

0 comments on commit 63bc7b3

Please sign in to comment.