Skip to content

Commit

Permalink
Fix set_energy<- so that argument value appears at the end of the arg…
Browse files Browse the repository at this point in the history
…ument list
  • Loading branch information
nfrerebeau committed Jun 23, 2023
1 parent c852bfa commit e441bc2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# gamma 1.0.3.9000
## Bugfixes & changes
* Fix the metadata when reading a CNF file: do not use a fixed index to isolate particular metadata (the number of metadata may vary depending on the user's acquisition).
* Fix `set_energy<-` so that argument `value` appears in the method at the end of the argument list.

# gamma 1.0.3
## Bugfixes & changes
Expand Down
5 changes: 3 additions & 2 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ NULL
#' Getters and setters to extract or replace parts of an object.
#' @param x An object from which to get or set element(s).
#' @param value A possible value for the element(s) of `x`.
#' @param expected TODO.
#' @param expected A [`logical`] scalar: should the expected values be returned
#' instead of observed values?
#' @param na.rm A [`logical`] scalar: should [`NA`] be omitted?
#' @param ... Currently not used.
#' @return
Expand Down Expand Up @@ -106,7 +107,7 @@ setGeneric(
#' @aliases set_energy-method
setGeneric(
name = "set_energy<-",
def = function(x, ..., value) standardGeneric("set_energy<-")
def = function(x, value) standardGeneric("set_energy<-")
)

#' @rdname mutator
Expand Down
13 changes: 4 additions & 9 deletions R/mutators.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ setMethod(
signature = "GammaSpectra",
definition = function(x, na.rm = FALSE) {
channels <- vapply(x, FUN = range_channels, FUN.VALUE = numeric(2),
na.rm = na.rm)
na.rm = na.rm)
channels <- t(channels)
colnames(channels) <- c("min", "max")
channels
Expand Down Expand Up @@ -358,17 +358,12 @@ setMethod(
setMethod(
f = "set_energy<-",
signature = c(x = "PeakPosition", value = "numeric"),
definition = function(x, value, expected = TRUE) {
definition = function(x, value) {
# Keep only complete cases
k <- if (anyNA(value)) which(!is.na(value)) else seq_along(value)

if (expected) {
x@energy_expected <- value[k]
x@energy_observed <- x@energy_observed[k]
} else {
x@energy_observed <- value[k]
x@energy_expected <- x@energy_expected[k]
}
x@energy_observed <- x@energy_observed[k]
x@energy_expected <- value[k]
x@channel <- x@channel[k]
methods::validObject(x)
x
Expand Down
7 changes: 4 additions & 3 deletions man/mutator.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e441bc2

Please sign in to comment.