R Under development (unstable) (2025-09-01 r88761 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(albatross) > library(tools) # assert* > > # array constructor > z <- feemcube(array(1:(11*13*3), c(11, 13, 3)), 1:11, 20 + 1:13, 2:4, names = letters[1:3]) > > # when not dropping dimensions, should return a cube > stopifnot(inherits(z[1:10, 1:10, 1:2], 'feemcube')) > # when dropping the sample dimension, should return a feem with correct scale > stopifnot( + inherits(z[1:10, c(TRUE, FALSE), 1], 'feem'), + attr(z[1:10, c(TRUE, FALSE), 1], 'scale') == 2 + ) > > # assign from FEEM matching wavelengths and scale > z[3 + 1:3, 5 + 1:5, 1] <- feem(matrix(15:1, 3), 3 + 1:3, 20 + 5 + 1:5, 2) > > # disallow assignment from non-matching wavelengths > assertError(z[,,2] <- feem(matrix(1:(11*13), 11), 1:11, 1:13, 3)) > assertError(z[,,] <- structure(z, emission = attr(z, 'emission') + 10)) > # no wavelength check with 1- or 0- argument form of [<- > z[,,2][] <- feem(matrix(1:(11*13), 11), 1:11, 1:13, 3) > > # warn about assignment from non-matching scales > assertWarning(z[,,] <- structure(z, scales = c(1e-2, 1, 1e+3)), verbose = TRUE) Asserted warning: Assigning from FEEM[s] with different scales: LHS RHS 1 2 0.01 2 3 1 3 4 1000 > assertWarning( + z[3 + 1:3, 5 + 1:5, 1] <- feem(matrix(15:1, 3), 3 + 1:3, 20 + 5 + 1:5, 1), + verbose = TRUE + ) Asserted warning: Assigning from FEEM[s] with different scales: LHS RHS 1 2 1 > > stopifnot( + c('emission', 'excitation', 'intensity', 'sample') %in% + colnames(as.data.frame(z[,1, 1, drop = F])) + ) > > z <- feemscale(z, na.rm = TRUE) > stopifnot(all.equal(z, feemcube(as.list(z), TRUE))) > > # "sample" column should be factor or character, but not integer > for (cube in list(z, feemcube(unname(as.list(z)), FALSE))) + with(as.data.frame(cube), + stopifnot(is.factor(sample) || is.character(sample)) + ) > > # sub-assignment with unset indices must work > z[] <- z > z[,,] <- z > > # must correctly index by dimnames > stopifnot(all.equal( + z, + z[dimnames(z)[[1]], dimnames(z)[[2]], dimnames(z)[[3]]] + )) > zz <- z > zz[dimnames(z)[[1]], dimnames(z)[[2]], dimnames(z)[[3]]] <- z[] > stopifnot(all.equal(z, zz)) > > # emission, excitation, scales must be numeric vectors > # names must be atomic vector > # x must be numeric 3-way array > # sizes must match > assertError( + feemcube(array(1:(11*13*3), c(11, 13, 3)), matrix(1:11, 1), 20 + 1:13), + verbose = TRUE + ) Asserted error: is.vector(emission, "numeric") is not TRUE > assertError( + feemcube(array(1:(11*13*3), c(11, 13, 3)), 1:11, matrix(20 + 1:13)), + verbose = TRUE + ) Asserted error: is.vector(excitation, "numeric") is not TRUE > assertError( + feemcube(array(1:(11*13*3), c(11, 13, 3)), as.list(1:11), 20 + 1:13), + verbose = TRUE + ) Asserted error: is.vector(emission, "numeric") is not TRUE > assertError( + feemcube(array(1:(11*13*3), c(11, 13, 3)), 1:11, letters[1:13]), + verbose = TRUE + ) Asserted error: is.vector(excitation, "numeric") is not TRUE > assertError( + feemcube(array(1:(11*13*3), c(11, 13, 3)), 1:11, 1:13, matrix(2:4)), + verbose = TRUE + ) Asserted error: is.vector(scales, "numeric") is not TRUE > assertError( + feemcube(array(1:(11*13*3), c(11, 13, 3)), 1:11, 1:13, 2:4, as.list(letters[2:4])), + verbose = TRUE + ) Asserted error: is.null(names) || (dim(x)[3] == length(names) && is.vector(names) && .... is not TRUE > assertError( + feemcube(as.character(array(1:(11*13*3), c(11, 13, 3))), 1:11, 20 + 1:13), + verbose = TRUE + ) Asserted error: no applicable method for 'feemcube' applied to an object of class "character" > > proc.time() user system elapsed 0.29 0.10 0.37