| Title: | Utility and internal functions for Bioconductor packages |
|---|---|
| Description: | The package coalesces typical helper functions that are scattered throughout the Bioconductor ecosystem. It aims to reduce code redundancy by formalizing functions often used by Bioconductor developers. These functions include operations such as replacing slots in an object, selecting observations for show methods, labeling function life cycles, and more. |
| Authors: | Marcel Ramos [aut, cre] (ORCID: <https://orcid.org/0000-0002-3242-0582>), Martin Morgan [ctb], Hervé Pagès [ctb] |
| Maintainer: | Marcel Ramos <[email protected]> |
| License: | Artistic-2.0 |
| Version: | 1.15.1 |
| Built: | 2026-05-08 21:00:15 UTC |
| Source: | https://github.com/bioc/BiocBaseUtils |
Ask user for a yes/no response
askUserYesNo(prompt, interactive.only = TRUE)askUserYesNo(prompt, interactive.only = TRUE)
prompt |
|
interactive.only |
|
TRUE when user replies with 'yes' to prompt, FALSE when 'no'
Martin M.
askUserYesNo("Do you want to continue?")askUserYesNo("Do you want to continue?")
These are a group of helper functions that allow the developer to easily check for common data types in Bioconductor. These include logical, character, and numeric (& integer).
isTRUEorFALSE(x, na.ok = FALSE) isScalarCharacter(x, na.ok = FALSE, zchar = FALSE) isScalarInteger(x, na.ok = FALSE) isScalarNumber(x, na.ok = FALSE, infinite.ok = FALSE) isScalarLogical(x, na.ok = FALSE) isCharacter(x, na.ok = FALSE, zchar = FALSE) isZeroOneCharacter(x, na.ok = FALSE, zchar = FALSE)isTRUEorFALSE(x, na.ok = FALSE) isScalarCharacter(x, na.ok = FALSE, zchar = FALSE) isScalarInteger(x, na.ok = FALSE) isScalarNumber(x, na.ok = FALSE, infinite.ok = FALSE) isScalarLogical(x, na.ok = FALSE) isCharacter(x, na.ok = FALSE, zchar = FALSE) isZeroOneCharacter(x, na.ok = FALSE, zchar = FALSE)
x |
The input vector whose type is to be checked |
na.ok |
logical(1L) Whether it is acceptable to consider |
zchar |
logical(1L) Whether is is acceptable to consider 'zero'
characters as defined by |
infinite.ok |
logical(1L) Whether it is acceptable to consider infinite
values as identified by |
Some functions such as isScalarCharacter allow exceptions to the type
checks via the na.ok and zchar arguments. Others, for example
isScalarNumber can permit Inf with the infinite.ok argument.
Either TRUE or FALSE
isTRUEorFALSE(): Is the input a single logical vector?
isScalarCharacter(): Is the input a single character vector?
isScalarInteger(): Is the input a single integer vector?
isScalarNumber(): Is the input a single numeric vector?
isScalarLogical(): Is the input a single logical vector?
isCharacter(): Is the input a character vector?
isZeroOneCharacter(): Is the input a character vector of zero or one length?
M. Morgan, H. Pagès
isTRUEorFALSE(TRUE) isTRUEorFALSE(FALSE) isTRUEorFALSE(NA, na.ok = TRUE) isScalarCharacter(LETTERS) isScalarCharacter("L") isCharacter(LETTERS) isCharacter(NA_character_, na.ok = TRUE) isZeroOneCharacter("") isZeroOneCharacter("", zchar = TRUE) isScalarInteger(1L) isScalarInteger(1) isScalarNumber(1) isScalarNumber(1:2)isTRUEorFALSE(TRUE) isTRUEorFALSE(FALSE) isTRUEorFALSE(NA, na.ok = TRUE) isScalarCharacter(LETTERS) isScalarCharacter("L") isCharacter(LETTERS) isCharacter(NA_character_, na.ok = TRUE) isZeroOneCharacter("") isZeroOneCharacter("", zchar = TRUE) isScalarInteger(1L) isScalarInteger(1) isScalarNumber(1) isScalarNumber(1:2)
checkInstalled allows to check if a package is installed. If the package is
not available, a convenient copy-and-paste message is provided for package
installation with BiocManager. The function is typically used within
functions that check for package availability from the Suggests field.
checkInstalled(pkgs)checkInstalled(pkgs)
pkgs |
|
TRUE if all packages are installed, otherwise stops with a message
and suggests installation of missing packages
M. Morgan, M. Ramos
if (interactive()) { checkInstalled( c("BiocParallel", "SummarizedExperiment") ) }if (interactive()) { checkInstalled( c("BiocParallel", "SummarizedExperiment") ) }
The lifeCycle function is used to set the life cycle stage of
a function. It is to be used within the body of the function that is being
deprecated or defunct. It is a wrapper around both .Deprecated and
.Defunct base R functions.
lifeCycle( newfun = oldfun, newpackage, package, cycle = c("deprecated", "defunct"), title = package )lifeCycle( newfun = oldfun, newpackage, package, cycle = c("deprecated", "defunct"), title = package )
newfun |
|
newpackage |
|
package |
|
cycle |
|
title |
|
Called for the side effect of issuing a warning or error message when a function is deprecated or defunct, respectively. The message includes the name of the function, the life cycle stage, and a suggestion for an alternative function to use.'
test_fun <- function() { lifeCycle(newfun = "new_test", package = "BiocBaseUtils") } ## catch warning and convert to message tryCatch(test_fun(), warning = function(w) message(w)) test_fun <- function() { lifeCycle( newfun = "new_test", package = "BiocBaseUtils", cycle = "defunct" ) } ## catch error and convert to message tryCatch(test_fun(), error = function(e) message(e))test_fun <- function() { lifeCycle(newfun = "new_test", package = "BiocBaseUtils") } ## catch warning and convert to message tryCatch(test_fun(), warning = function(w) message(w)) test_fun <- function() { lifeCycle( newfun = "new_test", package = "BiocBaseUtils", cycle = "defunct" ) } ## catch error and convert to message tryCatch(test_fun(), error = function(e) message(e))
selectSome works well in show methods. It abbreviates a vector input
depending on the maxToShow argument.
selectSome( obj, maxToShow = 5, ellipsis = "...", ellipsisPos = c("middle", "end", "start"), quote = FALSE )selectSome( obj, maxToShow = 5, ellipsis = "...", ellipsisPos = c("middle", "end", "start"), quote = FALSE )
obj |
character() A vector to be abbreviated for display purposes |
maxToShow |
numeric(1) The maximum number of values to show in the output (default: 5) |
ellipsis |
character(1) The symbol used to abbreviate values in the vector (default: "...") |
ellipsisPos |
character(1) The location for the ellipsis in the output,
by default in the |
quote |
logical(1) Whether or not to add a single quote around the |
An abbreviated output of obj
M. Morgan, H. Pagès
letters selectSome(letters)letters selectSome(letters)
Given the current object, the function setSlots will take name-value
pair inputs either as named arguments or a list and replace the values of
the specified slots. This is a convenient function for updating slots in
an S4 class object.
setSlots(object, ..., check = TRUE)setSlots(object, ..., check = TRUE)
object |
An S4 object with slots to replace |
... |
Slot name and value pairs either as named arguments
or a named list, e.g., |
check |
logical(1L) Whether to run validObject after the slot replacement |
The object input with updated slot data
H. Pagès
setClass("A", representation = representation(slotA = "character")) aclass <- new("A", slotA = "A") setSlots(aclass, slotA = "B")setClass("A", representation = representation(slotA = "character")) aclass <- new("A", slotA = "A") setSlots(aclass, slotA = "B")