Skip to content

Commit

Permalink
Merge branch 'main' into 999_default_dataname@main
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikeyakirar committed Dec 12, 2023
2 parents 5167ee3 + 0f0cf06 commit 28afe0b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: teal
Title: Exploratory Web Apps for Analyzing Clinical Trials Data
Version: 0.14.0.9027
Date: 2023-12-08
Version: 0.14.0.9028
Date: 2023-12-12
Authors@R: c(
person("Dawid", "Kaledkowski", , "[email protected]", role = c("aut", "cre")),
person("Pawel", "Rucki", , "[email protected]", role = "aut"),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# teal 0.14.0.9027
# teal 0.14.0.9028

### New features

Expand Down
24 changes: 14 additions & 10 deletions R/teal_slices-store.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,21 @@ slices_restore <- function(file) {
lapply(tss_json$slices, function(slice) {
for (field in c("selected", "choices")) {
if (!is.null(slice[[field]])) {
date_partial_regex <- "^[0-9]{4}-[0-9]{2}-[0-9]{2}"
time_stamp_regex <- paste0(date_partial_regex, "\\s[0-9]{2}:[0-9]{2}:[0-9]{2}\\sUTC$")
if (length(slice[[field]]) > 0) {
date_partial_regex <- "^[0-9]{4}-[0-9]{2}-[0-9]{2}"
time_stamp_regex <- paste0(date_partial_regex, "\\s[0-9]{2}:[0-9]{2}:[0-9]{2}\\sUTC$")

slice[[field]] <-
if (all(grepl(paste0(date_partial_regex, "$"), slice[[field]]))) {
as.Date(slice[[field]])
} else if (all(grepl(time_stamp_regex, slice[[field]]))) {
as.POSIXct(slice[[field]], tz = "UTC")
} else {
slice[[field]]
}
slice[[field]] <-
if (all(grepl(paste0(date_partial_regex, "$"), slice[[field]]))) {
as.Date(slice[[field]])
} else if (all(grepl(time_stamp_regex, slice[[field]]))) {
as.POSIXct(slice[[field]], tz = "UTC")
} else {
slice[[field]]
}
} else {
slice[[field]] <- character(0)
}
}
}
slice
Expand Down
42 changes: 42 additions & 0 deletions tests/testthat/test-teal_slices-store.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
testthat::test_that("teal_slice store/restore supports NULL and character(0) for choices and selected", {
slices_path <- withr::local_file("slices.json")
tss <- teal_slices(
teal_slice(
dataname = "data",
varname = "var",
choices = character(0),
selected = NULL
)
)
slices_store(tss, slices_path)
tss_restored <- teal:::slices_restore(slices_path)

slices2_path <- withr::local_file("slices2.json")
tss2 <- teal_slices(
teal_slice(
dataname = "data",
varname = "var",
choices = NULL,
selected = NULL
)
)
slices_store(tss2, slices2_path)
tss2_restored <- slices_restore(slices2_path)

slices3_path <- withr::local_file("slices3.json")
tss3 <- teal_slices(
teal_slice(
dataname = "data",
varname = "var",
choices = character(0),
selected = character(0)
)
)
slices_store(tss3, slices3_path)
tss3_restored <- slices_restore(slices3_path)

teal.slice:::expect_identical_slice(tss[[1]], tss_restored[[1]])
teal.slice:::expect_identical_slice(tss2[[1]], tss2_restored[[1]])
teal.slice:::expect_identical_slice(tss3[[1]], tss3_restored[[1]])
})

testthat::test_that("teal_slice store/restore supports saving `POSIXct` timestamps in selected", {
slices_path <- withr::local_file("slices.json")

Expand Down

0 comments on commit 28afe0b

Please sign in to comment.