-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added formatting function for filter panel classes #28
Changes from all commits
3020d22
e37e73c
a0ab58b
5d2986f
49ab696
0ede485
ee4f770
7e62953
8205487
967a751
02d3b9c
99999c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -354,6 +354,25 @@ FilterState <- R6::R6Class( # nolint | |
return(invisible(NULL)) | ||
}, | ||
|
||
#' @description | ||
#' Returns a formatted string representing this `FilterState`. | ||
#' | ||
#' @param indent (`numeric(1)`) the number of spaces before after each new line character of the formatted string. | ||
#' Default: 0 | ||
#' @return `character(1)` the formatted string | ||
#' | ||
format = function(indent = 0) { | ||
checkmate::assert_number(indent, finite = TRUE, lower = 0) | ||
|
||
sprintf( | ||
"%sFiltering on: %s\n%1$s Selected values: %s\n%1$s Include missing values: %s", | ||
format("", width = indent), | ||
self$get_varname(deparse = TRUE), | ||
paste0(format(self$get_selected(), nsmall = 3), collapse = " "), | ||
format(self$get_keep_na()) | ||
) | ||
}, | ||
|
||
#' @description | ||
#' Returns reproducible condition call for current selection relevant | ||
#' for selected variable type. | ||
|
@@ -370,7 +389,7 @@ FilterState <- R6::R6Class( # nolint | |
#' @return (`name` or `character(1)`) | ||
get_dataname = function(deparse = TRUE) { | ||
if (isTRUE(deparse)) { | ||
deparse(private$input_dataname) | ||
deparse1(private$input_dataname) | ||
} else { | ||
private$input_dataname | ||
} | ||
|
@@ -397,7 +416,7 @@ FilterState <- R6::R6Class( # nolint | |
#' @return (`name` or `character(1)`) | ||
get_varname = function(deparse = FALSE) { | ||
if (isTRUE(deparse)) { | ||
deparse(private$varname) | ||
deparse1(private$varname) | ||
} else { | ||
private$varname | ||
} | ||
|
@@ -424,6 +443,14 @@ FilterState <- R6::R6Class( # nolint | |
) | ||
}, | ||
|
||
#' @description | ||
#' Prints this `FilterState` object | ||
#' | ||
#' @param ... additional arguments to this method | ||
print = function(...) { | ||
cat(shiny::isolate(self$format()), "\n") | ||
}, | ||
|
||
#' @description | ||
#' Set if `NA` should be kept | ||
#' @param value (`logical(1)`)\cr | ||
|
@@ -1271,6 +1298,26 @@ RangeFilterState <- R6::R6Class( # nolint | |
return(invisible(self)) | ||
}, | ||
|
||
#' @description | ||
#' Returns a formatted string representing this `LogicalFilterState`. | ||
#' | ||
#' @param indent (`numeric(1)`) the number of spaces before after each new line character of the formatted string. | ||
#' Default: 0 | ||
#' @return `character(1)` the formatted string | ||
#' | ||
format = function(indent = 0) { | ||
checkmate::assert_number(indent, finite = TRUE, lower = 0) | ||
|
||
sprintf( | ||
"%sFiltering on: %s\n%1$s Selected range: %s - %s\n%1$s Include missing values: %s", | ||
format("", width = indent), | ||
self$get_varname(deparse = TRUE), | ||
format(self$get_selected(), nsmall = 3)[1], | ||
format(self$get_selected(), nsmall = 3)[2], | ||
format(self$get_keep_na()) | ||
) | ||
}, | ||
|
||
#' @description | ||
#' Answers the question of whether the current settings and values selected actually filters out any values. | ||
#' @return logical scalar | ||
|
@@ -2048,6 +2095,26 @@ DateFilterState <- R6::R6Class( # nolint | |
return(invisible(self)) | ||
}, | ||
|
||
#' @description | ||
#' Returns a formatted string representing this `DateFilterState`. | ||
#' | ||
#' @param indent (`numeric(1)`) the number of spaces before after each new line character of the formatted string. | ||
#' Default: 0 | ||
#' @return `character(1)` the formatted string | ||
#' | ||
format = function(indent = 0) { | ||
checkmate::assert_number(indent, finite = TRUE, lower = 0) | ||
|
||
sprintf( | ||
"%sFiltering on: %s\n%1$s Selected range: %s - %s\n%1$s Include missing values: %s", | ||
format("", width = indent), | ||
self$get_varname(deparse = TRUE), | ||
format(self$get_selected()[1], nsmall = 3), | ||
format(self$get_selected()[2], nsmall = 3), | ||
format(self$get_keep_na()) | ||
) | ||
}, | ||
|
||
#' @description | ||
#' Answers the question of whether the current settings and values selected actually filters out any values. | ||
#' @return logical scalar | ||
|
@@ -2346,6 +2413,26 @@ DatetimeFilterState <- R6::R6Class( # nolint | |
return(invisible(self)) | ||
}, | ||
|
||
#' @description | ||
#' Returns a formatted string representing this `DatetimeFilterState`. | ||
#' | ||
#' @param indent (`numeric(1)`) the number of spaces before after each new line character of the formatted string. | ||
#' Default: 0 | ||
#' @return `character(1)` the formatted string | ||
#' | ||
format = function(indent = 0) { | ||
checkmate::assert_number(indent, finite = TRUE, lower = 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should these be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The whole method doesn't throw even when passed a fraction but good point. Probably yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's because format implicitly casts |
||
|
||
sprintf( | ||
"%sFiltering on: %s\n%1$s Selected range: %s - %s\n%1$s Include missing values: %s", | ||
format("", width = indent), | ||
self$get_varname(deparse = TRUE), | ||
format(self$get_selected(), nsmall = 3)[1], | ||
format(self$get_selected(), nsmall = 3)[2], | ||
format(self$get_keep_na()) | ||
) | ||
}, | ||
|
||
#' @description | ||
#' Answers the question of whether the current settings and values selected actually filters out any values. | ||
#' @return logical scalar | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RangeFilterState handles also
Inf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's consequential for a human readable output to be honest. It was a conscious decision.