Title: | General utility functions for developing Bioconductor packages |
---|---|
Description: | The package provides utility functions related to package development. These include functions that replace slots, and selectors for show methods. It aims to coalesce the various helper functions often re-used throughout the Bioconductor ecosystem. |
Authors: | Marcel Ramos [aut, cre] , Martin Morgan [ctb], Hervé Pagès [ctb] |
Maintainer: | Marcel Ramos <[email protected]> |
License: | Artistic-2.0 |
Version: | 1.9.0 |
Built: | 2024-10-29 23:13:50 UTC |
Source: | https://github.com/Bioconductor/BiocBaseUtils |
BiocBaseUtils is a package aimed at helping the typical Bioconductor developer formalize often written functions that can be seen scattered throughout the Bioconductor ecosystem. Some of these functions include the ability to replace slots in an object. Other functions work to create a nice show method output by selecting some observations.
Maintainer: Marcel Ramos [email protected] (ORCID)
Other contributors:
Martin Morgan [email protected] [contributor]
Hervé Pagès [email protected] [contributor]
Useful links:
Report bugs at https://www.github.com/Bioconductor/BiocBaseUtils/issues
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 |
|
test_fun <- function() { lifeCycle(newfun = "new_test", package = "BiocBaseUtils") } tryCatch( test_fun(), warning = function(w) message(w) ) test_fun <- function() { lifeCycle( newfun = "new_test", package = "BiocBaseUtils", cycle = "defunct" ) } tryCatch( test_fun(), error = function(e) message(e) )
test_fun <- function() { lifeCycle(newfun = "new_test", package = "BiocBaseUtils") } tryCatch( test_fun(), warning = function(w) message(w) ) test_fun <- function() { lifeCycle( newfun = "new_test", package = "BiocBaseUtils", cycle = "defunct" ) } 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")