Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into teal_data@main
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Oct 19, 2023
2 parents d95994e + be2b2e2 commit bdcc7af
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.3.2.9021
rev: v0.3.2.9023
hooks:
- id: style-files
name: Style code with `styler`
Expand Down
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.slice
Title: Filter Module for 'teal' Applications
Version: 0.4.0.9016
Date: 2023-10-12
Version: 0.4.0.9018
Date: 2023-10-19
Authors@R: c(
person("Dawid", "Kaledkowski", , "[email protected]", role = c("aut", "cre")),
person("Pawel", "Rucki", , "[email protected]", role = "aut"),
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export(is.teal_slices)
export(list_to_teal_slices)
export(remove_filter_state)
export(set_filter_state)
export(slices_restore)
export(slices_store)
export(teal_slice)
export(teal_slices)
import(R6)
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# teal.slice 0.4.0.9016
# teal.slice 0.4.0.9018

### Miscellaneous

* Specified minimal version of package dependencies.
* Removed storing and restoring of `teal_slices` objects.

# teal.slice 0.4.0

Expand Down
58 changes: 0 additions & 58 deletions R/teal_slice-store.R

This file was deleted.

20 changes: 17 additions & 3 deletions R/teal_slice.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
#' requires `dataname` prefix, *e.g.* `data$var == "x"`.
#' @param choices (optional `vector`) specifying allowed choices;
#' When specified it should be a subset of values in variable denoted by `varname`;
#' Type and size depends on variable type.
#' Type and size depends on variable type. Factors are coerced to character.
#' @param selected (optional `vector`) of selected values from `choices`;
#' Type and size depends on variable type.
#' Type and size depends on variable type. Factors are coerced to character.
#' @param multiple (optional `logical(1)`) flag specifying whether more than one value can be selected;
#' only applicable to `ChoicesFilterState` and `LogicalFilterState`
#' @param keep_na (optional `logical(1)`) flag specifying whether to keep missing values
Expand All @@ -78,6 +78,10 @@
#' @return A `teal.slice` object. Depending on whether `varname` or `expr` was specified, the resulting
#' `teal_slice` also receives class `teal_slice_var` or `teal_slice_expr`, respectively.
#'
#' @note When `teal_slice` is printed and contains a `POSIX*t` class in `selected` or `choices` fields, then those
#' fields are converted to `UTC` timezone, for enhanced and unified storage and restoring with `teal::slices_store()`
#' and `teal::slices_restore()`.
#'
#' @examples
#' x1 <- teal_slice(
#' dataname = "data",
Expand Down Expand Up @@ -155,6 +159,8 @@ teal_slice <- function(dataname,
)
formal_args <- formal_args[ts_var_args]
args <- c(formal_args, list(...))
args[c("choices", "selected")] <-
lapply(args[c("choices", "selected")], function(x) if (is.factor(x)) as.character(x) else x)
if (missing(id)) {
args$id <- get_default_slice_id(args)
} else {
Expand Down Expand Up @@ -268,7 +274,7 @@ to_json <- function(x) {
vars <- c("selected", "choices")
if (is.list(x)) {
for (var in vars) {
if (!is.null(x[[var]])) x[[var]] <- I(x[[var]])
if (!is.null(x[[var]])) x[[var]] <- I(format_time(x[[var]]))
}
lapply(x, no_unbox)
} else {
Expand All @@ -279,6 +285,14 @@ to_json <- function(x) {
jsonlite::toJSON(no_unbox(x), pretty = TRUE, auto_unbox = TRUE, digits = 16, null = "null")
}

format_time <- function(x) {
if ("POSIXt" %in% class(x)) {
format(x, format = "%Y-%m-%d %H:%M:%S", usetz = TRUE, tz = "UTC")
} else {
x
}
}

#' Justify Colons in `JSON` String
#'
#' This function takes a `JSON` string as input, splits it into lines, and pads element names
Expand Down
4 changes: 4 additions & 0 deletions R/teal_slices.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#' @param i (`character` or `numeric` or `logical`) indicating which elements to extract
#' @param recursive (`logical(1)`) flag specifying whether to also convert to list the elements of this `teal_slices`
#'
#' @note When `teal_slices` are printed and any of `teal_slice` elements contain a `POSIX*t` class in `selected` or
#' `choices` fields, then those fields are converted to `UTC` timezone, for enhanced and unified storage and restoring
#' with `teal::slices_store()` and `teal::slices_restore()`.
#'
#' @return
#' `teal_slices`, which is an unnamed list of `teal_slice` objects.
#'
Expand Down
2 changes: 0 additions & 2 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ reference:
- clear_filter_states
- teal_slice
- teal_slices
- slices_store
- slices_restore
- title: For Developers
subtitle: R6 Classes
desc: Abstract and concrete classes used to build teal functionality.
Expand Down
25 changes: 0 additions & 25 deletions man/slices_restore.Rd

This file was deleted.

36 changes: 0 additions & 36 deletions man/slices_store.Rd

This file was deleted.

9 changes: 7 additions & 2 deletions man/teal_slice.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/teal_slices.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions tests/testthat/test-teal_slice.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,21 @@ testthat::test_that("teal_slice dataname has to be a string when expr is specifi
teal_slice(dataname = character(0), id = "x", title = "x", expr = "x == 'x'"), "length"
)
})

testthat::test_that(
"teal_slice converts factors to characters for 'selected' and 'choices' parameters",
{
slices_path <- withr::local_file("slices.json")
tss <- teal_slices(
teal_slice(
dataname = "ADSL",
varname = "EOSDTM",
choices = factor(c("a", "b", "c")),
selected = factor(c("a", "b"))
)
)

testthat::expect_type(shiny::isolate(tss[[1]]$selected), "character")
testthat::expect_type(shiny::isolate(tss[[1]]$choices), "character")
}
)

0 comments on commit bdcc7af

Please sign in to comment.