diff --git a/DESCRIPTION b/DESCRIPTION index d3f2b9d..9820548 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: tidygate Type: Package Title: Interactively Gate Points -Version: 1.0.12 +Version: 1.0.13 Authors@R: c(person(given = "Stefano", family = "Mangiola", diff --git a/NAMESPACE b/NAMESPACE index a7fb30a..368ae90 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,11 +4,8 @@ S3method(gate_chr,numeric) S3method(gate_int,numeric) export(fhs) export(gate) -export(gate.spec_tbl_df) -export(gate.tbl_df) export(gate_chr) export(gate_int) -export(gate_old) export(server) export(ui) import(dplyr) diff --git a/R/fhs.R b/R/fhs.R index 9332878..5e2c526 100644 --- a/R/fhs.R +++ b/R/fhs.R @@ -22,11 +22,11 @@ ##' @importFrom lifecycle deprecate_warn ##' @export ##' @examples -##' \dontrun{ -##' x <- cbind(1:10, 1:10) -##' rownames(x) <- 1:10 -##' plot(x, pch = 16, col = "red") -##' fhs(x) +##' if(interactive()) { +##' x <- cbind(1:10, 1:10) +##' rownames(x) <- 1:10 +##' plot(x, pch = 16, col = "red") +##' fhs(x) ##' } ##' @importFrom graphics locator lines points fhs <- function(data, mark = TRUE, names = TRUE, ...) { diff --git a/R/gate_app.R b/R/gate_app.R index a971ed7..e8dfffe 100644 --- a/R/gate_app.R +++ b/R/gate_app.R @@ -63,10 +63,11 @@ ui <- shiny::fluidPage( #' @export server <- function(input, output, session) { - # Fix CRAN note + # Fix CRAN notes key <- NULL curveNumber <- NULL pointNumber <- NULL + .gate <- NULL select_data <- tibble() brush_data <- tibble() diff --git a/R/methods.R b/R/methods.R index 181d435..c6d30a7 100755 --- a/R/methods.R +++ b/R/methods.R @@ -11,7 +11,7 @@ utils::globalVariables(c(".key", ".rs.invokeShinyPaneViewer")) #' @importFrom rlang quo_is_null #' @importFrom magrittr "%>%" #' @importFrom lifecycle deprecate_warn -#' +#' #' @name gate_chr #' #' @@ -30,19 +30,15 @@ utils::globalVariables(c(".key", ".rs.invokeShinyPaneViewer")) #' #' @return An character vector, with "0" for elements outside gates and "1..N" for the elements inside the N gates. #' -#' #' @examples #' -#' \dontrun{ #' # Standard use - interactive #' -#' if(interactive()){ -#' -#' tidygate::tidygate_data %>% -#' distinct(`ct 1` , `ct 2`, Dim1, Dim2) %>% -#' mutate(gate = gate_chr( Dim1, Dim2)) +#' if(interactive()){ #' -#' } +#' tidygate::tidygate_data %>% +#' distinct(`ct 1` , `ct 2`, Dim1, Dim2) %>% +#' mutate(gate = gate_chr( Dim1, Dim2)) #' #' } #' @@ -227,11 +223,6 @@ gate_int.numeric = function( .dim1, #' point size, either a numeric or factor of 6 or less levels. #' @return A vector of strings, of the gates each X and Y coordinate pair is within. If gates are #' drawn interactively, they are temporarily saved to `tidygate_env$gates` -#' @examples -#' \dontrun{ -#' mtcars |> -#' mutate(selected = gate_interactive(x = mpg, y = wt, shape = am)) -#'} gate_interactive <- function(x, y, colour = NULL, shape = NULL, alpha = 1, size = 2) { @@ -467,15 +458,18 @@ gate_programmatic <- #' @return A vector of strings, of the gates each X and Y coordinate pair is within. If gates are #' drawn interactively, they are temporarily saved to `tidygate_env$gates`. #' @examples -#' \dontrun{ +#' library(dplyr) +#' data("demo_gate_data", package = "tidygate") +#' #' # Gate points interactively -#' mtcars |> -#' mutate(gated = gate(x = mpg, y = wt, shape = am)) +#' if(interactive()) { +#' mtcars |> +#' mutate(gated = gate(x = mpg, y = wt, shape = am)) +#' } #' #' # Gate points programmatically #' mtcars |> -#' mutate(gated = gate(x = mpg, y = wt, programmatic_gates = tidygate_env$programmatic_gates)) -#'} +#' mutate(gated = gate(x = mpg, y = wt, programmatic_gates = demo_gate_data)) #' @export gate <- function(x, y, colour = NULL, shape = NULL, alpha = 1, size = 2, programmatic_gates = NULL) { diff --git a/R/methods_OLD.R b/R/methods_OLD.R deleted file mode 100644 index 8488c0e..0000000 --- a/R/methods_OLD.R +++ /dev/null @@ -1,188 +0,0 @@ -#' DEPRECATED - use gate_chr, gate_int instead inside a dplyr::mutate() statement -#' -#' \lifecycle{maturing} -#' -#' @keywords internal -#' -#' @description gate() takes as input a `tbl` formatted as | | | <...> | and calculates the rotated dimensional space of the feature value. -#' -#' @importFrom rlang enquo -#' @importFrom magrittr "%>%" -#' @importFrom lifecycle deprecate_warn -#' -#' @name gate_old -#' -#' -#' @param .data A tibble -#' @param .element A column symbol. The column that is used to calculate distance (i.e., normally genes) -#' @param .dim1 A column symbol. The x dimension -#' @param .dim2 A column symbol. The y dimension -#' @param .color A column symbol. Color of points -#' @param .shape A column symbol. Shape of points -#' @param .size A column symbol. Size of points -#' @param opacity A number between 0 and 1. The opacity level of the data points -#' @param how_many_gates An integer. The number of gates to label -#' @param gate_list A list of gates. It is returned by gate function as attribute \"gate\". If you want to create this list yourself, each element of the list is a data frame with x and y columns. Each row is a coordinate. The order matter. -#' @param name A character string. The name of the new column -#' @param action A character string. Whether to join the new information to the input tbl (add), or just get the non-redundant tbl with the new information (get). -#' @param ... Further parameters passed to the function gatepoints::fhs -#' -#' @details This function allow the user to label data points in inside one or more 2D gates. This package is based on on the package gatepoints. -#' -#' @return A tbl object with additional columns for the inside gate information. additional columns for the rotated dimensions. The rotated dimensions will be added to the original data set as ` rotated ` by default, or as specified in the input arguments. -#' -#' -#' @examples -#' -#' \dontrun{ -#' -#' if(interactive()){ -#' -#' tidygate::tidygate_data %>% -#' gate( .element = c(`ct 1`, `ct 2`), Dim1, Dim2 ) -#' -#' } -#' -#' -#' -#' library(magrittr) -#' -#' tidygate::tidygate_data %>% -#' gate( -#' .element = c(`ct 1`, `ct 2`), -#' Dim1, Dim2, -#' gate_list = tidygate::gate_list -#' ) -#' } -#' @docType methods -#' @rdname gate-methods -#' @export -#' -#' -#' -#' -gate_old <- function(.data, - .element, - .dim1, - .dim2, - .color = NULL, - .shape = NULL, - .size = NULL, - opacity = 1, - how_many_gates = 1, - gate_list = NULL, - name = "gate", - action = "add", ...) { - UseMethod("gate") -} - - - -# Set internal -.gate = function(.data, - .element, - .dim1, - .dim2, - .color = NULL, - .shape = NULL, - .size = NULL, - opacity = 1, - how_many_gates = 1, - gate_list = NULL, - name = "gate", - action = "add", ...) -{ - - deprecate_warn("0.3.0", "gate()", "gate_chr()") - - # Get column names - .element = enquo(.element) - .dim1 = enquo(.dim1) - .dim2 = enquo(.dim2) - .color = enquo(.color) - .shape = enquo(.shape) - - .data_processed = - - .data %>% - when( - - # Interactive - is.null(gate_list) ~ (.) %>% - gate_interactive( - .element = !!.element, - .dim1 = !!.dim1, - .dim2 = !!.dim2, - .color = !!.color, - .shape = !!.shape, - - # size can be number of column - .size = .size %>% when(is.null(.size) | is(., "numeric") ~ (.), ~ !!enquo(.)), - - opacity = opacity, - how_many_gates = how_many_gates, - name = name, - ... - ), - - # Programmatic - is.list(gate_list) ~ (.) %>% - gate_programmatic( - .element = !!.element, - .dim1 = !!.dim1, - .dim2 = !!.dim2, - gate_list = gate_list, - name = name - ), - - # Else error - ~ stop("tidygate says: the parameter gate_list has to be NULL or a list of data frames") - ) - - - if (action == "add"){ - - .data %>% - dplyr::left_join( .data_processed, by = quo_names(.element) ) %>% - - # Reattach internals - reattach_internals(.data_processed) - - } - else if (action == "get"){ - - .data %>% - - # Selecting the right columns - select( - !!.element, - get_specific_annotation_columns(.data, !!.element) - ) %>% - distinct() %>% - - dplyr::left_join( .data_processed, by = quo_names(.element) ) %>% - - # Reattach internals - reattach_internals(.data_processed) - - } - else if (action == "only") .data_processed - else - stop( - "tidygate says: action must be either \"add\" for adding this information to your data frame or \"get\" to just get the information" - ) -} - -#' gate -#' @docType methods -#' @rdname gate-methods -#' @export -#' @return A tbl object with additional columns for the reduced dimensions. additional columns for the rotated dimensions. The rotated dimensions will be added to the original data set as ` rotated ` by default, or as specified in the input arguments. -gate.spec_tbl_df = gate.tbl_df = .gate - -#' gate -#' @docType methods -#' @rdname gate-methods -#' @export -#' @return A tbl object with additional columns for the reduced dimensions. additional columns for the rotated dimensions. The rotated dimensions will be added to the original data set as ` rotated ` by default, or as specified in the input arguments. -gate.tbl_df = .gate \ No newline at end of file diff --git a/man/fhs.Rd b/man/fhs.Rd index c21ba94..7fcde99 100644 --- a/man/fhs.Rd +++ b/man/fhs.Rd @@ -32,11 +32,11 @@ The function will return the rownames of the enclosed points by the rownames of th co-ordinates given in \code{data}. } \examples{ -\dontrun{ -x <- cbind(1:10, 1:10) -rownames(x) <- 1:10 -plot(x, pch = 16, col = "red") -fhs(x) +if(interactive()) { + x <- cbind(1:10, 1:10) + rownames(x) <- 1:10 + plot(x, pch = 16, col = "red") + fhs(x) } } \author{ diff --git a/man/gate-methods.Rd b/man/gate-methods.Rd deleted file mode 100644 index 4a8bee7..0000000 --- a/man/gate-methods.Rd +++ /dev/null @@ -1,123 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/methods_OLD.R -\docType{methods} -\name{gate_old} -\alias{gate_old} -\alias{gate.spec_tbl_df} -\alias{gate.tbl_df} -\title{DEPRECATED - use gate_chr, gate_int instead inside a dplyr::mutate() statement} -\usage{ -gate_old( - .data, - .element, - .dim1, - .dim2, - .color = NULL, - .shape = NULL, - .size = NULL, - opacity = 1, - how_many_gates = 1, - gate_list = NULL, - name = "gate", - action = "add", - ... -) - -gate.spec_tbl_df( - .data, - .element, - .dim1, - .dim2, - .color = NULL, - .shape = NULL, - .size = NULL, - opacity = 1, - how_many_gates = 1, - gate_list = NULL, - name = "gate", - action = "add", - ... -) - -gate.tbl_df( - .data, - .element, - .dim1, - .dim2, - .color = NULL, - .shape = NULL, - .size = NULL, - opacity = 1, - how_many_gates = 1, - gate_list = NULL, - name = "gate", - action = "add", - ... -) -} -\arguments{ -\item{.data}{A tibble} - -\item{.element}{A column symbol. The column that is used to calculate distance (i.e., normally genes)} - -\item{.dim1}{A column symbol. The x dimension} - -\item{.dim2}{A column symbol. The y dimension} - -\item{.color}{A column symbol. Color of points} - -\item{.shape}{A column symbol. Shape of points} - -\item{.size}{A column symbol. Size of points} - -\item{opacity}{A number between 0 and 1. The opacity level of the data points} - -\item{how_many_gates}{An integer. The number of gates to label} - -\item{gate_list}{A list of gates. It is returned by gate function as attribute \"gate\". If you want to create this list yourself, each element of the list is a data frame with x and y columns. Each row is a coordinate. The order matter.} - -\item{name}{A character string. The name of the new column} - -\item{action}{A character string. Whether to join the new information to the input tbl (add), or just get the non-redundant tbl with the new information (get).} - -\item{...}{Further parameters passed to the function gatepoints::fhs} -} -\value{ -A tbl object with additional columns for the inside gate information. additional columns for the rotated dimensions. The rotated dimensions will be added to the original data set as ` rotated ` by default, or as specified in the input arguments. - -A tbl object with additional columns for the reduced dimensions. additional columns for the rotated dimensions. The rotated dimensions will be added to the original data set as ` rotated ` by default, or as specified in the input arguments. - -A tbl object with additional columns for the reduced dimensions. additional columns for the rotated dimensions. The rotated dimensions will be added to the original data set as ` rotated ` by default, or as specified in the input arguments. -} -\description{ -gate() takes as input a `tbl` formatted as | | | <...> | and calculates the rotated dimensional space of the feature value. -} -\details{ -\lifecycle{maturing} - -This function allow the user to label data points in inside one or more 2D gates. This package is based on on the package gatepoints. -} -\examples{ - -\dontrun{ - - if(interactive()){ - - tidygate::tidygate_data \%>\% - gate( .element = c(`ct 1`, `ct 2`), Dim1, Dim2 ) - - } - - - -library(magrittr) - -tidygate::tidygate_data \%>\% - gate( - .element = c(`ct 1`, `ct 2`), - Dim1, Dim2, - gate_list = tidygate::gate_list - ) -} -} -\keyword{internal} diff --git a/man/gate.Rd b/man/gate.Rd index 06489d3..6063f5b 100644 --- a/man/gate.Rd +++ b/man/gate.Rd @@ -49,13 +49,16 @@ programmatically. This feature allows the reproduction of previously drawn inter Programmatic gating is based on the package gatepoints by Wajid Jawaid. } \examples{ -\dontrun{ +library(dplyr) +data("demo_gate_data", package = "tidygate") + # Gate points interactively -mtcars |> - mutate(gated = gate(x = mpg, y = wt, shape = am)) +if(interactive()) { + mtcars |> + mutate(gated = gate(x = mpg, y = wt, shape = am)) +} # Gate points programmatically mtcars |> - mutate(gated = gate(x = mpg, y = wt, programmatic_gates = tidygate_env$programmatic_gates)) -} + mutate(gated = gate(x = mpg, y = wt, programmatic_gates = demo_gate_data)) } diff --git a/man/gate_chr-methods.Rd b/man/gate_chr-methods.Rd index a35f6c5..3944b43 100644 --- a/man/gate_chr-methods.Rd +++ b/man/gate_chr-methods.Rd @@ -68,16 +68,13 @@ This function allow the user to label data points in inside one or more 2D gates } \examples{ -\dontrun{ # Standard use - interactive - if(interactive()){ +if(interactive()){ - tidygate::tidygate_data \%>\% - distinct(`ct 1` , `ct 2`, Dim1, Dim2) \%>\% - mutate(gate = gate_chr( Dim1, Dim2)) - - } + tidygate::tidygate_data \%>\% + distinct(`ct 1` , `ct 2`, Dim1, Dim2) \%>\% + mutate(gate = gate_chr( Dim1, Dim2)) } diff --git a/man/gate_interactive.Rd b/man/gate_interactive.Rd index ac3f014..f497925 100644 --- a/man/gate_interactive.Rd +++ b/man/gate_interactive.Rd @@ -32,9 +32,3 @@ Create an interactive scatter plot based on user-defined X and Y coordinates. Co and alpha can be defined as constant values, or can be controlled by values in a specified column. } -\examples{ -\dontrun{ -mtcars |> - mutate(selected = gate_interactive(x = mpg, y = wt, shape = am)) -} -}