From cec59bb5dfe7accd3eba3609d8b0a63742a31f7f Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 5 Mar 2024 13:45:10 +0100 Subject: [PATCH] clean_brushedPoints --- R/plot_with_settings.R | 34 +++++++++++++++++++++++++++++----- man/clean_brushedPoints.Rd | 34 +++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/R/plot_with_settings.R b/R/plot_with_settings.R index 4b8f2bc9..1bbfe042 100644 --- a/R/plot_with_settings.R +++ b/R/plot_with_settings.R @@ -596,15 +596,39 @@ type_download_srv <- function(id, plot_reactive, plot_type, plot_w, default_w, p ) } -#' Cleans and organizes output to account for NAs and remove empty rows. +#' Clean brushed points #' -#' @description `r lifecycle::badge("stable")` +#' @description `r lifecycle::badge("stable")`\cr +#' Cleans and organizes output to account for NAs and remove empty rows. Wrapper around `shiny::brushedPoints`. #' @param data (`data.frame`)\cr -#' A dataframe from which to select rows. +#' A data.frame from which to select rows. #' @param brush (`list`)\cr -#' The data from a brush e.g. input$plot_brush. +#' The data from a brush e.g. `input$plot_brush`. +#' +#' @return A `data.frame` of selected rows. +#' +#' @examples +#' +#' brush <- list( +#' mapping = list( +#' x = "AGE", +#' y = "BMRKR1" +#' ), +#' xmin = 30, xmax = 40, +#' ymin = 0.7, ymax = 10, +#' direction = "xy" +#' ) +#' +#' data <- data.frame( +#' STUDYID = letters[1:20], +#' USUBJID = LETTERS[1:20], +#' AGE = sample(25:40, size = 20, replace = TRUE), +#' BMRKR1 = runif(20, min = 0, max = 12) +#' ) +#' nrow(clean_brushedPoints(data, brush)) +#' data$AGE[1:10] <- NA +#' nrow(clean_brushedPoints(data, brush)) #' -#' @return A dataframe of selected rows. #' @export #' clean_brushedPoints <- function(data, brush) { # nolint object_name_linter. diff --git a/man/clean_brushedPoints.Rd b/man/clean_brushedPoints.Rd index 76e17595..36980fe0 100644 --- a/man/clean_brushedPoints.Rd +++ b/man/clean_brushedPoints.Rd @@ -2,20 +2,44 @@ % Please edit documentation in R/plot_with_settings.R \name{clean_brushedPoints} \alias{clean_brushedPoints} -\title{Cleans and organizes output to account for NAs and remove empty rows.} +\title{Clean brushed points} \usage{ clean_brushedPoints(data, brush) } \arguments{ \item{data}{(\code{data.frame})\cr -A dataframe from which to select rows.} +A data.frame from which to select rows.} \item{brush}{(\code{list})\cr -The data from a brush e.g. input$plot_brush.} +The data from a brush e.g. \code{input$plot_brush}.} } \value{ -A dataframe of selected rows. +A \code{data.frame} of selected rows. } \description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}}\cr +Cleans and organizes output to account for NAs and remove empty rows. Wrapper around \code{shiny::brushedPoints}. +} +\examples{ + +brush <- list( + mapping = list( + x = "AGE", + y = "BMRKR1" + ), + xmin = 30, xmax = 40, + ymin = 0.7, ymax = 10, + direction = "xy" +) + +data <- data.frame( + STUDYID = letters[1:20], + USUBJID = LETTERS[1:20], + AGE = sample(25:40, size = 20, replace = TRUE), + BMRKR1 = runif(20, min = 0, max = 12) +) +nrow(clean_brushedPoints(data, brush)) +data$AGE[1:10] <- NA +nrow(clean_brushedPoints(data, brush)) + }