Git Product home page Git Product logo

biocbaseutils's Introduction

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)
#> [1] TRUE
isTRUEorFALSE(FALSE)
#> [1] TRUE
isTRUEorFALSE(NA, na.ok = TRUE)
#> [1] TRUE

Character

isScalarCharacter(LETTERS)
#> [1] FALSE
isScalarCharacter("L")
#> [1] TRUE
isCharacter(LETTERS)
#> [1] TRUE
isCharacter(NA_character_, na.ok = TRUE)
#> [1] TRUE
isZeroOneCharacter("")
#> [1] FALSE
isZeroOneCharacter("", zchar = TRUE)
#> [1] TRUE

Numeric

isScalarInteger(1L)
#> [1] TRUE
isScalarInteger(1)
#> [1] FALSE

isScalarNumber(1)
#> [1] TRUE
isScalarNumber(1:2)
#> [1] FALSE

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
#> An object of class "A"
#> Slot "slot1":
#>  [1]  1  2  3  4  5  6  7  8  9 10

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

aclass <- setSlots(aclass, slot1 = 11:20)
aclass
#> An object of class "A"
#> Slot "slot1":
#>  [1] 11 12 13 14 15 16 17 18 19 20

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
#> A sequence: 11 12 ... 19 20

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()
#> R version 4.2.1 (2022-06-23)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.4 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
#> 
#> locale:
#>  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
#>  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
#>  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
#> [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices datasets  utils     methods   base     
#> 
#> other attached packages:
#> [1] BiocBaseUtils_0.99.10
#> 
#> loaded via a namespace (and not attached):
#>  [1] compiler_4.2.1   magrittr_2.0.3   fastmap_1.1.0    htmltools_0.5.3 
#>  [5] tools_4.2.1      yaml_2.3.5       codetools_0.2-18 stringi_1.7.8   
#>  [9] rmarkdown_2.15   knitr_1.39       stringr_1.4.0    xfun_0.32       
#> [13] digest_0.6.29    rlang_1.0.4      renv_0.15.5      evaluate_0.16

Please report minimally reproducible bugs at our github issue page.

biocbaseutils's People

Contributors

jwokaty avatar link-ny avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

wyy-yiyang

biocbaseutils's Issues

functions to migrate from S4Vectors

Hi Hervé, @hpages
When you get a chance, can you note the functions you'd like me to move over from S4Vectors?
I am not sure how to generate a list other than with :

library(S4Vectors); cat(paste("- [ ] ", ls(envir = as.environment("package:S4Vectors"), all.names = TRUE), "\n"))
See list here
  • .__C__Annotated
  • .__C__atomic
  • .__C__character_OR_NULL
  • .__C__DataFrame
  • .__C__DataFrame_OR_NULL
  • .__C__DFrame
  • .__C__expression_OR_function
  • .__C__Factor
  • .__C__FilterMatrix
  • .__C__FilterRules
  • .__C__Hits
  • .__C__HitsList
  • .__C__integer_OR_LLint
  • .__C__integer_OR_raw
  • .__C__List
  • .__C__list_OR_List
  • .__C__LLint
  • .__C__NSBS
  • .__C__Pairs
  • .__C__RectangularData
  • .__C__Rle
  • .__C__SelfHits
  • .__C__SimpleList
  • .__C__SortedByQueryHits
  • .__C__SortedByQueryHitsList
  • .__C__SortedByQuerySelfHits
  • .__C__TransposedDataFrame
  • .__C__Vector
  • .__C__vector_OR_factor
  • .__C__vector_OR_Vector
  • .T!:base
  • .T!=:base
  • .T[:base
  • .T[[:base
  • .T[[<-:base
  • .T[<-:base
  • .T&:base
  • .T%in%:base
  • .T<:base
  • .T<=:base
  • .T==:base
  • .T>:base
  • .T>=:base
  • .T$:base
  • .T$<-:base
  • .__T__active:S4Vectors
  • .__T__active<-:S4Vectors
  • .__T__aggregate:stats
  • .__T__anyDuplicated:BiocGenerics
  • .__T__anyNA:base
  • .__T__append:BiocGenerics
  • .__T__as.character:base
  • .__T__as.complex:base
  • .__T__as.data.frame:BiocGenerics
  • .__T__as.env:S4Vectors
  • .__T__as.factor:base
  • .__T__as.integer:base
  • .__T__as.list:base
  • .__T__as.logical:base
  • .__T__as.matrix:base
  • .__T__as.numeric:base
  • .__T__as.raw:base
  • .__T__as.table:base
  • .__T__bindCOLS:S4Vectors
  • .__T__bindROWS:S4Vectors
  • .__T__by:base
  • .__T__c:base
  • .__T__cbind:BiocGenerics
  • .__T__classNameForDisplay:S4Vectors
  • .__T__coerce:methods
  • .__T__colnames:BiocGenerics
  • .__T__colnames<-:base
  • .__T__combineCols:S4Vectors
  • .__T__combineRows:S4Vectors
  • .__T__complete.cases:stats
  • .__T__cor:stats
  • .__T__countLnodeHits:S4Vectors
  • .__T__countMatches:S4Vectors
  • .__T__countRnodeHits:S4Vectors
  • .__T__cov:stats
  • .__T__decode:S4Vectors
  • .__T__dim:base
  • .__T__dimnames:base
  • .__T__dimnames<-:base
  • .__T__do.call:BiocGenerics
  • .__T__droplevels:base
  • .__T__duplicated:BiocGenerics
  • .__T__elementMetadata:S4Vectors
  • .__T__elementMetadata<-:S4Vectors
  • .__T__elementNROWS:S4Vectors
  • .__T__elementType:S4Vectors
  • .__T__end:stats
  • .__T__eval:BiocGenerics
  • .__T__evalSeparately:S4Vectors
  • .__T__expand:S4Vectors
  • .__T__expand.grid:S4Vectors
  • .__T__extractCOLS:S4Vectors
  • .__T__extractROWS:S4Vectors
  • .__T__FactorToClass:S4Vectors
  • .__T__Filter:BiocGenerics
  • .__T__filterRules:S4Vectors
  • .__T__findMatches:S4Vectors
  • .__T__findRun:S4Vectors
  • .__T__first:S4Vectors
  • .__T__first<-:S4Vectors
  • .__T__from:S4Vectors
  • .__T__getListElement:S4Vectors
  • .__T__grep:BiocGenerics
  • .__T__grepl:BiocGenerics
  • .__T__head:utils
  • .__T__horizontal_slot_names:S4Vectors
  • .__T__intersect:BiocGenerics
  • .__T__is.finite:base
  • .__T__is.na:base
  • .__T__is.unsorted:BiocGenerics
  • .__T__isConstant:S4Vectors
  • .__T__isEmpty:S4Vectors
  • .__T__isSorted:S4Vectors
  • .__T__isStrictlySorted:S4Vectors
  • .__T__lapply:BiocGenerics
  • .__T__length:base
  • .__T__lengths:base
  • .__T__levels:base
  • .__T__levels<-:base
  • .__T__makeNakedCharacterMatrixForDisplay:S4Vectors
  • .__T__match:BiocGenerics
  • .__T__max:base
  • .__T__mcols:S4Vectors
  • .__T__mcols<-:S4Vectors
  • .__T__merge:base
  • .__T__mergeROWS:S4Vectors
  • .__T__metadata:S4Vectors
  • .__T__metadata<-:S4Vectors
  • .__T__mstack:S4Vectors
  • .__T__na.exclude:stats
  • .__T__na.omit:stats
  • .__T__names:base
  • .__T__names<-:base
  • .__T__nchar:base
  • .__T__ncol:base
  • .__T__nLnode:S4Vectors
  • .__T__nnode:S4Vectors
  • .__T__normalizeSingleBracketReplacementValue:S4Vectors
  • .__T__nRnode:S4Vectors
  • .__T__nrow:base
  • .__T__nrun:S4Vectors
  • .__T__NSBS:S4Vectors
  • .__T__Ops:base
  • .__T__order:BiocGenerics
  • .__T__parallel_slot_names:S4Vectors
  • .__T__parallelVectorNames:S4Vectors
  • .__T__params:S4Vectors
  • .__T__pcompare:S4Vectors
  • .__T__pcompareRecursively:S4Vectors
  • .__T__rank:BiocGenerics
  • .__T__rbind:BiocGenerics
  • .__T__Reduce:BiocGenerics
  • .__T__relistToClass:S4Vectors
  • .__T__rename:S4Vectors
  • .__T__rep:base
  • .__T__rep.int:base
  • .__T__replaceCOLS:S4Vectors
  • .__T__replaceROWS:S4Vectors
  • .__T__rev:base
  • .__T__revElements:S4Vectors
  • .__T__Rle:S4Vectors
  • .__T__rownames:BiocGenerics
  • .__T__ROWNAMES:S4Vectors
  • .__T__rownames<-:base
  • .__T__ROWNAMES<-:S4Vectors
  • .__T__runLength:S4Vectors
  • .__T__runLength<-:S4Vectors
  • .__T__runmean:S4Vectors
  • .__T__runq:S4Vectors
  • .__T__runsum:S4Vectors
  • .__T__runValue:S4Vectors
  • .__T__runValue<-:S4Vectors
  • .__T__runwtsum:S4Vectors
  • .__T__sameAsPreviousROW:S4Vectors
  • .__T__sapply:BiocGenerics
  • .__T__sd:BiocGenerics
  • .__T__second:S4Vectors
  • .__T__second<-:S4Vectors
  • .__T__selfmatch:S4Vectors
  • .__T__setdiff:BiocGenerics
  • .__T__setequal:base
  • .__T__setListElement:S4Vectors
  • .__T__shiftApply:S4Vectors
  • .__T__show:methods
  • .__T__showAsCell:S4Vectors
  • .__T__sort:BiocGenerics
  • .__T__space:S4Vectors
  • .__T__split:base
  • .__T__splitAsList:S4Vectors
  • .__T__stack:utils
  • .__T__start:stats
  • .__T__subset:base
  • .__T__subsetByFilter:S4Vectors
  • .__T__substr:base
  • .__T__substring:base
  • .__T__summary:base
  • .__T__Summary:base
  • .__T__t:base
  • .__T__tail:utils
  • .__T__to:S4Vectors
  • .__T__transform:base
  • .__T__unfactor:S4Vectors
  • .__T__union:BiocGenerics
  • .__T__unique:BiocGenerics
  • .__T__unlist:base
  • .__T__unname:S4Vectors
  • .__T__unstrsplit:S4Vectors
  • .__T__updateObject:BiocGenerics
  • .__T__values:S4Vectors
  • .__T__values<-:S4Vectors
  • .__T__var:BiocGenerics
  • .__T__vertical_slot_names:S4Vectors
  • .__T__width:BiocGenerics
  • .__T__window:stats
  • .__T__with:base
  • .__T__within:base
  • .__T__xtabs:BiocGenerics
  • .__T__xtfrm:base
  • .__T__zipdown:S4Vectors
  • .__T__zipup:S4Vectors
  • .Call2
  • .Depends
  • %in%
  • active
  • active<-
  • aggregate
  • aggregate.Vector
  • anyDuplicated
  • anyDuplicated.NSBS
  • anyDuplicated.Rle
  • anyDuplicated.Vector
  • append
  • as.character.LLint
  • as.data.frame
  • as.data.frame.Hits
  • as.data.frame.Vector
  • as.env
  • as.factor
  • as.integer.LLint
  • as.list
  • as.list.Vector
  • as.LLint
  • as.logical.LLint
  • as.matrix
  • as.matrix.Vector
  • as.numeric.LLint
  • as.table
  • as.vector.Rle
  • bindCOLS
  • bindROWS
  • breakTies
  • by
  • cbind
  • cbind_mcols_for_display
  • cbind.DataFrame
  • cbind.List
  • cbind.RectangularData
  • classNameForDisplay
  • coerce
  • colnames
  • colnames<-
  • combineCols
  • combineRows
  • combineUniqueCols
  • complete.cases
  • coolcat
  • cor
  • countLnodeHits
  • countMatches
  • countQueryHits
  • countRnodeHits
  • countSubjectHits
  • cov
  • DataFrame
  • decode
  • diff.Rle
  • do.call
  • droplevels
  • droplevels.Factor
  • droplevels.List
  • droplevels.Rle
  • duplicated
  • duplicated.DataFrame
  • duplicated.Vector
  • duplicatedIntegerPairs
  • duplicatedIntegerQuads
  • elementMetadata
  • elementMetadata<-
  • elementNROWS
  • elementType
  • end
  • endoapply
  • eval
  • evalSeparately
  • expand
  • expand.grid
  • extractCOLS
  • extractROWS
  • Factor
  • FactorToClass
  • Filter
  • FilterMatrix
  • filterRules
  • FilterRules
  • findMatches
  • findRun
  • first
  • first<-
  • fold
  • from
  • get_showHeadLines
  • get_showTailLines
  • getListElement
  • grep
  • grepl
  • head
  • head.LLint
  • head.RectangularData
  • head.Vector
  • Hits
  • HitsList
  • horizontal_slot_names
  • I
  • intersect
  • intersect.Vector
  • is.LLint
  • is.unsorted
  • isConstant
  • isEmpty
  • isRedundantHit
  • isSelfHit
  • isSequence
  • isSingleInteger
  • isSingleNumber
  • isSingleNumberOrNA
  • isSingleString
  • isSingleStringOrNA
  • isSorted
  • isStrictlySorted
  • isTRUEorFALSE
  • lapply
  • levels
  • levels.Rle
  • List
  • LLint
  • make_zero_col_DFrame
  • makeClassinfoRowForCompactPrinting
  • makeNakedCharacterMatrixForDisplay
  • makePrettyMatrixForCompactPrinting
  • match
  • matchIntegerPairs
  • matchIntegerQuads
  • mcols
  • mcols<-
  • mean.Rle
  • median.Rle
  • mendoapply
  • merge
  • mergeROWS
  • metadata
  • metadata<-
  • mstack
  • NA_LLint_
  • na.exclude
  • na.omit
  • nchar
  • ncol
  • new2
  • nLnode
  • nnode
  • normalizeDoubleBracketSubscript
  • normalizeSingleBracketReplacementValue
  • normalizeSingleBracketSubscript
  • nRnode
  • nrow
  • nrun
  • NSBS
  • Ops
  • order
  • orderIntegerPairs
  • orderIntegerQuads
  • Pairs
  • parallel_slot_names
  • parallelVectorNames
  • params
  • pc
  • pcompare
  • pcompareRecursively
  • printAtomicVectorInAGrid
  • quantile.Rle
  • queryHits
  • queryLength
  • rank
  • rbind
  • rbind.RectangularData
  • recycleArg
  • recycleCharacterArg
  • recycleIntegerArg
  • recycleLogicalArg
  • recycleNumericArg
  • Reduce
  • relistToClass
  • remapHits
  • rename
  • rep.int
  • replaceCOLS
  • replaceROWS
  • rev
  • rev.Rle
  • rev.Vector
  • revElements
  • Rle
  • rownames
  • ROWNAMES
  • rownames<-
  • ROWNAMES<-
  • runLength
  • runLength<-
  • runmean
  • runq
  • runsum
  • runValue
  • runValue<-
  • runwtsum
  • safeExplode
  • sameAsPreviousROW
  • sapply
  • sd
  • second
  • second<-
  • selectHits
  • SelfHits
  • selfmatch
  • selfmatchIntegerPairs
  • selfmatchIntegerQuads
  • setdiff
  • setdiff.Vector
  • setequal
  • setequal.Vector
  • setListElement
  • setMethods
  • setValidity2
  • shiftApply
  • show
  • showAsCell
  • SimpleList
  • sort
  • sort.DataFrame
  • sort.List
  • sort.Rle
  • sort.Vector
  • space
  • split
  • splitAsList
  • stack
  • start
  • subjectHits
  • subjectLength
  • subset
  • subset.Vector
  • subsetByFilter
  • substr
  • substring
  • summary
  • Summary
  • summary.Hits
  • summary.Rle
  • summary.Vector
  • svn.time
  • t
  • t.DataFrame
  • t.Hits
  • t.HitsList
  • t.TransposedDataFrame
  • tail
  • tail.LLint
  • tail.RectangularData
  • tail.Vector
  • to
  • toListOfIntegerVectors
  • transform
  • transform.DataFrame
  • transform.Vector
  • unfactor
  • union
  • union.Vector
  • unique
  • unique.DataFrame
  • unique.Vector
  • unname
  • unstrsplit
  • updateObject
  • values
  • values<-
  • var
  • vertical_slot_names
  • width
  • window
  • window.LLint
  • window.Vector
  • with
  • within
  • wmsg
  • xtabs
  • zipdown
  • zipup

Package name

@LiNk-NY @mtmorgan Can we discuss the name of the package here and reach consensus before renaming the repo?

Initial BiocUtils was not bad. I only suggested that we add a middle word that tries to give a sense of the kind of utilities that are in the package, that is, nothing that the end-user will ever see or use directly, but low-level things that are used internally by other packages.

I suggested "Internal" for the middle word. Things like "Base" or "Core" are reasonable alternatives if you are worried that "Internal" could imply that the package is intended for the Bioc-core. Personally I think that only a few Bioc-core members might actually be biased into this, not the community in general, so to me this not an issue. I'm against using "Devel" as middle word as this suggests that the package (BiocDevelUtils) is some kind of Bioconductor version of devtools, or, more generally speaking, is some package used actively during the development of a package to automate some tasks, like packages roxygen2 or codetoolsBioC.

I don't like naming a package according to its target audience (BiocDeveloper). As a developer myself I'd rather see a name that gives me an idea of what the package contains. But that name doesn't tell me anything, except that the package might contain stuff that might be of interest to me as a developer. The name of CRAN package assert tells me what the package is about so is a good name. Thankfully they didn't decide to name it developer!

So my proposals are, in order of preference: (1) BiocInternalUtils, (2) BiocBaseUtils, (3) BiocCoreUtils. Any of those 3 would satisfy me.

Also open to other suggestions.

Thanks,
H.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.