Skip to content

Commit

Permalink
no old Rd tags - partial
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Feb 7, 2024
1 parent c5e475e commit b4959ac
Show file tree
Hide file tree
Showing 39 changed files with 319 additions and 288 deletions.
4 changes: 3 additions & 1 deletion R/Queue.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#' @title R6 Class - A First-In-First-Out Abstract Data Type
#'
#' @description `r lifecycle::badge("experimental")`\cr
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' Abstract data type that stores and returns any number of elements.
#'
#' A `Queue` object stores all elements in a single vector,
Expand Down
15 changes: 7 additions & 8 deletions R/call_utils.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#' Checks `varname` argument and convert to call
#'
#' Checks `varname` type and parse if it's a `character`
#' @param varname (`name`, `call` or `character(1)`)\cr
#' name of the variable
#'
#' @param varname (`name`, `call` or `character(1)`)
#' name of the variable
#'
#' @keywords internal
#'
call_check_parse_varname <- function(varname) {
Expand Down Expand Up @@ -373,12 +375,9 @@ call_extract_matrix <- function(dataname = ".", row = NULL, column = NULL) {

#' Compose extract call with `$` operator
#'
#' @param dataname (`character(1)` or `name`)
#' name of the object
#' @param varname (`character(1)` or `name`)
#' name of the slot in data
#' @param dollar (`logical(1)`)\cr
#' whether returned call should use `$` or `[[` operator
#' @param dataname (`character(1)` or `name`) name of the object
#' @param varname (`character(1)` or `name`) name of the slot in data
#' @param dollar (`logical(1)`) whether returned call should use `$` or `[[` operator
#'
#' @return `$` or `[[` call
#'
Expand Down
2 changes: 1 addition & 1 deletion R/column_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#'
#' @return A named character vector with the non-key columns of the `data`.
#'
#' @references [data_extract_srv]
#' @references [data_extract_srv()]
get_dataset_prefixed_col_names <- function(data) {
if (!is.null(attr(data, "filter_and_columns")$columns) && attr(data, "filter_and_columns")$columns != "") {
paste(attr(data, "dataname"), attr(data, "filter_and_columns")$columns, sep = ".")
Expand Down
65 changes: 29 additions & 36 deletions R/data_extract_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,31 @@ cond_data_extract_single_ui <- function(ns, single_data_extract_spec) {
#'
#' @description `r lifecycle::badge("experimental")`
#' This functionality should be used in the encoding panel of your `teal` app.
#' It will allow app-developers to specify a [data_extract_spec] object.
#' It will allow app-developers to specify a [data_extract_spec()] object.
#' This object should be used to `teal` module variables being filtered data
#' from `CDISC` datasets. You can use this function in the same way as any
#' [shiny module](https://shiny.rstudio.com/articles/modules.html) UI.
#' [`shiny module`](https://shiny.rstudio.com/articles/modules.html) UI.
#' The corresponding server module can be found in [data_extract_srv()].
#'
#' @param id (`character`) shiny input unique identifier
#' @param label (`character`) Label above the data extract input
#' @param data_extract_spec (`list` of `data_extract_spec`)
#' This is the outcome of listing [data_extract_spec]
#' constructor calls.
#' This is the outcome of listing [data_extract_spec()] constructor calls.
#' @param is_single_dataset (`logical`) FALSE to display the dataset widget
#'
#' @return shiny [shiny::selectInput]`s` that allow to define how to extract data from
#' a specific dataset. The input elements will be returned inside a [shiny::div] container.
#'
#' There are three inputs that will be rendered
#' \enumerate{
#' \item{Dataset select}{ Optional. If more than one [data_extract_spec] is handed over
#' to the function, a shiny [shiny::selectInput] will be rendered. Else just the name
#' of the dataset is given.
#' }
#' \item{Filter Panel }{Optional. If the [data_extract_spec] contains a
#' filter element a shiny [shiny::selectInput] will be rendered with the options to
#' filter the dataset.
#' }
#' \item{Select panel }{A shiny [shiny::selectInput] to select columns from the dataset to
#' go into the analysis.
#' }
#' }
#'
#' 1. Dataset select Optional. If more than one [data_extract_spec] is handed over
#' to the function, a shiny [shiny::selectInput] will be rendered. Else just the name
#' of the dataset is given.
#' 2. Filter Panel Optional. If the [data_extract_spec] contains a
#' filter element a shiny [shiny::selectInput] will be rendered with the options to
#' filter the dataset.
#' 3. Select panel A shiny [shiny::selectInput] to select columns from the dataset to
#' go into the analysis.
#'
#' The output can be analyzed using `data_extract_srv(...)`.
#'
Expand Down Expand Up @@ -252,32 +247,30 @@ check_data_extract_spec_react <- function(datasets, data_extract) {
#' Extraction of the selector(s) details
#'
#' @description `r lifecycle::badge("stable")`
#'
#' Extracting details of the selection(s) in [data_extract_ui] elements.
#'
#' @inheritParams shiny::moduleServer
#' @param datasets (`FilteredData` or `list` of `reactive` or non-`reactive` `data.frame`)\cr
#' object containing data either in the form of `FilteredData` or as a list of `data.frame`.
#' When passing a list of non-reactive `data.frame` objects, they are converted to reactive `data.frame`s internally.
#' When passing a list of reactive or non-reactive `data.frame` objects, the argument `join_keys` is required also.
#' @param data_extract_spec (`data_extract_spec` or a list of `data_extract_spec`)\cr
#' A list of data filter and select information constructed by [data_extract_spec].
#' @param datasets (`FilteredData` or `list` of `reactive` or non-`reactive` `data.frame`)
#' object containing data either in the form of `FilteredData` or as a list of `data.frame`.
#' When passing a list of non-reactive `data.frame` objects, they are converted to reactive `data.frame`s internally.
#' When passing a list of reactive or non-reactive `data.frame` objects, the argument `join_keys` is required also.
#' @param data_extract_spec (`data_extract_spec` or a list of `data_extract_spec`)
#' A list of data filter and select information constructed by [data_extract_spec].
#' @param ...
#' an additional argument `join_keys` is required when `datasets` is a list of `data.frame`.
#' It shall contain the keys per dataset in `datasets`.
#'
#' @return
#' A reactive `list` containing following fields:
#'
#' \itemize{
#' \item{`filters`: }{A list with the information on the filters that are applied to the data set.}
#' \item{`select`: }{The variables that are selected from the dataset.}
#' \item{`always_selected`: }{The column names from the data set that should always be selected.}
#' \item{`reshape`: }{Whether reshape long to wide should be applied or not.}
#' \item{`dataname`: }{The name of the data set.}
#' \item{`internal_id`: }{The `id` of the corresponding shiny input element.}
#' \item{`keys`: }{The names of the columns that can be used to merge the data set.}
#' \item{`iv`:}{A `shinyvalidate::InputValidator` containing `validator` for this `data_extract`}
#' }
#' @return A reactive `list` containing following fields:
#'
#' * `filters`: A list with the information on the filters that are applied to the data set.
#' * `select`: The variables that are selected from the dataset.
#' * `always_selected`: The column names from the data set that should always be selected.
#' * `reshape`: Whether reshape long to wide should be applied or not.
#' * `dataname`: The name of the data set.
#' * `internal_id`: The `id` of the corresponding shiny input element.
#' * `keys`: The names of the columns that can be used to merge the data set.
#' * `iv`: A `shinyvalidate::InputValidator` containing `validator` for this `data_extract`
#'
#' @references [data_extract_srv]
#'
Expand Down
28 changes: 13 additions & 15 deletions R/data_extract_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@
#' @rdname data_extract_spec
#'
#' @section Module Development:
#' \describe{
#' `teal.transform` uses this object to construct a UI element in a module.
#' }
#'
#' @param dataname (`character`)\cr
#' The name of the dataset to be extracted.
#' @param select (`NULL`, `select_spec`-S3 class or `delayed_select_spec`)\cr
#' Columns to be selected from the input dataset
#' mentioned in `dataname`. The setup can be created using [select_spec] function.
#' @param filter (`NULL` or `filter_spec` or its respective delayed version)\cr
#' Setup of the filtering of key columns inside the dataset.
#' This setup can be created using the [filter_spec] function.
#' Please note that if both select and filter are set to NULL, then the result will be a filter spec UI with all
#' variables as possible choices and a select spec with multiple set to `TRUE`.
#' @param reshape (`logical`)\cr
#' whether reshape long to wide. Note that it will be used only in case of long dataset with multiple
#' keys selected in filter part.
#' @param dataname (`character`)
#' The name of the dataset to be extracted.
#' @param select (`NULL`, `select_spec`-S3 class or `delayed_select_spec`)
#' Columns to be selected from the input dataset
#' mentioned in `dataname`. The setup can be created using [select_spec] function.
#' @param filter (`NULL` or `filter_spec` or its respective delayed version)
#' Setup of the filtering of key columns inside the dataset.
#' This setup can be created using the [filter_spec] function.
#' Please note that if both select and filter are set to NULL, then the result will be a filter spec UI with all
#' variables as possible choices and a select spec with multiple set to `TRUE`.
#' @param reshape (`logical`)
#' whether reshape long to wide. Note that it will be used only in case of long dataset with multiple
#' keys selected in filter part.
#'
#' @examples
#' adtte_filters <- filter_spec(
Expand Down
41 changes: 21 additions & 20 deletions R/get_dplyr_call.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#' same selector - same dataset, same filter configuration and same reshape status
#' @inheritParams get_merge_call
#'
#' @return (\code{list}) simplified selectors with aggregated set of filters,
#' selections, reshapes etc. All necessary data for merging
#' @return (`list`) simplified selectors with aggregated set of filters,
#' selections, reshapes etc. All necessary data for merging
#' @keywords internal
#'
get_dplyr_call_data <- function(selector_list, join_keys = teal.data::join_keys()) {
Expand Down Expand Up @@ -121,12 +121,12 @@ get_dplyr_call_data <- function(selector_list, join_keys = teal.data::join_keys(
#'
#' Parse filter, select, rename and reshape call
#' @inheritParams get_dplyr_call_data
#' @param idx optional (\code{integer}) current selector index in all selectors list
#' @param dplyr_call_data (\code{list}) simplified selectors with aggregated set of filters,
#' selections, reshapes etc. All necessary data for merging
#' @param idx optional (`integer`) current selector index in all selectors list
#' @param dplyr_call_data (`list`) simplified selectors with aggregated set of filters,
#' selections, reshapes etc. All necessary data for merging
#' @param data (`NULL` or named `list`).
#'
#' @return (\code{call}) filter, select, rename and reshape call
#' @return (`call`) filter, select, rename and reshape call
#'
#' @examples
#' # use non-exported function from teal.transform
Expand Down Expand Up @@ -246,11 +246,11 @@ get_dplyr_call <- function(selector_list,
return(final_call)
}

#' Parse \code{dplyr} select call
#' Parse `dplyr` select call
#'
#' @param select (\code{character}) vector of selected column names
#' @param select (`character`) vector of selected column names
#'
#' @return (\code{call}) \code{dplyr} select call
#' @return (`call`) `dplyr` select call
#'
#' @examples
#' # use non-exported function from teal.transform
Expand All @@ -269,12 +269,12 @@ get_select_call <- function(select) {
as.call(c(list(quote(dplyr::select)), lapply(select, as.name)))
}

#' Returns \code{dplyr} filter call
#' Returns `dplyr` filter call
#'
#' @param filter (\code{list}) Either list of lists or list with \code{select} and \code{selected} items.
#' @param dataname (\code{NULL} or \code{character}) name of dataset.
#' @param datasets (\code{NULL} or \code{named `list`}).
#' @return (\code{call}) \code{dplyr} filter call
#' @param filter (`list`) Either list of lists or list with `select` and `selected` items.
#' @param dataname (`NULL` or `character`) name of dataset.
#' @param datasets (`NULL` or named `list`).
#' @return (`call`) `dplyr` filter call
#'
#' @examples
#' # use non-exported function from teal.transform
Expand Down Expand Up @@ -408,13 +408,14 @@ rename_duplicated_cols <- function(x, internal_id, selected_cols, all_cols) {
)
}

#' Returns \code{dplyr} rename call
#' Returns `dplyr` rename call
#'
#' Rename is used only if there are duplicated columns
#'
#' @inheritParams get_dplyr_call
#'
#' @return (\code{call}) \code{dplyr} rename call
#' @return (`call`) `dplyr` rename call
#'
#' @references get_rename_dict
#'
#' @examples
Expand Down Expand Up @@ -489,11 +490,11 @@ get_rename_call <- function(selector_list = list(),
as.call(append(quote(dplyr::rename), internal))
}

#' Returns \code{dplyr} reshape call
#' Returns `dplyr` reshape call
#'
#' @inheritParams get_dplyr_call
#'
#' @return (\code{list}) list of multiple \code{dplyr} calls that reshape data
#' @return (`list`) list of multiple `dplyr` calls that reshape data
#'
#' @examples
#' # use non-exported function from teal.transform
Expand Down Expand Up @@ -573,7 +574,7 @@ get_reshape_call <- function(selector_list = list(),
#' Get pivot longer columns
#'
#' Get values names which are spread into columns.
#' @param selector one element of selector_list obtained by \code{get_dplyr_call_data}.
#' @param selector one element of selector_list obtained by `get_dplyr_call_data`.
#' @keywords internal
#'
get_pivot_longer_col <- function(selector) {
Expand All @@ -584,7 +585,7 @@ get_pivot_longer_col <- function(selector) {
#' Get unite columns
#'
#' Get key names which spreads values into columns. Reshape is done only
#' on keys which are in \code{filter_spec}.
#' on keys which are in `filter_spec`.
#' @inheritParams get_pivot_longer_col
#' @keywords internal
#'
Expand Down
35 changes: 18 additions & 17 deletions R/get_merge_call.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,16 @@ get_merge_key_grid <- function(selector_list, join_keys = teal.data::join_keys()
#' @param selector_to (`list`) `data_extract_srv`
#' @param key_from (`character`) keys used in the first selector while joining
#'
#' @details This function covers up to now 4 cases
#' \itemize{
#' \item{dataset without parent }{ Primary keys are returned}
#' \item{dataset source = dataset target}{
#' The primary keys subtracted of all key columns that
#' get purely filtered. This means just one value would
#' be left after filtering inside this column. Then it
#' can be taken out.
#' }
#' \item{target `dataname` is parent }{ foreign keys}
#' \item{any other case }{foreign keys}
#' }
#' @details
#' This function covers up to now 4 cases
#'
#' * dataset without parent: Primary keys are returned
#' * dataset source = dataset target:
#' The primary keys subtracted of all key columns that get purely filtered.
#' This means just one value would be left after filtering inside this column.
#' Then it can be taken out.
#' * target `dataname` is parent foreign keys
#' * any other case foreign keys
#'
#' @return (`character`)
#' @keywords internal
Expand Down Expand Up @@ -335,10 +333,11 @@ get_dropped_filters <- function(selector) {

#' Gets the relabel call
#'
#' @description `r lifecycle::badge("stable")`
#' `r lifecycle::badge("stable")`
#'
#' @inheritParams merge_datasets
#' @param columns_source \code{named list}\cr
#' where names are column names, values are labels + additional attribute `dataname`
#' @param columns_source named `list`
#' where names are column names, values are labels + additional attribute `dataname`
#'
#' @return (`call`) to relabel `dataset` and assign to `anl_name`.
#'
Expand Down Expand Up @@ -404,9 +403,11 @@ get_anl_relabel_call <- function(columns_source, datasets, anl_name = "ANL") {
#' Create relabel call from named character
#'
#' @description `r lifecycle::badge("stable")`
#'
#' Function creates relabel call from named character.
#' @param labels (`named character`)\cr
#' where name is name is function argument name and value is a function argument value.
#'
#' @param labels (`named character`)
#' where name is name is function argument name and value is a function argument value.
#'
#' @return (`call`) object with relabel step
#' @examples
Expand Down
7 changes: 5 additions & 2 deletions R/merge_datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,12 @@ merge_selectors <- function(selector_list) {
#' Validate data_extracts in merge_datasets
#'
#' Validate selected inputs from data_extract before passing to data_merge to avoid
#' \code{dplyr} errors or unexpected results
#' `dplyr` errors or unexpected results
#'
#' @inheritParams merge_datasets
#' @return \code{NULL} if check is successful
#'
#' @return `NULL` if check is successful
#'
#' @keywords internal
#'
check_data_merge_selectors <- function(selector_list) {
Expand Down
Loading

0 comments on commit b4959ac

Please sign in to comment.