diff --git a/NEWS.md b/NEWS.md index ce22ec5..b6b41ac 100644 --- a/NEWS.md +++ b/NEWS.md @@ -42,6 +42,7 @@ * Dataset `faux_cell` and function `generate_faux_cell()` replace `chondro` dataset (cbeleites/hyperSpec#125, cbeleites/hyperSpec#156, cbeleites/hyperSpec#180, cbeleites/hyperSpec#229). * Documentation aliases have been updated. Now, ?hyperSpec points to the function `hyperSpec()`, and to refer to the package, `package?hyperSpec` should be used (#129). * Vignette `hyperSpec.Rmd`: suggested packages (`pls`) are now loaded conditionally so the vignette builds even when they are not installed. +* Function `labels<-()` converted into an S4 generic, making it consistent with the existing `labels()` S4 generic (r-hyperspec/hyperSpec#115). ### Bugfixes diff --git a/R/labels.R b/R/labels.R index c9211b9..2c170a6 100644 --- a/R/labels.R +++ b/R/labels.R @@ -140,7 +140,8 @@ hySpc.testthat::test(.labels) <- function() { #' @examples #' #' labels(flu, "c") <- expression("/"("c", "mg / l")) -`labels<-` <- function(object, which = NULL, ..., value) { +# helper function (similar to .labels for the getter) +.labels_replace <- function(object, which = NULL, ..., value) { assert_hyperSpec(object) validObject(object) @@ -163,6 +164,17 @@ hySpc.testthat::test(.labels) <- function() { object } +# generic replacement function +#' @export +setGeneric("labels<-", function(object, which = NULL, ..., value) { + standardGeneric("labels<-") +}) + +setMethod("labels<-", + signature = signature(object = "hyperSpec"), + .labels_replace +) + # Unit tests -----------------------------------------------------------------