Skip to content

Refactoring: move anonymous functions into hidden functions #238

Closed

Description

@cbeleites

There are still quite a lot of calls to setMethod() in hyperSpec that use anonymous functions, e.g.

setMethod("colSums", signature = signature(x = "hyperSpec"), function(x, na.rm = TRUE, ..., label.spc) {
  result <- colSums(x@data$spc, na.rm = na.rm, ...)
  if (is.matrix(result) && ncol(result) != nwl(x) && nrow(result) == nwl(x)) {
    result <- t(result)
  }

  decomposition(x, result, scores = FALSE, label.spc = label.spc)
})

Moving these anonymous functions into hidden functions, e.g.

.colSums <-  function(x, na.rm = TRUE, ..., label.spc) {
  result <- colSums(x@data$spc, na.rm = na.rm, ...)
  if (is.matrix(result) && ncol(result) != nwl(x) && nrow(result) == nwl(x)) {
    result <- t(result)
  }

  decomposition(x, result, scores = FALSE, label.spc = label.spc)
}

setMethod("colSums", signature = signature(x = "hyperSpec"), .colSums)

would make the code easier to debug and also to unit test (#230). Possibly also easier to read


Marked as low priority since this is not a change that a user would notice, so it is not necessary to do this before the 1.0 milestone

Activity

  1. GegznaV commented on Jul 29, 2020

    @GegznaV
    Collaborator

    I did this in #225 for some functions for which I created unit tests. The most relevant commits have the same structure of commit messages "Update the way unit tests are attached in some-file-name". @cbeleites, please, review the PR.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions