% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/as_picks.R
\name{as.picks}
\alias{as.picks}
\alias{teal_transform_filter}
\title{Convert data_extract_spec to picks}
\usage{
as.picks(x, quiet = FALSE)

teal_transform_filter(x, label = "Filter")
}
\arguments{
\item{x}{(\code{data_extract_spec}, \code{select_spec}, \code{filter_spec}) object to convert to \code{\link{picks}}}

\item{quiet}{(\code{logical(1)}) whether to suppress warnings about non-convertible elements.}

\item{label}{(\code{character(1)}) Label of the module.}
}
\value{
A \code{picks} object when conversion is possible, otherwise \code{NULL} with a warning (if \code{quiet = FALSE}).
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
Helper functions to ease transition between \code{\link[teal.transform:data_extract_spec]{teal.transform::data_extract_spec()}} and \code{\link[=picks]{picks()}}.
}
\details{
With introduction of \code{\link{picks}}, \code{\link[teal.transform:data_extract_spec]{data_extract_spec}} will no longer serve a primary tool to
define variable choices and default selection in teal-modules and eventually \code{\link[teal.transform:data_extract_spec]{data_extract_spec}}
will be deprecated.
To ease the transition to the new tool, we provide \code{as.picks} method which can handle 1:1
conversion from \code{\link[teal.transform:data_extract_spec]{data_extract_spec}} to \code{\link{picks}}. Unfortunately, when \code{\link[teal.transform:data_extract_spec]{data_extract_spec}}
contains \code{\link[teal.transform:filter_spec]{filter_spec}} then \code{as.picks} is unable to provide reliable \code{\link{picks}} equivalent.
}
\examples{
# convert des with eager select_spec
as.picks(
  teal.transform::data_extract_spec(
    dataname = "iris",
    teal.transform::select_spec(
      choices = c("Sepal.Length", "Sepal.Width", "Species"),
      selected = c("Sepal.Length", "Species"),
      multiple = TRUE,
      ordered = TRUE
    )
  )
)

# convert des with delayed select_spec
as.picks(
  teal.transform::data_extract_spec(
    dataname = "iris",
    teal.transform::select_spec(
      choices = teal.transform::variable_choices("iris"),
      selected = teal.transform::first_choice(),
      multiple = TRUE,
      ordered = TRUE
    )
  )
)

as.picks(
  teal.transform::data_extract_spec(
    dataname = "iris",
    teal.transform::select_spec(
      choices = teal.transform::variable_choices(
        "iris",
        subset = function(data) names(Filter(is.numeric, data))
      ),
      selected = teal.transform::first_choice(),
      multiple = TRUE,
      ordered = TRUE
    )
  )
)

# teal_transform_module build on teal.transform

teal_transform_filter(
  teal.transform::data_extract_spec(
    dataname = "iris",
    filter = teal.transform::filter_spec(
      vars = "Species",
      choices = c("setosa", "versicolor", "virginica"),
      selected = c("setosa", "versicolor")
    )
  )
)

teal_transform_filter(
  picks(
    datasets(choices = "iris", select = "iris"),
    variables(choices = "Species", "Species"),
    values(
      choices = c("setosa", "versicolor", "virginica"),
      selected = c("setosa", "versicolor")
    )
  )
)

}
