Skip to content

Add generic function version() #28

Open

Description

@hpages

Requested by the spatialdataR folks.

After quickly going around the Bioconductor ecosystem, I found that several packages define the version() function, either as a regular function, or as an S4 generic function with methods:

BiocManager:

  • regular function with no argument

DaparToolshed:

  • generic with 1 method
  • generic's arguments: version(object, ...)
  • note that the method does not use the ellipsis

GenomicSuperSignature:

  • generic with 1 method
  • generic's arguments: version(x)

NanoStringNCTools:

  • generic with 1 method
  • generic's arguments: version(object, ...)
  • note that the method does not use the ellipsis

RedeR:

  • generic with 1 method
  • generic's arguments: version(obj)

Rigraphlib:

  • regular function with 1 argument
  • arguments: version(expected = FALSE)

msa:

  • generic with 1 method
  • generic's arguments: version(object)

I propose to use version(object) for the version() generic that we add to BiocGenerics. Better not to have the ellipsis in the argument list if it's not used. Problem with having the ellipsis in the generic and then define methods that ignore the ellipsis is that extra arguments mistakenly passed thru these methods are silently ignored instead of triggering an error.

So we can always add the ellipsis later when it's actually needed. Note that it's easy to do and doesn't break the existing methods.

Finally, as @Artur-man pointed out, conflicts with BiocManager::version() will be avoided by using the BiocManager:: prefix. Same thing with Rigraphlib::version().

Activity

  1. hpages commented on Nov 10, 2026

    @hpages
    ContributorAuthor

    Taking back my little blurb about methods silently ignoring the extra arguments. With R 4.5 and R 4.6:

    setGeneric("version", function(object, ...) standardGeneric("version"))
    
    setClass("A", slots=c(stuff="ANY", version="character"))
    a <- new("A", version="1.3.99")
    
    setMethod("version", "A", function(object) object@version)
    
    version(a)
    # [1] "1.3.99"
    
    version(a, major=TRUE)
    # Error in .local(object, ...) : unused argument (major = TRUE)

    So everything is fine.

    That's because the .local() trick does the right thing i.e. .local() gets called with .local(object, ...):

    > selectMethod(version, "A")
    Method Definition:
    
    function (object, ...) 
    {
        .local <- function (object) 
        object@version
        .local(object, ...)
    }
    <bytecode: 0x5a20da14ae40>
    
    Signatures:
            object
    target  "A"   
    defined "A"   

    I've not checked this for a long time but I have some vague memory that things were different at some point. But maybe not.

    Anyways, adding version(object, ...) now...

  2. hpages commented on Nov 11, 2026

    @hpages
    ContributorAuthor

    Done in BiocGenerics 0.59.13. See commit 9263b0b

    Also submitted a PR for msa that removes their own version() generic and uses the new generic in BiocGenerics instead. See UBod/msa#45

    At some point we should also notify the maintainers of DaparToolshed, GenomicSuperSignature, NanoStringNCTools, and RedeR, to encourage them to do the same thing. @Artur-man Do you think you can help with this? Note that GenomicSuperSignature::version() and RedeR::version() use a different argument name so they will need to adapt the definition of their version() methods. Thanks!

  3. Artur-man commented on Nov 11, 2026

    @Artur-man

    ohhh, we gonna knock on doors again, will do @hpages!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions