R/utils.R

Defines functions column_first strip_plexset_suffix transform_log10_infinite

#' autoplot generic
#'
#' See \code{ggplot2::\link[ggplot2]{autoplot}} for details.
#'
#' @name autoplot
#' @rdname autoplot
#' @keywords internal
#' @export
#' @importFrom ggplot2 autoplot
NULL

#' Log-10 transform that keeps infinite values
#'
#' Maps `-Inf` and `Inf` to themselves, so shaded bands can extend
#' to the panel edges on a log-10 axis without triggering a warning.
#'
#' @noRd
#'
#' @return A `transform` object from [scales::new_transform()].
transform_log10_infinite <- function() {
  scales::new_transform(
    name = "log-10-infinite",
    transform = function(x) {
      finite <- !is.infinite(x)
      x[finite] <- log10(x[finite])
      x
    },
    inverse = function(x) {
      finite <- !is.infinite(x)
      x[finite] <- 10^x[finite]
      x
    },
    d_transform = function(x) 1 / (x * log(10)),
    d_inverse = function(x) 10^x * log(10),
    breaks = scales::breaks_log(base = 10),
    domain = c(1e-100, Inf)
  )
}

#' Drop the PlexSet suffix from sample identifiers
#'
#' PlexSet samples are named `<file>_S1` to `<file>_S8`. Lane-level plots
#' group the eight samples of a lane back under their file name.
#'
#' @noRd
#'
#' @return A copy of `data` with the suffix removed from `id_colname`.
strip_plexset_suffix <- function(data, id_colname) {
  data <- data.table::copy(data)
  data[[id_colname]] <- sub("_S[0-9]*$", "", data[[id_colname]])
  data
}

#' Move a column to the front of a data frame
#'
#' @noRd
column_first <- function(data, column) {
  data[, c(column, setdiff(names(data), column)), drop = FALSE]
}

Try the NACHO package in your browser

Any scripts or data that you put into this service are public.

NACHO documentation built on Nov. 2, 2026, 5:09 p.m.