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* > > sortfeem <- function(x) + x[order(attr(x, 'emission')), order(attr(x, 'excitation'))] > > # round-trip a matrix via data.frame > (z <- feem(matrix(1:40, ncol = 8), 66 + 1:5, 99 + 1:8)) excitation emission 100 101 102 103 104 105 106 107 67 1 6 11 16 21 26 31 36 68 2 7 12 17 22 27 32 37 69 3 8 13 18 23 28 33 38 70 4 9 14 19 24 29 34 39 71 5 10 15 20 25 30 35 40 attr(,"emission") [1] 67 68 69 70 71 attr(,"excitation") [1] 100 101 102 103 104 105 106 107 attr(,"scale") [1] 1 attr(,"class") [1] "feem" > stopifnot( + all.equal( + sortfeem(z), + sortfeem(feem(as.data.frame(feem(as.data.frame(z))))) + ) + ) > > # extraction operator must return FEEM objects unless dropping dimensions > stopifnot(inherits(z[2:4, 3:7], 'feem')) > > # replacement operator must verify wavelengths when assigning from FEEM object > assertError( + z[1:2, 3:4] <- feem(matrix(1:4, 2), 1:2, 1:2) + ) > # but the check is disabled if we use 1- or 0- argument form of [<- > z[1:2,3:4][] <- feem(matrix(1:4, 2), 1:2, 1:2) > > # replacement operator must warn about scale differences > assertWarning( + z[2:3, 4:5] <- feem(matrix(1:4, 2), 66 + 2:3, 99 + 4:5, 2), + verbose = TRUE + ) Asserted warning: Assigning from FEEM with different scale: LHS(1) != RHS(2) > > # sub-assignment with unset subscripts must work > z[] <- z > z[,] <- z > > # must keep wavelengths when subscripting with dimnames > stopifnot(all.equal( + z, + z[dimnames(z)[[1]], dimnames(z)[[2]]] + )) > zz <- z > zz[dimnames(z)[[1]], dimnames(z)[[2]]] <- z[] > stopifnot(all.equal(z, zz)) > > sortdf <- function(x) x[do.call(order, x),] > > # round-trip a sparse data.frame via feem > (z <- data.frame(emission = 1:10, excitation = 21:30, intensity = 31:40)) emission excitation intensity 1 1 21 31 2 2 22 32 3 3 23 33 4 4 24 34 5 5 25 35 6 6 26 36 7 7 27 37 8 8 28 38 9 9 29 39 10 10 30 40 > stopifnot( + all.equal( + sortdf(z), + sortdf(as.data.frame(feem(as.data.frame(feem(z))))) + ) + ) > > # must not allow matrices of correct length: > # other code assumes that emission and excitation doesn't have dimensions > assertError(feem(matrix(1:4, 2), matrix(1:2), 1:2), verbose = TRUE) Asserted error: is.vector(emission, "numeric") is not TRUE > assertError(feem(matrix(1:4, 2), 1:2, matrix(1:2, 1)), verbose = TRUE) Asserted error: is.vector(excitation, "numeric") is not TRUE > assertError(feem(matrix(1:4, 2), letters[1:2], matrix(1:2)), verbose = TRUE) Asserted error: is.vector(emission, "numeric") is not TRUE > # non-scalar/non-numeric scale > assertError(feem(matrix(1:4, 2), 1:2, 1:2, 1:2), verbose = TRUE) Asserted error: length(scale) == 1 is not TRUE > assertError(feem(matrix(1:4, 2), 1:2, 1:2, matrix(1)), verbose = TRUE) Asserted error: is.vector(scale, "numeric") is not TRUE > assertError(feem(matrix(1:4, 2), 1:2, 1:2, 'x'), verbose = TRUE) Asserted error: is.vector(scale, "numeric") is not TRUE > # non-numeric x > # NB: character x gets dispatched to feem.character and fails for a > # different reason > assertError(feem(as.complex(matrix(1:4, 2)), 1:2, 1:2), verbose = TRUE) Asserted error: no applicable method for 'feem' applied to an object of class "complex" > > proc.time() user system elapsed 0.35 0.14 0.48