Skip to content

Feature/288 initialize with wl only - #292

Merged
cbeleites merged 7 commits into
cbeleites:developfrom
GegznaV:feature/288-initialize-with-wl-only
Dec 23, 2020
Merged

cbeleites merged 7 commits into
cbeleites:developfrom
GegznaV:feature/288-initialize-with-wl-only

Conversation

@GegznaV

@GegznaV GegznaV commented Dec 21, 2020

Copy link
Copy Markdown
Collaborator

This PR enables the possibility to initialize hyperSpec object by providing only wavelengths. So the following syntax does not fail anymore:

new("hyperSpec", wavelength = 300:400)

image

Includes fix #291, closes #288.

@GegznaV GegznaV added the Type: enhancement 🎈 asking for a new feature. label Dec 21, 2020
@GegznaV

GegznaV commented Dec 21, 2020 •

Copy link
Copy Markdown
Collaborator Author

I also tried syntax that includes a data object:

if (is.null(spc) && !is.null(wavelength) &&
    is.numeric(wavelength) && is.vector(wavelength)) {
  
  n_rows <- nrow(data)
  if (is.null(n_rows)) n_rows <- 0
  spc <- matrix(NA_real_, ncol = length(wavelength), nrow = n_rows)
}

But this attempt broke several unit tests so I returned to my current suggestion.

Details

Additional unit tests that passed:

# 100 wavelengths + data
df <- data.frame(a = letters, b = LETTERS)
expect_silent(hy_obj_3 <- new("hyperSpec", wavelength = 1:100, data = df))
expect_equal(nwl(hy_obj_3), 100)
expect_equal(nrow(hy_obj_3), length(letters))
expect_equal(ncol(hy_obj_3), 3)
expect_equal(colnames(hy_obj_3), c("a", "b", "spc"))

@cbeleites
cbeleites merged commit e83e070 into cbeleites:develop Dec 23, 2020
@GegznaV
GegznaV deleted the feature/288-initialize-with-wl-only branch December 23, 2020 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: enhancement 🎈 asking for a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add possibility to create hyperSpec object without spectra

2 participants