knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

BiocBaseUtils

The BiocBaseUtils package provides a suite of helper functions designed to help developers. Currently, it covers three topics often encountered during the development process.

  1. Assertions - Type checks for logical, character, and numeric inputs
  2. Slot replacement - Replacing the value of object slots
  3. show method - Limiting the output of internal components of a class

Installation

Install the package directly from Bioconductor:

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("BiocBaseUtils")

Load Package

library(BiocBaseUtils)

Assertions

We provide a number of functions that helps the developer establish the type of class of a particular object. These include integer, numeric, character, and logical; types often used in R / Bioconductor.

Logical

isTRUEorFALSE(TRUE)
isTRUEorFALSE(FALSE)
isTRUEorFALSE(NA, na.ok = TRUE)

Character

isScalarCharacter(LETTERS)
isScalarCharacter("L")
isCharacter(LETTERS)
isCharacter(NA_character_, na.ok = TRUE)
isZeroOneCharacter("")
isZeroOneCharacter("", zchar = TRUE)

Numeric

isScalarInteger(1L)
isScalarInteger(1)

isScalarNumber(1)
isScalarNumber(1:2)

Slot replacement

This function is often used in packages that establish formal S4 classes. When updating the value of a slot, one often uses the setSlots function.

setClass("A", representation = representation(slot1 = "numeric"))
aclass <- new("A", slot1 = 1:10)
aclass

Now we use the setSlots function to update the values in the object.

aclass <- setSlots(aclass, slot1 = 11:20)
aclass

Note that setSlots provides the same functionality as BiocGenerics:::replaceSlots but is more consistent with Bioconductor the setter and getter language.

show method

The selectSome function allows the developer to display a limited amount of information from a developed class. Note that the use of the @ here is due to the minimal implementation in the examples provided. The developer should always provide an interface to access the internal components of the class via an 'accessor' function.

setMethod("show", signature = "A", function(object) {
    s1info <- getElement(object, "slot1")
    cat("A sequence:", selectSome(s1info))
})
aclass

Contributing

BiocBaseUtils is a work in progress and we welcome contributions. There are quite a few often-used utility functions that are yet to be included in the package. We would like to keep the dependencies in this package minimal; therefore, contributions should mostly use base R.

Session Info

sessionInfo()

Please report minimally reproducible bugs at our github issue page.



Bioconductor/BiocUtils documentation built on Oct. 31, 2024, 1:35 a.m.