Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
### Bugfixes

* Possibility to initialize `hyperSpec` object by providing wavelengths only (cbeleites/hyperSpec#288).
* Possibility to initialize `hyperSpec` object providing only `data` without `spc` (cbeleites/hyperSpec#296).
* Column names in spectra matrix (`$spc` column of `hyperSpec` object) are now returned correctly by functions `spc.bin()` (cbeleites/hyperSpec#237), and `spc.loess()` (cbeleites/hyperSpec#245
* `all.equal()` method for `hyperSpec` objects converted from S4 to S3 registration. The S4 `setMethod()` approach for this S3 generic caused roxygen2 (>= 7.3) to crash during documentation generation.
* `rbind.fill()` (internal): strip the `AsIs` class from matrix columns after data frame assembly. R >= 4.4 introduced `all.equal.AsIs()` which caused spurious class-mismatch failures when comparing `hyperSpec` objects that had been through `rbind` or `collapse`.
Expand Down
12 changes: 11 additions & 1 deletion R/initialize.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
#' spc = spc
#' )
#'
#' # data only, no spectra
#' new("hyperSpec", data = data.frame(x = 1:5))
#'
#' colnames(spc) <- 600:603
#' new("hyperSpec", spc = spc) # wavelength taken from colnames (spc)
#'
Expand Down Expand Up @@ -203,7 +206,8 @@ NULL

# Deal with spectra
if (is.null(spc) && is.null(data$spc)) {
spc <- structure(numeric(0), .Dim = c(0L, 0L))
nrows <- if (!is.null(data)) nrow(data) else 0L
spc <- structure(numeric(0), .Dim = c(nrows, 0L))
}

if (!is.null(spc) && !is.matrix(spc)) {
Expand Down Expand Up @@ -397,6 +401,12 @@ hySpc.testthat::test(.initialize) <- function() {
expect_equal(hy_obj_1c, hy_obj_2c)
})

test_that("data only, no spc", {
h <- new("hyperSpec", data = data.frame(c = 1:5))
expect_equal(dim(h), c(nrow = 5L, ncol = 2L, nwl = 0L))
expect_equal(h@wavelength, numeric(0))
expect_equal(h$c, 1:5)
})

test_that('hyperSpec() and new("hyperSpec") give identical results', {
expect_equal(hyperSpec(), new("hyperSpec"))
Expand Down