R Under development (unstable) (2023-08-20 r84995 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 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(Rarity) > data(spid.occ) > > # Preparation of rarity weights > rarity.weights <- rWeights(spid.occ, extended = TRUE) Rarity cut-off points: occurMA 0.0357142857142857 / 2 occurWP 0.339285714285714 / 19 > > # Generation of an assemblage matrix > assemblages.matrix <- cbind(assemblage.1 = sample(c(0, 1), 50, replace = TRUE), + assemblage.2 = sample(c(0, 1), 50, replace = TRUE), + assemblage.3 = sample(c(0, 1), 50, replace = TRUE), + assemblage.4 = sample(c(0, 1), 50, replace = TRUE), + assemblage.5 = sample(c(0, 1), 50, replace = TRUE)) > # Random attribution of names to the sampled species > rownames(assemblages.matrix) <- sample(rownames(spid.occ), 50, replace = FALSE) > > > # Test 1: A vector - W vector > curW <- rarity.weights$W > names(curW) <- rownames(rarity.weights) > curA <- assemblages.matrix[, 1] > > result <- Irr(W = curW, assemblages = curA) > result Irr Richness 0.09164 25.00000 > tot.res <- result[1] > if(any(is.na(result)) | any(result[grep("Irr", names(result))] < 0)) + { + stop("Error in the test") + } > # Testing NAs > curW[2] <- NA > result <- Irr(W = curW, assemblages = curA) W contains NA values, they will be removed > result Irr Richness 0.09164 25.00000 > if(any(is.na(result)) | any(result[grep("Irr", names(result))] < 0)) + { + stop("Error in the test") + } > > > # Test 2: A vector - W matrix > curW <- as.matrix(rarity.weights) > curA <- assemblages.matrix[, 1] > > result <- Irr(W = curW, assemblages = curA) > result Irr_W1 Irr_W2 Irr_W Richness 0.12612 0.05712 0.09164 25.00000 > if(any(is.na(result)) | any(result[grep("Irr", names(result))] < 0)) + { + stop("Error in the test") + } > tot.res <- c(tot.res, + result["Irr_W"]) > > # Testing NAs > curW[1, 2] <- NA > curW[10, 2] <- NA > curW[5, 3] <- NA > result <- Irr(W = curW, assemblages = curA) W contains NA values, they will be removed > result Irr_W1 Irr_W2 Irr_W Richness 0.12612 0.05712 0.09164 25.00000 > if(any(is.na(result)) | any(result[grep("Irr", names(result))] < 0)) + { + stop("Error in the test") + } > > > # Test 3: A matrix - W vector > curW <- rarity.weights$W > names(curW) <- rownames(rarity.weights) > curA <- assemblages.matrix > > result <- Irr(W = curW, assemblages = curA) > result Irr Richness assemblage.1 0.09164000 25 assemblage.2 0.04967500 20 assemblage.3 0.07303846 26 assemblage.4 0.13650000 26 assemblage.5 0.11530556 18 > tot.res <- c(tot.res, + result[1, 1]) > if(any(is.na(result)) | any(result[grep("Irr", names(result))] < 0)) + { + stop("Error in the test") + } > > # Testing NAs > curW[2] <- NA > result <- Irr(W = curW, assemblages = curA) W contains NA values, they will be removed > result Irr Richness assemblage.1 0.09164000 25 assemblage.2 0.04967500 20 assemblage.3 0.07303846 26 assemblage.4 0.13650000 26 assemblage.5 0.11530556 18 > if(any(is.na(result)) | any(result[grep("Irr", names(result))] < 0)) + { + stop("Error in the test") + } > > # Test 4: A matrix - W matrix > curW <- rarity.weights > curA <- assemblages.matrix > > result <- Irr(W = curW, assemblages = curA) > result Irr_W1 Irr_W2 Irr_W Richness assemblage.1 0.12612000 0.05712000 0.09164000 25 assemblage.2 0.05510000 0.04420000 0.04967500 20 assemblage.3 0.08476923 0.06123077 0.07303846 26 assemblage.4 0.16169231 0.11119231 0.13650000 26 assemblage.5 0.17516667 0.05538889 0.11530556 18 > tot.res <- c(tot.res, + result[1, 3]) > if(any(is.na(result)) | any(result[grep("Irr", names(result))] < 0)) + { + stop("Error in the test") + } > > # Testing NAs > curW[1, 2] <- NA > curW[10, 2] <- NA > curW[5, 3] <- NA > result <- Irr(W = curW, assemblages = curA) W contains NA values, they will be removed > result Irr_W1 Irr_W2 Irr_W Richness assemblage.1 0.12612000 0.05712000 0.09164000 25 assemblage.2 0.05510000 0.04420000 0.04967500 20 assemblage.3 0.08476923 0.06123077 0.07303846 26 assemblage.4 0.16169231 0.11119231 0.13650000 26 assemblage.5 0.17516667 0.05538889 0.11530556 18 > if(any(is.na(result)) | any(result[grep("Irr", names(result))] < 0)) + { + stop("Error in the test") + } > > > if(any(diff(tot.res)) > 0) + { + stop("Different values found for the same indices") + } Warning message: In any(diff(tot.res)) : coercing argument of type 'double' to logical > > proc.time() user system elapsed 0.32 0.07 0.39