11# ' Convert data_extract_spec to picks
22# '
33# ' Helper functions to ease transition between [data_extract_spec()] and [picks()].
4+ # ' @inheritParams teal::teal_transform_module
45# ' @param x (`data_extract_spec`, `select_spec`, `filter_spec`) object to convert to [`picks`]
5- # '
66# ' @details
77# ' With introduction of [`picks`], [`data_extract_spec`] will no longer serve a primary tool to
88# ' define variable choices and default selection in teal-modules and eventually [`data_extract_spec`]
5151# ' )
5252# '
5353# ' @export
54- as.picks <- function (x , ... ) {
54+ as.picks <- function (x ) { # nolint
5555 if (inherits(x , c(" picks" , " pick" ))) {
5656 x
5757 } else if (checkmate :: test_list(x , c(" data_extract_spec" , " filter_spec" ))) {
58- Filter(length , lapply(x , as.picks , ... ))
58+ Filter(length , lapply(x , as.picks ))
5959 } else if (inherits(x , " data_extract_spec" )) {
6060 args <- Filter(
6161 length ,
6262 list (
6363 datasets(choices = x $ dataname , fixed = TRUE ),
6464 as.picks(x $ select ),
65- as.picks(x $ filter , dataname = x $ dataname )
65+ as.picks(x $ filter )
6666 # filter_spec as they are not necessary linked with `select` (selected variables)
6767 # as filter_spec can be specified on the variable(s) different than select_spec for example:
6868 # for example: #pseudocode select = select_spec(AVAL); filter = filter_spec(PARAMCD))
@@ -72,7 +72,6 @@ as.picks <- function(x, ...) {
7272 } else if (inherits(x , " select_spec" )) {
7373 .select_spec_to_variables(x )
7474 } else if (inherits(x , " filter_spec" )) {
75- dataname <- list (... )$ dataname
7675 # warning
7776 warning(
7877 " `filter_spec` are not convertible to picks - please use `transformers` argument" ,
@@ -113,7 +112,7 @@ as.picks <- function(x, ...) {
113112teal_transform_filter <- function (x , label = " Filter" ) {
114113 checkmate :: assert_multi_class(x , c(" data_extract_spec" , " picks" ))
115114 if (inherits(x , " data_extract_spec" )) {
116- lapply(as.picks.filter(x ), teal_transform_filter , label = label )
115+ lapply(. as.picks.filter(x ), teal_transform_filter , label = label )
117116 } else {
118117 checkmate :: assert_true(" values" %in% names(x ))
119118 teal :: teal_transform_module(
@@ -123,11 +122,10 @@ teal_transform_filter <- function(x, label = "Filter") {
123122 picks_ui(ns(" transformer" ), picks = x , container = div )
124123 },
125124 server <- function (id , data ) {
126- moduleServer(id , function (input , output , session ) {
125+ shiny :: moduleServer(id , function (input , output , session ) {
127126 selector <- picks_srv(" transformer" , picks = x , data = data )
128127 reactive({
129128 req(data(), selector())
130- # todo: make sure filter call is not executed when setequal(selected, all_possible_choices)
131129 filter_call <- .make_filter_call(
132130 datasets = selector()$ datasets $ selected ,
133131 variables = selector()$ variables $ selected ,
@@ -141,7 +139,7 @@ teal_transform_filter <- function(x, label = "Filter") {
141139 }
142140}
143141
144- as.picks.filter <- function (x , dataname ) {
142+ . as.picks.filter <- function (x , dataname ) { # nolint
145143 if (inherits(x , " filter_spec" )) {
146144 if (inherits(x $ choices , " delayed_data" )) {
147145 warning(
@@ -163,12 +161,12 @@ as.picks.filter <- function(x, dataname) {
163161 values(choices = x $ choices , selected = x $ selected , multiple = x $ multiple )
164162 )
165163 } else if (checkmate :: test_list(x , " filter_spec" )) {
166- lapply(x , as.picks.filter , dataname = dataname )
164+ lapply(x , . as.picks.filter , dataname = dataname )
167165 } else if (inherits(x , " data_extract_spec" )) {
168- as.picks.filter(x $ filter , dataname = x $ dataname )
166+ . as.picks.filter(x $ filter , dataname = x $ dataname )
169167 } else if (checkmate :: test_list(x , c(" data_extract_spec" , " list" , " NULL" ))) {
170168 unlist(
171- lapply(Filter(length , x ), as.picks.filter ),
169+ lapply(Filter(length , x ), . as.picks.filter ),
172170 recursive = FALSE
173171 )
174172 }
0 commit comments