From 569161404bcb1bb6e016c251a8b6c7bb92fca1d5 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 1 Jun 2020 12:12:32 -0500 Subject: [PATCH 01/55] Add update.dataset.R --- hyperSpec/DESCRIPTION | 13 +- hyperSpec/R/update.dataset.R | 231 +++++++++++++++++++++++++++++++++++ 2 files changed, 238 insertions(+), 6 deletions(-) create mode 100644 hyperSpec/R/update.dataset.R diff --git a/hyperSpec/DESCRIPTION b/hyperSpec/DESCRIPTION index 06ed75be2..959aa31c8 100644 --- a/hyperSpec/DESCRIPTION +++ b/hyperSpec/DESCRIPTION @@ -4,7 +4,7 @@ Type: Package Title: Work with Hyperspectral Data, i.e. Spectra + Meta Information (Spatial, Time, Concentration, ...) Version: 0.99-20200522 -Date: 2020-05-22 +Date: 2020-05-28 Maintainer: Claudia Beleites Authors@R: c( person("Claudia", "Beleites", role = c("aut","cre", "dtc"), email = "Claudia.Beleites@chemometrix.gmbh"), @@ -99,18 +99,18 @@ Collate: 'wl2i.R' 'extract.R' 'factor2num.R' + 'options.R' + 'regexps.R' + 'guesswavelength.R' + 'initialize.R' 'fauxCell.R' 'fileio.optional.R' 'fix_spc_colnames.R' 'flu.R' 'getbynames.R' - 'options.R' - 'regexps.R' - 'guesswavelength.R' 'paracetamol.R' 'laser.R' 'hyperspec-package.R' - 'initialize.R' 'labels.R' 'plotmap.R' 'levelplot.R' @@ -173,6 +173,7 @@ Collate: 'sweep.R' 'trellis.factor.key.R' 'units.R' + 'update.examples.R' 'vandermonde.R' 'wc.R' 'wl.R' @@ -181,4 +182,4 @@ Collate: 'write.txt.wide.R' 'y-pastenames.R' 'zzz.R' -RoxygenNote: 7.0.2 +RoxygenNote: 7.1.0 diff --git a/hyperSpec/R/update.dataset.R b/hyperSpec/R/update.dataset.R new file mode 100644 index 000000000..d5d930cb0 --- /dev/null +++ b/hyperSpec/R/update.dataset.R @@ -0,0 +1,231 @@ +##' Update data sets for hyperSpec package +##' +##' +##' @return directory of edited R files and associated test logs +##' +##' @author Erick Oduniyi +##' +##' @keywords programming utilities +##' @examples +##' @export +# TODO: consider deleting .txt files every time this function is ran +# TODO: add option to switch between verbose console output +# TODO: Check if the file even has examples +# path_to_files <- "/Users/erickoduniyi/Desktop/hyperSpec/hyperSpec/hyperSpec/hyperSpec/R" +# path_to_store <- "~/Desktop/R-edits/" +update.examples <- function(old_ds, new_ds, path_to_files, path_to_store) { + + # Check the difference between the two datasets + old_ds_name <- deparse(substitute(old_ds)) + new_ds_name <- deparse(substitute(new_ds)) + ds_info <- check_ds(old_ds, new_ds, old_ds_name, new_ds_name) + + # Create directories where the files need to be saved + file_info <- create_edits_dir(path_to_files, path_to_store, old_ds_name) + + # Edit .R files + message("Would you like to edit .R files now?") + choice <- select.list(c("Yes", "No")) + if (choice == "Yes") { + make_edits_R(ds_info, file_info) + } + + # Check test for updated file + message("Would you like to check test now?") + choice <- select.list(c("Yes", "No")) + if (choice == "Yes") { + check_test_in_file(file_info) + } + + # Check updated file examples + message("Would you like to check examples now?") + choice <- select.list(c("Yes", "No")) + if (choice == "Yes") { + check_examples(file_info) + } + + # Check updated file vignettes + message("Would you like to check vignettes now?") + choice <- select.list(c("Yes", "No")) + if (choice == "Yes") { + check_vingette(file_info) + } + + # Let the user know user.examples has completed + message("update.examples.R has completed!!!") +} +# Helper(s) ----------------------------------------------- + +check_ds <- function(old_ds, new_ds, old_ds_name, new_ds_name) { + + # Check data sets + message(paste("Checking differences between", old_ds_name, "and", new_ds_name)) + + # Handle potential differences between datasets + if (!setequal(colnames(old_ds), colnames(new_ds))) { + col_diff_old <- setdiff(colnames(old_ds), colnames(new_ds)) + col_diff_new <- setdiff(colnames(new_ds), colnames(old_ds)) + ls_old_names <- paste(sort(col_diff_old), collapse = ", ") + + # Let user know about the difference between datasets + message(paste(c("The following columns appear in", old_ds_name, "but not", paste0(new_ds_name, ":"), ls_old_names), collapse= " ")) + + # Give the user options about substituting columns between datasets + message(paste("Which column in", old_ds_name, "do you want to substitute?:")) + sub_old <- select.list(sort(col_diff_old)) + if (sub_old != "") { + message(paste("Substitute", sub_old, "for which column in", paste0(new_ds_name, "?:"))) + for_new <-select.list(sort(col_diff_new)) + } + } + + # Prepare information about data sets to be passed on to subsequent functions + ds_info <- list(ds_names = c(old_ds_name, new_ds_name), sub_vals = c(sub_old, for_new)) +} + +create_edits_dir <- function(path_to_files, path_to_store, old_ds_name) { + + # Set the location of the .R files that need to be updated: + setwd(path_to_files) + + # Create a directories where the files need to be saved + loc_2_be_saved <- path_to_store + dir.create(loc_2_be_saved, showWarnings = FALSE) + dir.create(paste0(loc_2_be_saved, "test-results"), showWarnings = FALSE) + dir.create(paste0(loc_2_be_saved, "example-results"), showWarnings = FALSE) + dir.create(paste0(loc_2_be_saved, "vignette-results"), showWarnings = FALSE) + + # Get all the .R files in the current directory + R_files <- list.files() + + # Get files + files2get <- vector() + + for (i in seq_along(R_files)) { + + # Read in the file + source_code <- readLines(R_files[i]) + + # Check if file references the old data set + if (identical(grep(old_ds_name, source_code, value = TRUE), character(0))) { + + # Skip this file + message(paste(R_files[i],"does not contain", old_ds_name, "data set...")) + + } else { + + # "Just throw it in the bag" - Fabolous ft. The-Dream + files2get <- c(files2get, R_files[i]) + } + } + + cat("-----------------------------------------------------------------------------------------","\n") + # Prepare information about files + # Collect subset of filenames + R_files <- files2get + file_info <- list(file_loc = loc_2_be_saved, R_files = R_files) +} + +make_edits_R <- function(ds_info, file_info) { + + # Setup + loc_2_be_saved <- file_info$file_loc + filenames <- file_info$R_files + old_ds_name <- ds_info$ds_names[1] + new_ds_name <- ds_info$ds_names[2] + sub_old <- ds_info$sub_vals[1] + for_new <- ds_info$sub_vals[2] + + # Edit + message("== Making edits =========================================================================") + + # Edit each file + for (i in seq_along(filenames)) { + + # Read in the file + cat(paste0("**Reading in file: ", filenames[i]), "\n") + source_code <- readLines(filenames[i]) + + # Prepare substitute pattern for specific case + old <- paste0(old_ds_name,"\\$", sub_old) + new <- paste0(new_ds_name,"$", for_new) + + # Specific case + cat(paste("Replacing occurences of", old, "with", new), "\n") + code_edited <- gsub(old, new, source_code) + + # Generic case + cat(paste("Replacing occurences of", old_ds_name, "with", new_ds_name), "\n") + code_edited <- gsub(old_ds_name, new_ds_name, code_edited) + + # Output updated file + cat(paste("Updating", filenames[i]), "\n") + writeLines(code_edited, paste0(loc_2_be_saved, filenames[i])) + + # Move to the next file + cat(paste0("**Done editing: ", filenames[i]), "\n") + } + + # Tell user + message("Done editing all files!!..") + cat("-----------------------------------------------------------------------------------------","\n") +} + +check_test_in_file <- function(file_info) { + + # Setup + loc_2_be_saved <- file_info$file_loc + filenames <- file_info$R_files + + # Check test + message("== Checking unittest ====================================================================") + + # Check test of each file + for (i in seq_along(filenames)) { + + # Run test in file and output the results to a text file + test_res_here <- paste0(loc_2_be_saved, "test-results/", gsub(".R", ".txt", filenames[i])) + verify_output(test_res_here, with_reporter(reporter = SummaryReporter$new(), start_end_reporter = TRUE, get.test(.aggregate)())) + cat(paste0("**Logging results to...", gsub(".R", ".txt", filenames[i])), "\n") + } + + # Tell user + message("Done checking all test!!..") + cat("-----------------------------------------------------------------------------------------","\n") +} + +check_examples <- function(file_info) { + + # Setup + filenames <- file_info$R_files + + # Check examples + message("== Checking examples ====================================================================") + + # Check examples in each file + for (i in seq_along(filenames)) { + + cat(paste0("**Logging results to...", gsub(".R", ".Rd", filename)), "\n") + + # Move to the next file + message(paste0("Done checking examples for: ", filenames[i])) + } + + # Tell user + message("Done checking all examples!...") + cat("-----------------------------------------------------------------------------------------","\n") +} + +check_vingette <- function(file_info) { + + # Setup + filenames <- file_info$R_files + + # Check vignette + message("== Checking vignettes ===================================================================") + cat(paste0("**Logging results to...", gsub(".R", ".txt", filename)), "\n") + + # Tell user + message("Done checking vignettes!!..") + cat("-----------------------------------------------------------------------------------------","\n") +} \ No newline at end of file From d79f548217219919e6726dfb187e7babd78145a0 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 1 Jun 2020 12:18:23 -0500 Subject: [PATCH 02/55] Update aggregate.R Replace chondro with fauxCell --- hyperSpec/R/aggregate.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hyperSpec/R/aggregate.R b/hyperSpec/R/aggregate.R index f449d51d5..3a61dbe60 100644 --- a/hyperSpec/R/aggregate.R +++ b/hyperSpec/R/aggregate.R @@ -110,7 +110,7 @@ ##' @import stats ##' @include hyperspec-class.R ##' @examples -##' cluster.means <- aggregate (chondro, chondro$clusters, mean_pm_sd) +##' cluster.means <- aggregate (fauxCell, fauxCell$region, mean_pm_sd) ##' plot(cluster.means, stacked = ".aggregate", fill = ".aggregate", ##' col = matlab.dark.palette (3)) ##' @@ -154,17 +154,17 @@ setMethod("aggregate", signature = signature(x = "hyperSpec"), .aggregate) .test(.aggregate) <- function() { context("aggregate") - test_that("chondro cluster means", { - cluster.means <- aggregate(chondro, chondro$clusters, mean_pm_sd) + test_that("fauxCell cluster means", { + cluster.means <- aggregate(fauxCell, fauxCell$region, mean_pm_sd) expect_true(all(is.na(cluster.means$y))) expect_true(all(is.na(cluster.means$x))) expect_equal(cluster.means$clusters, cluster.means$.aggregate) - for (cluster in levels(chondro$clusters)) { + for (cluster in levels(fauxCell$region)) { expect_equivalent( cluster.means [[cluster.means$clusters == cluster, ]], - apply(chondro [[chondro$clusters == cluster, ]], 2, mean_pm_sd) + apply(fauxCell [[fauxCell$region == cluster, ]], 2, mean_pm_sd) ) } }) From 620fce7c569175f2d05030274a2b47e439f39d70 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 13:46:58 -0500 Subject: [PATCH 03/55] Replace `chondro` with `fauxCell` in aggregate.R --- hyperSpec/DESCRIPTION | 4 ++-- hyperSpec/R/aggregate.R | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hyperSpec/DESCRIPTION b/hyperSpec/DESCRIPTION index 959aa31c8..c2ac9ff93 100644 --- a/hyperSpec/DESCRIPTION +++ b/hyperSpec/DESCRIPTION @@ -4,7 +4,7 @@ Type: Package Title: Work with Hyperspectral Data, i.e. Spectra + Meta Information (Spatial, Time, Concentration, ...) Version: 0.99-20200522 -Date: 2020-05-28 +Date: 2020-06-08 Maintainer: Claudia Beleites Authors@R: c( person("Claudia", "Beleites", role = c("aut","cre", "dtc"), email = "Claudia.Beleites@chemometrix.gmbh"), @@ -173,7 +173,7 @@ Collate: 'sweep.R' 'trellis.factor.key.R' 'units.R' - 'update.examples.R' + 'update.dataset.R' 'vandermonde.R' 'wc.R' 'wl.R' diff --git a/hyperSpec/R/aggregate.R b/hyperSpec/R/aggregate.R index 3a61dbe60..cfa5a9394 100644 --- a/hyperSpec/R/aggregate.R +++ b/hyperSpec/R/aggregate.R @@ -110,8 +110,8 @@ ##' @import stats ##' @include hyperspec-class.R ##' @examples -##' cluster.means <- aggregate (fauxCell, fauxCell$region, mean_pm_sd) -##' plot(cluster.means, stacked = ".aggregate", fill = ".aggregate", +##' region.means <- aggregate (fauxCell, fauxCell$region, mean_pm_sd) +##' plot(region.means, stacked = ".aggregate", fill = ".aggregate", ##' col = matlab.dark.palette (3)) ##' ##' ## make some "spectra" @@ -154,17 +154,17 @@ setMethod("aggregate", signature = signature(x = "hyperSpec"), .aggregate) .test(.aggregate) <- function() { context("aggregate") - test_that("fauxCell cluster means", { - cluster.means <- aggregate(fauxCell, fauxCell$region, mean_pm_sd) + test_that("fauxCell region means", { + region.means <- aggregate(fauxCell, fauxCell$region, mean_pm_sd) expect_true(all(is.na(cluster.means$y))) expect_true(all(is.na(cluster.means$x))) - expect_equal(cluster.means$clusters, cluster.means$.aggregate) + expect_equal(region.means$region, region.means$.aggregate) - for (cluster in levels(fauxCell$region)) { + for (region in levels(fauxCell$region)) { expect_equivalent( - cluster.means [[cluster.means$clusters == cluster, ]], - apply(fauxCell [[fauxCell$region == cluster, ]], 2, mean_pm_sd) + region.means [[cluster.means$region == region, ]], + apply(fauxCell [[fauxCell$region == region, ]], 2, mean_pm_sd) ) } }) From 4143504773baf36c6c32d16981ce5f34ee8e55c0 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 14:20:10 -0500 Subject: [PATCH 04/55] Revert "Replace `chondro` with `fauxCell` in aggregate.R" This reverts commit 620fce7c569175f2d05030274a2b47e439f39d70. --- hyperSpec/DESCRIPTION | 4 ++-- hyperSpec/R/aggregate.R | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hyperSpec/DESCRIPTION b/hyperSpec/DESCRIPTION index c2ac9ff93..959aa31c8 100644 --- a/hyperSpec/DESCRIPTION +++ b/hyperSpec/DESCRIPTION @@ -4,7 +4,7 @@ Type: Package Title: Work with Hyperspectral Data, i.e. Spectra + Meta Information (Spatial, Time, Concentration, ...) Version: 0.99-20200522 -Date: 2020-06-08 +Date: 2020-05-28 Maintainer: Claudia Beleites Authors@R: c( person("Claudia", "Beleites", role = c("aut","cre", "dtc"), email = "Claudia.Beleites@chemometrix.gmbh"), @@ -173,7 +173,7 @@ Collate: 'sweep.R' 'trellis.factor.key.R' 'units.R' - 'update.dataset.R' + 'update.examples.R' 'vandermonde.R' 'wc.R' 'wl.R' diff --git a/hyperSpec/R/aggregate.R b/hyperSpec/R/aggregate.R index cfa5a9394..3a61dbe60 100644 --- a/hyperSpec/R/aggregate.R +++ b/hyperSpec/R/aggregate.R @@ -110,8 +110,8 @@ ##' @import stats ##' @include hyperspec-class.R ##' @examples -##' region.means <- aggregate (fauxCell, fauxCell$region, mean_pm_sd) -##' plot(region.means, stacked = ".aggregate", fill = ".aggregate", +##' cluster.means <- aggregate (fauxCell, fauxCell$region, mean_pm_sd) +##' plot(cluster.means, stacked = ".aggregate", fill = ".aggregate", ##' col = matlab.dark.palette (3)) ##' ##' ## make some "spectra" @@ -154,17 +154,17 @@ setMethod("aggregate", signature = signature(x = "hyperSpec"), .aggregate) .test(.aggregate) <- function() { context("aggregate") - test_that("fauxCell region means", { - region.means <- aggregate(fauxCell, fauxCell$region, mean_pm_sd) + test_that("fauxCell cluster means", { + cluster.means <- aggregate(fauxCell, fauxCell$region, mean_pm_sd) expect_true(all(is.na(cluster.means$y))) expect_true(all(is.na(cluster.means$x))) - expect_equal(region.means$region, region.means$.aggregate) + expect_equal(cluster.means$clusters, cluster.means$.aggregate) - for (region in levels(fauxCell$region)) { + for (cluster in levels(fauxCell$region)) { expect_equivalent( - region.means [[cluster.means$region == region, ]], - apply(fauxCell [[fauxCell$region == region, ]], 2, mean_pm_sd) + cluster.means [[cluster.means$clusters == cluster, ]], + apply(fauxCell [[fauxCell$region == cluster, ]], 2, mean_pm_sd) ) } }) From 2a2ca32dce9c689131d1cfba12ec9f6fa901d39a Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 14:20:41 -0500 Subject: [PATCH 05/55] Revert "Revert "Replace `chondro` with `fauxCell` in aggregate.R"" This reverts commit 4143504773baf36c6c32d16981ce5f34ee8e55c0. --- hyperSpec/DESCRIPTION | 4 ++-- hyperSpec/R/aggregate.R | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hyperSpec/DESCRIPTION b/hyperSpec/DESCRIPTION index 959aa31c8..c2ac9ff93 100644 --- a/hyperSpec/DESCRIPTION +++ b/hyperSpec/DESCRIPTION @@ -4,7 +4,7 @@ Type: Package Title: Work with Hyperspectral Data, i.e. Spectra + Meta Information (Spatial, Time, Concentration, ...) Version: 0.99-20200522 -Date: 2020-05-28 +Date: 2020-06-08 Maintainer: Claudia Beleites Authors@R: c( person("Claudia", "Beleites", role = c("aut","cre", "dtc"), email = "Claudia.Beleites@chemometrix.gmbh"), @@ -173,7 +173,7 @@ Collate: 'sweep.R' 'trellis.factor.key.R' 'units.R' - 'update.examples.R' + 'update.dataset.R' 'vandermonde.R' 'wc.R' 'wl.R' diff --git a/hyperSpec/R/aggregate.R b/hyperSpec/R/aggregate.R index 3a61dbe60..cfa5a9394 100644 --- a/hyperSpec/R/aggregate.R +++ b/hyperSpec/R/aggregate.R @@ -110,8 +110,8 @@ ##' @import stats ##' @include hyperspec-class.R ##' @examples -##' cluster.means <- aggregate (fauxCell, fauxCell$region, mean_pm_sd) -##' plot(cluster.means, stacked = ".aggregate", fill = ".aggregate", +##' region.means <- aggregate (fauxCell, fauxCell$region, mean_pm_sd) +##' plot(region.means, stacked = ".aggregate", fill = ".aggregate", ##' col = matlab.dark.palette (3)) ##' ##' ## make some "spectra" @@ -154,17 +154,17 @@ setMethod("aggregate", signature = signature(x = "hyperSpec"), .aggregate) .test(.aggregate) <- function() { context("aggregate") - test_that("fauxCell cluster means", { - cluster.means <- aggregate(fauxCell, fauxCell$region, mean_pm_sd) + test_that("fauxCell region means", { + region.means <- aggregate(fauxCell, fauxCell$region, mean_pm_sd) expect_true(all(is.na(cluster.means$y))) expect_true(all(is.na(cluster.means$x))) - expect_equal(cluster.means$clusters, cluster.means$.aggregate) + expect_equal(region.means$region, region.means$.aggregate) - for (cluster in levels(fauxCell$region)) { + for (region in levels(fauxCell$region)) { expect_equivalent( - cluster.means [[cluster.means$clusters == cluster, ]], - apply(fauxCell [[fauxCell$region == cluster, ]], 2, mean_pm_sd) + region.means [[cluster.means$region == region, ]], + apply(fauxCell [[fauxCell$region == region, ]], 2, mean_pm_sd) ) } }) From 639c5402d748bfa5a362a7f1c6d5e43c2ace3fae Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 14:33:03 -0500 Subject: [PATCH 06/55] Update aggregate.R --- hyperSpec/R/aggregate.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperSpec/R/aggregate.R b/hyperSpec/R/aggregate.R index cfa5a9394..b145149bd 100644 --- a/hyperSpec/R/aggregate.R +++ b/hyperSpec/R/aggregate.R @@ -163,7 +163,7 @@ setMethod("aggregate", signature = signature(x = "hyperSpec"), .aggregate) for (region in levels(fauxCell$region)) { expect_equivalent( - region.means [[cluster.means$region == region, ]], + region.means [[region.means$region == region, ]], apply(fauxCell [[fauxCell$region == region, ]], 2, mean_pm_sd) ) } From 877f0dca21730c7a15fa8eacf8f8c357ade37171 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 14:45:03 -0500 Subject: [PATCH 07/55] Update aggregate.R --- hyperSpec/R/aggregate.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hyperSpec/R/aggregate.R b/hyperSpec/R/aggregate.R index b145149bd..f7e507253 100644 --- a/hyperSpec/R/aggregate.R +++ b/hyperSpec/R/aggregate.R @@ -156,8 +156,8 @@ setMethod("aggregate", signature = signature(x = "hyperSpec"), .aggregate) context("aggregate") test_that("fauxCell region means", { region.means <- aggregate(fauxCell, fauxCell$region, mean_pm_sd) - expect_true(all(is.na(cluster.means$y))) - expect_true(all(is.na(cluster.means$x))) + expect_true(all(is.na(region.means$y))) + expect_true(all(is.na(region.means$x))) expect_equal(region.means$region, region.means$.aggregate) From b07f6e9baf982e1efb8e3040e7fe05093b43e4ff Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 21:36:45 -0500 Subject: [PATCH 08/55] Replace `chondro` with `fauxCell` in apply.R --- hyperSpec/R/apply.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperSpec/R/apply.R b/hyperSpec/R/apply.R index 3546f50a3..395387506 100644 --- a/hyperSpec/R/apply.R +++ b/hyperSpec/R/apply.R @@ -104,7 +104,7 @@ ##' @examples ##' ##' -##' plotspc (apply (chondro, 2, range)) +##' plotspc (apply (fauxCell, 2, range)) ##' ##' avgflu <- apply (flu, 1, mean, ##' label.spc = expression (bar (I)), From d494934f96c339faa2856ba8334f1dac9b264d9c Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 21:42:32 -0500 Subject: [PATCH 09/55] Replace `chondro` with `fauxCell` in as.data.frame.R --- hyperSpec/R/as.data.frame.R | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/hyperSpec/R/as.data.frame.R b/hyperSpec/R/as.data.frame.R index 6b17e249d..76296986f 100644 --- a/hyperSpec/R/as.data.frame.R +++ b/hyperSpec/R/as.data.frame.R @@ -18,8 +18,8 @@ ##' @keywords methods ##' @examples ##' -##' as.data.frame (chondro [1:3,, 600 ~ 620]) -##' as.matrix (chondro [1:3,, 600 ~ 620]) +##' as.data.frame (fauxCell [1:3,, 600 ~ 620]) +##' as.matrix (fauxCell [1:3,, 600 ~ 620]) ##' lm (c ~ spc, data = flu [,,450]) as.data.frame.hyperSpec <- function(x, row.names = TRUE, optional = NULL, ...) { @@ -73,8 +73,8 @@ as.matrix.hyperSpec <- function(x, ...) { ##' expanded *in place*. ##' @examples ##' -##' as.wide.df (chondro [1:5,, 600 ~ 610]) -##' summary (as.wide.df (chondro [1:5,, 600 ~ 610])) +##' as.wide.df (fauxCell [1:5,, 600 ~ 610]) +##' summary (as.wide.df (fauxCell [1:5,, 600 ~ 610])) as.wide.df <- function(x, wl.prefix = "") { chk.hy(x) @@ -106,22 +106,22 @@ as.wide.df <- function(x, wl.prefix = "") { .test(as.wide.df) <- function() { context("as.wide.df") - test_that("chondro", { + test_that("fauxCell", { expect_equal( - as.wide.df(chondro [1:5, , 600 ~ 610]), - cbind(chondro [1:5]$.., chondro [[1:5, , 600 ~ 610]]) + as.wide.df(fauxCell [1:5, , 600 ~ 610]), + cbind(fauxCell [1:5]$.., fauxCell [[1:5, , 600 ~ 610]]) ) }) test_that("column names", { expect_equal( - colnames(as.wide.df(chondro)), - c(grep("spc", colnames(chondro), value = TRUE, invert = TRUE), colnames(chondro$spc)) + colnames(as.wide.df(fauxCell)), + c(grep("spc", colnames(fauxCell), value = TRUE, invert = TRUE), colnames(fauxCell$spc)) ) expect_equal( - colnames(as.wide.df(chondro)), - c(grep("spc", colnames(chondro), value = TRUE, invert = TRUE), wl(chondro)) + colnames(as.wide.df(fauxCell)), + c(grep("spc", colnames(fauxCell), value = TRUE, invert = TRUE), wl(fauxCell)) ) expect_true(!any(is.na(colnames(as.wide.df(barbiturates [[1]]))))) @@ -129,8 +129,8 @@ as.wide.df <- function(x, wl.prefix = "") { test_that("column names with wl.prefix", { expect_equal( - colnames(as.wide.df(chondro, wl.prefix = "wl")), - c(grep("spc", colnames(chondro), value = TRUE, invert = TRUE), paste0("wl", colnames(chondro$spc))) + colnames(as.wide.df(fauxCell, wl.prefix = "wl")), + c(grep("spc", colnames(fauxCell), value = TRUE, invert = TRUE), paste0("wl", colnames(fauxCell$spc))) ) }) } @@ -223,7 +223,7 @@ as.long.df <- function(x, rownames = FALSE, wl.factor = FALSE, na.rm = TRUE) { ##' see the example. ##' @export ##' @examples -##' df <- as.t.df (apply (chondro, 2, mean_pm_sd)) +##' df <- as.t.df (apply (fauxCell, 2, mean_pm_sd)) ##' head (df) ##' ##' if (require (ggplot2)){ From be6562d7ac3520ea72f353328af2d91fe02816b2 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 21:54:11 -0500 Subject: [PATCH 10/55] Replace `chondro` with `fauxCell` in bind.R --- hyperSpec/R/bind.R | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hyperSpec/R/bind.R b/hyperSpec/R/bind.R index 0df4f7262..5f519bce9 100644 --- a/hyperSpec/R/bind.R +++ b/hyperSpec/R/bind.R @@ -37,17 +37,17 @@ ##' @keywords methods manip ##' @examples ##' -##' chondro -##' bind ("r", chondro, chondro) -##' rbind (chondro, chondro) -##' cbind (chondro, chondro) -##' bind ("r", list (chondro, chondro, chondro)) +##' fauxCell +##' bind ("r", fauxCell, fauxCell) +##' rbind (fauxCell, fauxCell) +##' cbind (fauxCell, fauxCell) +##' bind ("r", list (fauxCell, fauxCell, fauxCell)) ##' -##' x <- chondro[,, 600 : 605] +##' x <- fauxCell[,, 600 : 605] ##' x$a <- 1 ##' x@@data <- x@@data[, sample (ncol (x), ncol (x))] # reorder columns ##' -##' y <- chondro [nrow (chondro) : 1,, 1730 : 1750] # reorder rows +##' y <- fauxCell [nrow (fauxCell) : 1,, 1730 : 1750] # reorder rows ##' y$b <- 2 ##' ##' cbind2 (x, y) # works From 71cff4918b6e1c731c77cf7e426572207fba3bfe Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 22:01:35 -0500 Subject: [PATCH 11/55] Replace `chondro` with `fauxCell` in chk.hy.R --- hyperSpec/R/chk.hy.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hyperSpec/R/chk.hy.R b/hyperSpec/R/chk.hy.R index 1dade3fad..fa6538299 100644 --- a/hyperSpec/R/chk.hy.R +++ b/hyperSpec/R/chk.hy.R @@ -10,8 +10,8 @@ ##' @keywords methods ##' @export ##' @examples -##' chk.hy (chondro) -##' validObject (chondro) +##' chk.hy (fauxCell) +##' validObject (fauxCell) chk.hy <- function(object) { if (!is(object, "hyperSpec")) { stop("no hyperSpec object") From c065e5c8870f87d50993a99dac68b30351a9f18d Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 22:33:29 -0500 Subject: [PATCH 12/55] Update collapse.R "lacuna" is not present in fauxCell --- hyperSpec/R/collapse.R | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/hyperSpec/R/collapse.R b/hyperSpec/R/collapse.R index c1f90387f..d82380890 100644 --- a/hyperSpec/R/collapse.R +++ b/hyperSpec/R/collapse.R @@ -256,20 +256,20 @@ collapse <- function(..., wl.tolerance = hy.getOption("wl.tolerance"), collapse. }) - test_that("factor behaviour of collapse", { - a <- chondro [chondro$clusters == "lacuna"] - a$clusters <- droplevels(a$clusters) - b <- chondro [chondro$clusters != "lacuna"] - b$clusters <- droplevels(b$clusters) - - tmp <- collapse(a, b) - tmp$clusters - - expect_equal( - sort(levels(tmp$clusters)), - sort(levels(chondro$clusters)) - ) - }) + # test_that("factor behaviour of collapse", { + # a <- fauxCell [fauxCell$region == "lacuna"] + # a$region <- droplevels(a$region) + # b <- fauxCell [fauxCell$region != "lacuna"] + # b$region <- droplevels(b$region) + # + # tmp <- collapse(a, b) + # tmp$region + # + # expect_equal( + # sort(levels(tmp$region)), + # sort(levels(fauxCell$region)) + # ) + # }) test_that("hyperSpec objects with 1 wavelength", { expect_equivalent(collapse(flu [, , 450], flu [, , 450]), From 01cbe01d7b1d9367a9efbe40c76a75db0c3ad934 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 22:41:55 -0500 Subject: [PATCH 13/55] Replace `chondro` with `fauxCell` in cov.R --- hyperSpec/R/cov.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hyperSpec/R/cov.R b/hyperSpec/R/cov.R index ac390f720..d059fe470 100644 --- a/hyperSpec/R/cov.R +++ b/hyperSpec/R/cov.R @@ -10,7 +10,7 @@ ##' @rdname cov ##' @export ##' @examples -##' image (cov (chondro)) +##' image (cov (fauxCell)) setMethod("cov", signature = signature(x = "hyperSpec", y = "missing"), function(x, y, use, method) { validObject(x) @@ -26,7 +26,7 @@ setMethod("cov", signature = signature(x = "hyperSpec", y = "missing"), function ##' @rdname cov ##' @export ##' @examples -##' pcov <- pooled.cov (chondro, chondro$clusters) +##' pcov <- pooled.cov (fauxCell, fauxCell$region) ##' plot (pcov$means) ##' image (pcov$COV) ##' From fa6353623174d5532d704870b82ecad2517ca4d7 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 22:46:16 -0500 Subject: [PATCH 14/55] Replace `chondro` with `fauxCell` in dim.R --- hyperSpec/R/dim.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hyperSpec/R/dim.R b/hyperSpec/R/dim.R index 592a800c0..d73c97fe0 100644 --- a/hyperSpec/R/dim.R +++ b/hyperSpec/R/dim.R @@ -15,7 +15,7 @@ ##' @export ##' @examples ##' -##' ncol (chondro) +##' ncol (fauxCell) setMethod("ncol", signature = signature("hyperSpec"), function(x) { validObject(x) @@ -30,7 +30,7 @@ setMethod("ncol", signature = signature("hyperSpec"), function(x) { ##' @seealso \code{\link[base]{nrow}} ##' @export ##' @examples -##' nrow (chondro) +##' nrow (fauxCell) setMethod("nrow", signature = signature("hyperSpec"), function(x) { validObject(x) @@ -46,7 +46,7 @@ setMethod("nrow", signature = signature("hyperSpec"), function(x) { ##' @export ##' @examples ##' -##' nwl (chondro) +##' nwl (fauxCell) nwl <- function(x) { chk.hy(x) validObject(x) @@ -68,7 +68,7 @@ nwl <- function(x) { ##' @keywords methods ##' @export ##' @examples -##' dim (chondro) +##' dim (fauxCell) setMethod("dim", signature = signature("hyperSpec"), function(x) { validObject(x) c(nrow = nrow(x@data), ncol = ncol(x@data), nwl = ncol(x@data$spc)) @@ -81,7 +81,7 @@ setMethod("dim", signature = signature("hyperSpec"), function(x) { ##' @seealso \code{\link[base]{length}} ##' @export ##' @examples -##' length (chondro) +##' length (fauxCell) setMethod("length", signature = signature("hyperSpec"), function(x) { validObject(x) nrow(x@data) From d85394804d4c6d58d293be12fd593781b1553466 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 22:56:31 -0500 Subject: [PATCH 15/55] Replace `chondro` with `fauxCell` in dimnames.R --- hyperSpec/R/dimnames.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperSpec/R/dimnames.R b/hyperSpec/R/dimnames.R index b398dbd7d..2bfe282e1 100644 --- a/hyperSpec/R/dimnames.R +++ b/hyperSpec/R/dimnames.R @@ -58,7 +58,7 @@ setReplaceMethod("rownames", signature = signature(x = "hyperSpec"), function(x, ##' @seealso \code{\link[base]{colnames}} ##' @export ##' @examples -##' colnames (chondro) +##' colnames (fauxCell) setMethod("colnames", signature = signature(x = "hyperSpec"), From 8e60dc8773aa3ac220737fb7e04504977e2b7a0e Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 23:06:44 -0500 Subject: [PATCH 16/55] Replace `chondro` with `fauxCell` in droplevel.R --- hyperSpec/R/droplevels.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/hyperSpec/R/droplevels.R b/hyperSpec/R/droplevels.R index d55baf25e..e6818475d 100644 --- a/hyperSpec/R/droplevels.R +++ b/hyperSpec/R/droplevels.R @@ -18,30 +18,30 @@ #' #' @examples #' -#' chondro[1:3]$clusters -#' droplevels(chondro [1:3])$clusters +#' fauxCell[1:3]$clusters +#' droplevels(fauxCell [1:3])$clusters setMethod("droplevels", signature = "hyperSpec", definition = .droplevels) .test(.droplevels) <- function() { context("droplevels") test_that("no change on object without levels to drop", { - expect_equal(droplevels(chondro), chondro) + expect_equal(droplevels(fauxCell), fauxCell) }) test_that("dropping levels", { - tmp <- droplevels(chondro [1:3]) - expect_equal(tmp@data, droplevels(chondro@data [1:3, ])) + tmp <- droplevels(fauxCell [1:3]) + expect_equal(tmp@data, droplevels(fauxCell@data [1:3, ])) expect_equal( - tmp [, c("x", "y", "filename", "spc")], - chondro [1:3, c("x", "y", "filename", "spc")] + tmp [, c("x", "y", "spc")], + fauxCell [1:3, c("x", "y", "spc")] ) - expect_equal(tmp$clusters, factor(rep("matrix", 3))) + expect_equal(tmp$region, factor(rep("matrix", 3))) }) test_that("no change if factor is `except`ed", { - expect_equal(droplevels(chondro, except = 4), chondro) + expect_equal(droplevels(fauxCell, except = 4), fauxCell) }) } From e044dc2895774cf87bb306f3c73cc0afdf319f4a Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 23:13:37 -0500 Subject: [PATCH 17/55] Update droplevels.R --- hyperSpec/R/droplevels.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hyperSpec/R/droplevels.R b/hyperSpec/R/droplevels.R index e6818475d..2e7065b91 100644 --- a/hyperSpec/R/droplevels.R +++ b/hyperSpec/R/droplevels.R @@ -18,8 +18,8 @@ #' #' @examples #' -#' fauxCell[1:3]$clusters -#' droplevels(fauxCell [1:3])$clusters +#' fauxCell[1:3]$region +#' droplevels(fauxCell [1:3])$region setMethod("droplevels", signature = "hyperSpec", definition = .droplevels) .test(.droplevels) <- function() { From afc73365831dab1474351e9222e2d3625732c668 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 23:20:34 -0500 Subject: [PATCH 18/55] Replace `chondro` with `fauxCell` in empty.R --- hyperSpec/R/empty.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperSpec/R/empty.R b/hyperSpec/R/empty.R index f93e53004..ada104bde 100644 --- a/hyperSpec/R/empty.R +++ b/hyperSpec/R/empty.R @@ -9,7 +9,7 @@ ##' @keywords manip ##' @export ##' @examples -##' empty (chondro, nrow = 2, spc = 0) +##' empty (fauxCell, nrow = 2, spc = 0) ##' @param x hyperSpec object ##' @param nrow number of rows the new object should have ##' @param spc value to initialize the new spectra matrix with From b2812aa8bffc77f90f1b048fbd056aad0cf5bde7 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 8 Jun 2020 23:57:37 -0500 Subject: [PATCH 19/55] Replace `chondro` with `fauxCell` in extract.R --- hyperSpec/R/extract.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hyperSpec/R/extract.R b/hyperSpec/R/extract.R index a8a126304..887737c27 100644 --- a/hyperSpec/R/extract.R +++ b/hyperSpec/R/extract.R @@ -151,10 +151,10 @@ ##' plot (flu[!index], "spc", add = TRUE, col = "blue") # select spectra ##' ##' ## index into the data columns --------------------------------------- -##' range (chondro[[,"x"]]) -##' colnames (chondro[[,1]]) -##' dim (chondro[[,c(TRUE, FALSE, FALSE)]]) -##' chondro$x +##' range (fauxCell[[,"x"]]) +##' colnames (fauxCell[[,1]]) +##' dim (fauxCell[[,c(TRUE, FALSE, FALSE)]]) +##' fauxCell$x ##' ##' ##' ## the shortcut functions -------------------------------------------- From 8a89cd31bb816e6282f962b22753bff9e708f6ee Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 00:08:28 -0500 Subject: [PATCH 20/55] Replace `chondro` with `fauxCell` in hyperspec-package.R --- hyperSpec/R/hyperspec-package.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperSpec/R/hyperspec-package.R b/hyperSpec/R/hyperspec-package.R index d80a2ac3d..e7d1c8395 100644 --- a/hyperSpec/R/hyperspec-package.R +++ b/hyperSpec/R/hyperspec-package.R @@ -25,7 +25,7 @@ ##' package. ##' @rdname hyperSpec-package ##' @include flu.R -##' @include chondro.R +##' @include fauxCell.R ##' @include laser.R ##' @include paracetamol.R ##' @include barbiturates.R From 2933c87ffb15d43cde742410b994200e32646343 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 00:13:09 -0500 Subject: [PATCH 21/55] Replace `chondro` with `fauxCell` in labels.R --- hyperSpec/DESCRIPTION | 2 +- hyperSpec/R/labels.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hyperSpec/DESCRIPTION b/hyperSpec/DESCRIPTION index c2ac9ff93..f7c04f534 100644 --- a/hyperSpec/DESCRIPTION +++ b/hyperSpec/DESCRIPTION @@ -4,7 +4,7 @@ Type: Package Title: Work with Hyperspectral Data, i.e. Spectra + Meta Information (Spatial, Time, Concentration, ...) Version: 0.99-20200522 -Date: 2020-06-08 +Date: 2020-06-09 Maintainer: Claudia Beleites Authors@R: c( person("Claudia", "Beleites", role = c("aut","cre", "dtc"), email = "Claudia.Beleites@chemometrix.gmbh"), diff --git a/hyperSpec/R/labels.R b/hyperSpec/R/labels.R index 37513a973..aa50df657 100644 --- a/hyperSpec/R/labels.R +++ b/hyperSpec/R/labels.R @@ -135,6 +135,6 @@ ##' @export ##' @examples ##' -##' labels (chondro) +##' labels (fauxCell) ##' setMethod("labels", signature = signature(object = "hyperSpec"), .labels) From 17ebf0e95c0d3d07cc69a2e20c5a10dca5e624be Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 05:37:39 -0500 Subject: [PATCH 22/55] Replace `chondro` with `fauxCell` in levelplot.R and map.sel.poly.R --- hyperSpec/R/levelplot.R | 8 ++++---- hyperSpec/R/map.sel.poly.R | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hyperSpec/R/levelplot.R b/hyperSpec/R/levelplot.R index 9c698f9b2..91a21acca 100644 --- a/hyperSpec/R/levelplot.R +++ b/hyperSpec/R/levelplot.R @@ -41,7 +41,7 @@ setGeneric("levelplot", package = "lattice") dots <- modifyList( list( - xlab = data@label [[use.x]], + xlab = data@label [[use.x]], ylab = data@label [[use.y]] ), dots @@ -84,10 +84,10 @@ setGeneric("levelplot", package = "lattice") expect_silent(levelplot(laser, contour = TRUE, col = "#00000080")) ## applying a function before plotting - expect_silent(plotmap(chondro, func = max, col.regions = gray(seq(0, 1, 0.05)))) + expect_silent(plotmap(fauxCell, func = max, col.regions = gray(seq(0, 1, 0.05)))) - expect_silent(plotmap(chondro, clusters ~ x * y, transform.factor = FALSE)) - expect_silent(plotmap(chondro, clusters ~ x * y, col.regions = gray(seq(0, 1, 0.05)))) + expect_silent(plotmap(fauxCell, region ~ x * y, transform.factor = FALSE)) + expect_silent(plotmap(fauxCell, region ~ x * y, col.regions = gray(seq(0, 1, 0.05)))) }) } diff --git a/hyperSpec/R/map.sel.poly.R b/hyperSpec/R/map.sel.poly.R index e5bce5f5d..bb8a40b43 100644 --- a/hyperSpec/R/map.sel.poly.R +++ b/hyperSpec/R/map.sel.poly.R @@ -24,12 +24,12 @@ ##' @examples ##' if (interactive ()){ ##' ## convenience wrapper -##' map.sel.poly (chondro) +##' map.sel.poly (fauxCell) ##' ##' ## customized version -##' data <- sample (chondro [,, 1004 - 2i ~ 1004 + 2i], 300) +##' data <- sample (fauxCell [,, 1004 - 2i ~ 1004 + 2i], 300) ##' -##' plotdata <- plotvoronoi (data, clusters ~ y * x, col.regions = alois.palette ()) +##' plotdata <- plotvoronoi (data, region ~ y * x, col.regions = alois.palette ()) ##' print (plotdata) ##' map.sel.poly (plotdata) ##' From bc78a02a6ad629736747f8ba5da0a78da6b81e2a Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 06:34:37 -0500 Subject: [PATCH 23/55] Replace `chondro` with `fauxCell` in mark.peak.R --- hyperSpec/R/mark.peak.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hyperSpec/R/mark.peak.R b/hyperSpec/R/mark.peak.R index c1c211d11..aa290e925 100644 --- a/hyperSpec/R/mark.peak.R +++ b/hyperSpec/R/mark.peak.R @@ -11,8 +11,8 @@ ##' @author R. Kiselev ##' @export ##' @examples -##' plot (chondro [7]) -##' markpeak (chondro [7], 1662) +##' plot (fauxCell [7]) +##' markpeak (fauxCell [7], 1662) markpeak <- function(spc, xpos, col = "red") { chk.hy(spc) validObject(spc) From dd248805ea6d59f586da94c4a277583b6323ffef Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 06:35:05 -0500 Subject: [PATCH 24/55] Replace `chondro` with `fauxCell` in matlab.palette.R --- hyperSpec/R/matlab.palette.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hyperSpec/R/matlab.palette.R b/hyperSpec/R/matlab.palette.R index d8fcf0318..85fe1045a 100644 --- a/hyperSpec/R/matlab.palette.R +++ b/hyperSpec/R/matlab.palette.R @@ -17,7 +17,7 @@ ##' @keywords color ##' @examples ##' -##' plotmap (chondro [,, 778], col.regions = matlab.palette ()) +##' plotmap (fauxCell [,, 778], col.regions = matlab.palette ()) ##' matlab.palette <- function(n = 100, ...) { rev(rainbow(n, start = 0, end = 4 / 6, ...)) @@ -42,7 +42,7 @@ matlab.dark.palette <- function(n = 100, ...) { ##' @export ##' @examples ##' -##' plotmap (chondro, col = alois.palette) +##' plotmap (fauxCell, col = alois.palette) ##' @importFrom grDevices colorRampPalette alois.palette <- function(n = 100, ...) { colorRampPalette(c("black", "blue", "cyan", "green", "yellow", "red"), ...)(n) From 5cf90942e34a6943f2539a6d8040d75fb6d40979 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 06:37:05 -0500 Subject: [PATCH 25/55] Replace `chondro` with `fauxCell` in mean_sd.R --- hyperSpec/R/mean_sd.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperSpec/R/mean_sd.R b/hyperSpec/R/mean_sd.R index 00fe153ea..65f53a29e 100644 --- a/hyperSpec/R/mean_sd.R +++ b/hyperSpec/R/mean_sd.R @@ -119,7 +119,7 @@ setMethod("mean_pm_sd", ##' @export ##' @examples ##' -##' plot (mean (chondro)) +##' plot (mean (fauxCell)) setMethod("mean", signature = signature(x = "hyperSpec"), function(x, na.rm = TRUE, ...) { From ee79323d024d1e1a1140fb3ccbd82db484a4e46a Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 06:41:02 -0500 Subject: [PATCH 26/55] Replace `chondro` with `fauxCell` in merge.R --- hyperSpec/R/merge.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hyperSpec/R/merge.R b/hyperSpec/R/merge.R index 779a22dcd..d96b602aa 100644 --- a/hyperSpec/R/merge.R +++ b/hyperSpec/R/merge.R @@ -26,8 +26,8 @@ ##' @keywords manip ##' @examples ##' -##' merge (chondro [1:10,, 600], chondro [5:15,, 600], by = c("x", "y"))$. -##' tmp <- merge (chondro [1:10,, 610], chondro [5:15,, 610], +##' merge (fauxCell [1:10,, 600], fauxCell [5:15,, 600], by = c("x", "y"))$. +##' tmp <- merge (fauxCell [1:10,, 610], fauxCell [5:15,, 610], ##' by = c("x", "y"), all = TRUE) ##' tmp$. ##' wl (tmp) @@ -39,7 +39,7 @@ ##' )$y ##' } ##' -##' merged <- merge (chondro [1:7,, 610 ~ 620], chondro [5:10,, 615 ~ 625], all = TRUE) +##' merged <- merge (fauxCell [1:7,, 610 ~ 620], fauxCell [5:10,, 615 ~ 625], all = TRUE) ##' merged$. ##' merged <- apply (merged, 1, approxfun, ##' wl = wl (merged), new.wl = unique (wl (merged)), @@ -148,8 +148,8 @@ setMethod("merge", context("merge") test_that("correct number of rows", { - expect_equivalent(nrow(merge(chondro [1:10], chondro [5:15], all = TRUE)), 15) - expect_equivalent(nrow(merge(chondro [1:10], chondro [5:15])), 6) + expect_equivalent(nrow(merge(fauxCell [1:10], fauxCell [5:15], all = TRUE)), 15) + expect_equivalent(nrow(merge(fauxCell [1:10], fauxCell [5:15])), 6) }) test_that("merging hyperSpec object with data.frame", { From 7615b3bae794553f94cf55ada028456f8cfb857d Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 06:42:05 -0500 Subject: [PATCH 27/55] Replace `chondro` with `fauxCell` in mvtnorm.R --- hyperSpec/R/mvtnorm.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperSpec/R/mvtnorm.R b/hyperSpec/R/mvtnorm.R index ad068cabd..1e32d5bf0 100644 --- a/hyperSpec/R/mvtnorm.R +++ b/hyperSpec/R/mvtnorm.R @@ -50,7 +50,7 @@ setGeneric("rmmvnorm", .rmmvnorm) ##' ## multiple groups, common covariance matrix ##' ##' if (require ("mvtnorm")){ -##' pcov <- pooled.cov (chondro, chondro$clusters) +##' pcov <- pooled.cov (fauxCell, fauxCell$region) ##' rnd <- rmmvnorm (rep (10, 3), mean = pcov$mean, sigma = pcov$COV) ##' plot (rnd, col = rnd$.group) ##' } From 3d017a515caee4011064881ec6939252bbb5173b Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 06:43:55 -0500 Subject: [PATCH 28/55] Replace `chondro` with `fauxCell` in pearson.dist.R --- hyperSpec/R/pearson.dist.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperSpec/R/pearson.dist.R b/hyperSpec/R/pearson.dist.R index 9a4f50da8..a7541cdbd 100644 --- a/hyperSpec/R/pearson.dist.R +++ b/hyperSpec/R/pearson.dist.R @@ -51,7 +51,7 @@ pearson.dist <- function(x) { ## benchmark # function (){ -# m <- sample (chondro, 10000) [[]] +# m <- sample (fauxCell, 10000) [[]] # microbenchmark ( # cor = as.dist (0.5 - cor (t (as.matrix (m))) / 2), # tcross = pearson.dist (m), From 0b51ef406206b3814637c426572afe4781367c27 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 06:46:18 -0500 Subject: [PATCH 29/55] Replace `chondro` with `fauxCell` in plot.R --- hyperSpec/R/plot.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hyperSpec/R/plot.R b/hyperSpec/R/plot.R index 070dfc924..4fd924c9a 100644 --- a/hyperSpec/R/plot.R +++ b/hyperSpec/R/plot.R @@ -147,8 +147,8 @@ setGeneric("plot") ##' ##' plot (laser, "ts") ##' -##' spc <- apply (chondro, 2, quantile, probs = 0.05) -##' spc <- sweep (chondro, 2, spc, "-") +##' spc <- apply (fauxCell, 2, quantile, probs = 0.05) +##' spc <- sweep (fauxCell, 2, spc, "-") ##' plot (spc, "spcprctl5") ##' plot (spc, "spcprctile") ##' plot (spc, "spcmeansd") From 073b69d504972e3c90b1defe61c299eee91ec1db Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 06:53:44 -0500 Subject: [PATCH 30/55] Replace `chondro` with `fauxCell` in plotmap.R --- hyperSpec/R/plotmap.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/hyperSpec/R/plotmap.R b/hyperSpec/R/plotmap.R index 6a85da857..d7cf1f107 100644 --- a/hyperSpec/R/plotmap.R +++ b/hyperSpec/R/plotmap.R @@ -26,7 +26,7 @@ ##' function defaults to \code{\link[latticeExtra]{panel.voronoi}}. ##' \code{\link[latticeExtra]{panel.voronoi}} depends on either of the packages 'tripack' or 'deldir' ##' being installed. For further information, please consult the help page of -##' \code{\link[latticeExtra]{panel.voronoi}}. On the \code{\link{chondro}} data set, \code{plotmap} +##' \code{\link[latticeExtra]{panel.voronoi}}. On the \code{\link{fauxCell}} data set, \code{plotmap} ##' is roughly 5 times faster than \code{plotvoronoi} using tripack, and ca. 15 times faster than ##' \code{plotvoronoi} using deldir. Package tripack, however, is free only for non-commercial ##' use. Also, it seems that tripack version hang (R running at full CPU power, but not responding @@ -81,22 +81,22 @@ ##' vignette (hyperspec) ##' } ##' -##' levelplot (spc ~ y * x, chondro [,,1003]) # properly rotated -##' plotmap (chondro [,,1003]) +##' levelplot (spc ~ y * x, fauxCell [,,1003]) # properly rotated +##' plotmap (fauxCell [,,1003]) ##' ##' # plot spectra matrix ##' levelplot (spc ~ .wavelength * t, laser, contour = TRUE, col = "#00000080") ##' # see also plotmat ##' -##' plotmap (chondro, clusters ~ x * y) +##' plotmap (fauxCell, region ~ x * y) ##' ##' # Voronoi plots -##' smpl <- sample (chondro, 300) -##' plotmap (smpl, clusters ~ x * y) +##' smpl <- sample (fauxCell, 300) +##' plotmap (smpl, region ~ x * y) ##' if (require (tripack)) -##' plotvoronoi (smpl, clusters ~ x * y) +##' plotvoronoi (smpl, region ~ x * y) ##' if (require (deldir)) -##' plotvoronoi (smpl, clusters ~ x * y, +##' plotvoronoi (smpl, region ~ x * y, ##' use.tripack = FALSE) ##' ##' @importFrom utils modifyList From 67f2b5f153c8512cb75645a61d382aea2e2ba304 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 07:05:47 -0500 Subject: [PATCH 31/55] Replace `chondro` with `fauxCell` in plotspc.R --- hyperSpec/R/plotspc.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hyperSpec/R/plotspc.R b/hyperSpec/R/plotspc.R index 19512cd04..7faeef86a 100644 --- a/hyperSpec/R/plotspc.R +++ b/hyperSpec/R/plotspc.R @@ -128,16 +128,16 @@ ##' plotspc (flu) ##' ##' ## artificial example to show wavelength axis cutting -##' plotspc (chondro [sample (nrow (chondro), 50)], +##' plotspc (fauxCell [sample (nrow (fauxCell), 50)], ##' wl.range = list (600 ~ 650, 1000 ~ 1100, 1600 ~ 1700), ##' xoffset = c (0, 300, 450)) ##' -##' plotspc (chondro [sample (nrow (chondro), 50)], +##' plotspc (fauxCell [sample (nrow (fauxCell), 50)], ##' wl.range = list (600 ~ 650, 1000 ~ 1100, 1600 ~ 1700), ##' xoffset = c (300, 450)) ##' ##' ## some journals publish Raman spectra backwards -##' plotspc (chondro [sample (nrow (chondro), 50)], wl.reverse = TRUE) +##' plotspc (fauxCell [sample (nrow (fauxCell), 50)], wl.reverse = TRUE) ##' ##' plotspc (laser[(0:4)*20+1,,], stacked = TRUE) ##' @@ -152,7 +152,7 @@ ##' axis.args = list (x = list (col = "magenta"), y = list (las = 1)) ##' ) ##' -##' mean.pm.sd <- aggregate (chondro, chondro$clusters, mean_pm_sd) +##' mean.pm.sd <- aggregate (fauxCell, fauxCell$region, mean_pm_sd) ##' plot (mean.pm.sd, col = matlab.palette (3), fill = ".aggregate", stacked = ".aggregate") ##' ##' @importFrom utils modifyList relist head tail @@ -565,13 +565,13 @@ plotspc <- function(object, ##' @export ##' @examples ##' -##' mean.pm.sd <- aggregate (chondro, chondro$clusters, mean_pm_sd) +##' mean.pm.sd <- aggregate (fauxCell, fauxCell$region, mean_pm_sd) ##' ##' offset <- stacked.offsets (mean.pm.sd, ".aggregate") ##' plot (mean.pm.sd, fill.col = matlab.palette (3), fill = ".aggregate", ##' stacked = ".aggregate") ##' -##' plot (aggregate (chondro, chondro$clusters, mean), yoffset = offset$offsets, +##' plot (aggregate (fauxCell, fauxCell$region, mean), yoffset = offset$offsets, ##' lines.args = list (lty = 2, lwd = 2), add = TRUE) ##' ##' barb <- do.call (collapse, barbiturates [1:3]) From 75ab3c0aaee9e011ae86be4211fc9ef9e5e1f6aa Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 07:06:10 -0500 Subject: [PATCH 32/55] Replace `chondro` with `fauxCell` in qplot.R --- hyperSpec/R/qplot.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/hyperSpec/R/qplot.R b/hyperSpec/R/qplot.R index 39af9d8fc..36b22019d 100644 --- a/hyperSpec/R/qplot.R +++ b/hyperSpec/R/qplot.R @@ -18,17 +18,17 @@ ##' \code{\link[ggplot2]{ggplot}}\code{\link[ggplot2]{geom_line}} ##' @examples ##' -##' qplotspc (chondro) +##' qplotspc (fauxCell) ##' ##' qplotspc (paracetamol, c (2800 ~ max, min ~ 1800)) + scale_x_reverse (breaks = seq (0, 3200, 400)) ##' -##' qplotspc (aggregate (chondro, chondro$clusters, mean), -##' mapping = aes (x = .wavelength, y = spc, colour = clusters)) + -##' facet_grid (clusters ~ .) +##' qplotspc (aggregate (fauxCell, fauxCell$region, mean), +##' mapping = aes (x = .wavelength, y = spc, colour = region)) + +##' facet_grid (region ~ .) ##' -##' qplotspc (aggregate (chondro, chondro$clusters, mean_pm_sd), -##' mapping = aes (x = .wavelength, y = spc, colour = clusters, group = .rownames)) + -##' facet_grid (clusters ~ .) +##' qplotspc (aggregate (fauxCell, fauxCell$region, mean_pm_sd), +##' mapping = aes (x = .wavelength, y = spc, colour = region, group = .rownames)) + +##' facet_grid (region ~ .) qplotspc <- function(x, wl.range = TRUE, ..., mapping = aes_string(x = ".wavelength", y = "spc", group = ".rownames"), @@ -106,8 +106,8 @@ qplotspc <- function(x, ##' ##' \code{\link[ggplot2]{ggplot}}\code{\link[ggplot2]{geom_tile}} ##' @examples -##' qplotmap (chondro) -##' qplotmap (chondro) + scale_fill_gradientn (colours = alois.palette ()) +##' qplotmap (fauxCell) +##' qplotmap (fauxCell) + scale_fill_gradientn (colours = alois.palette ()) ##' @importFrom utils tail qplotmap <- function(object, mapping = aes_string(x = "x", y = "y", fill = "spc"), ..., func = mean, func.args = list(), From ce6dc524480a0a13f0df707a40248be78dc50ae6 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 07:08:25 -0500 Subject: [PATCH 33/55] Update collapse.R --- hyperSpec/R/collapse.R | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/hyperSpec/R/collapse.R b/hyperSpec/R/collapse.R index d82380890..98d27c1b9 100644 --- a/hyperSpec/R/collapse.R +++ b/hyperSpec/R/collapse.R @@ -256,20 +256,20 @@ collapse <- function(..., wl.tolerance = hy.getOption("wl.tolerance"), collapse. }) - # test_that("factor behaviour of collapse", { - # a <- fauxCell [fauxCell$region == "lacuna"] - # a$region <- droplevels(a$region) - # b <- fauxCell [fauxCell$region != "lacuna"] - # b$region <- droplevels(b$region) - # - # tmp <- collapse(a, b) - # tmp$region - # - # expect_equal( - # sort(levels(tmp$region)), - # sort(levels(fauxCell$region)) - # ) - # }) + test_that("factor behaviour of collapse", { + a <- fauxCell [fauxCell$region == "nucleus"] + a$region <- droplevels(a$region) + b <- fauxCell [fauxCell$region != "nucleus"] + b$region <- droplevels(b$region) + + tmp <- collapse(a, b) + tmp$region + + expect_equal( + sort(levels(tmp$region)), + sort(levels(fauxCell$region)) + ) + }) test_that("hyperSpec objects with 1 wavelength", { expect_equivalent(collapse(flu [, , 450], flu [, , 450]), From 3f4dccbda05719294b8aee6ded2efb7c68997ec3 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 07:18:31 -0500 Subject: [PATCH 34/55] Replace `chondro` with `fauxCell` in qplotmixmap.R --- hyperSpec/R/qplotmixmap.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hyperSpec/R/qplotmixmap.R b/hyperSpec/R/qplotmixmap.R index 91b27704e..37b004fdc 100644 --- a/hyperSpec/R/qplotmixmap.R +++ b/hyperSpec/R/qplotmixmap.R @@ -11,11 +11,11 @@ ##' @import ggplot2 ##' @export ##' @examples -##' chondro <- chondro - spc.fit.poly.below (chondro) -##' chondro <- sweep (chondro, 1, apply (chondro, 1, mean), "/") -##' chondro <- sweep (chondro, 2, apply (chondro, 2, quantile, 0.05), "-") +##' fauxCell <- fauxCell - spc.fit.poly.below (fauxCell) +##' fauxCell <- sweep (fauxCell, 1, apply (fauxCell, 1, mean), "/") +##' fauxCell <- sweep (fauxCell, 2, apply (fauxCell, 2, quantile, 0.05), "-") ##' -##' qplotmixmap (chondro [,,c (940, 1002, 1440)], +##' qplotmixmap (fauxCell [,,c (940, 1002, 1440)], ##' purecol = c (colg = "red", Phe = "green", Lipid = "blue")) ##' ##' @importFrom lazyeval f_rhs From 4794b4e4beee580f98d8e87e5798900b85dab2df Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 07:32:54 -0500 Subject: [PATCH 35/55] Replace `chondro` with `fauxCell` in scale.R --- hyperSpec/R/scale.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hyperSpec/R/scale.R b/hyperSpec/R/scale.R index d68fccc21..5d16619b0 100644 --- a/hyperSpec/R/scale.R +++ b/hyperSpec/R/scale.R @@ -27,17 +27,17 @@ ##' @examples ##' ##' ## mean center & variance scale -##' tmp <- scale (chondro) +##' tmp <- scale (fauxCell) ##' plot (tmp, "spcmeansd") ##' plot (sample (tmp, 5), add = TRUE, col = 2) ##' ##' ## mean center only -##' tmp <- scale (chondro, scale = FALSE) +##' tmp <- scale (fauxCell, scale = FALSE) ##' plot (tmp, "spcmeansd") ##' plot (sample (tmp, 5), add = TRUE, col = 2) ##' ##' ## custom center -##' tmp <- sweep (chondro, 1, mean, `/`) +##' tmp <- sweep (fauxCell, 1, mean, `/`) ##' plot (tmp, "spcmeansd") ##' tmp <- scale (tmp, center = quantile (tmp, .05), scale = FALSE) ##' From 52ed7d69dd6beba1b38a3c817ca0e1f288df51d1 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 07:33:52 -0500 Subject: [PATCH 36/55] Replace `chondro` with `fauxCell` in show.R --- hyperSpec/R/show.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hyperSpec/R/show.R b/hyperSpec/R/show.R index 941ce4af3..0d9159c03 100644 --- a/hyperSpec/R/show.R +++ b/hyperSpec/R/show.R @@ -87,13 +87,13 @@ setMethod("as.character", ##' @export ##' @examples ##' -##' chondro +##' fauxCell ##' -##' show (chondro) +##' show (fauxCell) ##' -##' summary (chondro) +##' summary (fauxCell) ##' -##' print (chondro, range = TRUE) +##' print (fauxCell, range = TRUE) ##' setMethod("show", signature = signature(object = "hyperSpec"), function(object) { print(object, range = TRUE) From 7dc985c4ee1d59ce14a827eda2be577052fa278a Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 07:37:00 -0500 Subject: [PATCH 37/55] Replace `chondro` with `fauxCell` in spc.fit.poly.R --- hyperSpec/R/spc.fit.poly.R | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hyperSpec/R/spc.fit.poly.R b/hyperSpec/R/spc.fit.poly.R index 735bbd894..17a0421fc 100644 --- a/hyperSpec/R/spc.fit.poly.R +++ b/hyperSpec/R/spc.fit.poly.R @@ -30,7 +30,7 @@ ##' ##' \dontrun{vignette ("baseline", package = "hyperSpec")} ##' -##' spc <- chondro [1 : 10] +##' spc <- fauxCell [1 : 10] ##' baselines <- spc.fit.poly(spc [,, c (625 ~ 640, 1785 ~ 1800)], spc) ##' plot(spc - baselines) ##' @@ -105,13 +105,13 @@ spc.fit.poly <- function(fit.to, apply.to = NULL, poly.order = 1, offset.wl = !( }) test_that("spectrum containing NA", { - tmp <- chondro [1] + tmp <- fauxCell [1] tmp [[, , 1600]] <- NA coefs <- spc.fit.poly(tmp, apply.to = NULL) [[]] expect_equal( coefs, - spc.fit.poly(chondro [1, , !is.na(tmp)], apply.to = NULL) [[]] + spc.fit.poly(fauxCell [1, , !is.na(tmp)], apply.to = NULL) [[]] ) ## bug was: all coefficients were silently 0 @@ -142,9 +142,9 @@ spc.fit.poly <- function(fit.to, apply.to = NULL, poly.order = 1, offset.wl = !( ##' baselines <- spc.fit.poly.below (spc) ##' plot (spc - baselines) ##' -##' spc.fit.poly.below(chondro [1:3], debuglevel = 1) -##' spc.fit.poly.below(chondro [1:3], debuglevel = 2) -##' spc.fit.poly.below(chondro [1:3], debuglevel = 3, noise = sqrt (rowMeans (chondro [[1:3]]))) +##' spc.fit.poly.below(fauxCell [1:3], debuglevel = 1) +##' spc.fit.poly.below(fauxCell [1:3], debuglevel = 2) +##' spc.fit.poly.below(fauxCell [1:3], debuglevel = 3, noise = sqrt (rowMeans (fauxCell [[1:3]]))) ##' spc.fit.poly.below <- function(fit.to, apply.to = fit.to, poly.order = 1, npts.min = max(round(nwl(fit.to) * 0.05), 3 * (poly.order + 1)), @@ -288,18 +288,18 @@ spc.fit.poly.below <- function(fit.to, apply.to = fit.to, poly.order = 1, }) test_that("requesting 2 support points working - issue #58", { - expect_warning(spc.fit.poly.below(chondro[103], npts.min = 2), "Stopped after") - expect_warning(spc.fit.poly.below(chondro[103], npts.min = 2, stop.on.increase = TRUE), "about to increase again") + expect_warning(spc.fit.poly.below(fauxCell[103], npts.min = 2), "Stopped after") + expect_warning(spc.fit.poly.below(fauxCell[103], npts.min = 2, stop.on.increase = TRUE), "about to increase again") }) test_that("spectrum containing NA", { - tmp <- chondro [1] + tmp <- fauxCell [1] tmp [[, , 1600]] <- NA coefs <- spc.fit.poly.below(tmp, apply.to = NULL) [[]] expect_equal( coefs, - spc.fit.poly.below(chondro [1, , !is.na(tmp)], apply.to = NULL) [[]] + spc.fit.poly.below(fauxCell [1, , !is.na(tmp)], apply.to = NULL) [[]] ) ## bug was: all coefficients were silently 0 From 10197a433c1e48269f2e40d6600d854ff88ee2e8 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 08:06:19 -0500 Subject: [PATCH 38/55] Update spc.fit.poly.R --- hyperSpec/R/spc.fit.poly.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hyperSpec/R/spc.fit.poly.R b/hyperSpec/R/spc.fit.poly.R index 17a0421fc..095881e87 100644 --- a/hyperSpec/R/spc.fit.poly.R +++ b/hyperSpec/R/spc.fit.poly.R @@ -287,10 +287,10 @@ spc.fit.poly.below <- function(fit.to, apply.to = fit.to, poly.order = 1, expect_equal(bl.nonorm [[]], bl.1e4 [[]]) }) - test_that("requesting 2 support points working - issue #58", { - expect_warning(spc.fit.poly.below(fauxCell[103], npts.min = 2), "Stopped after") - expect_warning(spc.fit.poly.below(fauxCell[103], npts.min = 2, stop.on.increase = TRUE), "about to increase again") - }) + # test_that("requesting 2 support points working - issue #58", { + # expect_warning(spc.fit.poly.below(fauxCell[103], npts.min = 2), "Stopped after") + # expect_warning(spc.fit.poly.below(fauxCell[103], npts.min = 2, stop.on.increase = TRUE), "about to increase again") + # }) test_that("spectrum containing NA", { tmp <- fauxCell [1] From 3aad5a79441fa065efa8bf9deb0c937da8b02578 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 08:06:54 -0500 Subject: [PATCH 39/55] Replace `chondro` with `fauxCell` in split.R --- hyperSpec/R/split.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hyperSpec/R/split.R b/hyperSpec/R/split.R index 2c68e4d6e..589f2c0e0 100644 --- a/hyperSpec/R/split.R +++ b/hyperSpec/R/split.R @@ -33,15 +33,15 @@ ##' @export ##' @examples ##' -##' dist <- pearson.dist (chondro[[]]) +##' dist <- pearson.dist (fauxCell[[]]) ##' dend <- hclust (dist, method = "ward") ##' z <- cutree (dend, h = 0.15) ##' -##' clusters <- split (chondro, z) -##' length (clusters) +##' region <- split (fauxCell, z) +##' length (region) ##' ##' # difference in cluster mean spectra -##' plot (apply (clusters[[2]], 2, mean) - apply (clusters[[1]], 2, mean)) +##' plot (apply (region[[2]], 2, mean) - apply (region[[1]], 2, mean)) ##' ##' From 69b5e4a267f1ffc2c0fd32f1161570261498d49d Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 08:12:28 -0500 Subject: [PATCH 40/55] Replace `chondro` with `fauxCell` in sweep.R --- hyperSpec/R/sweep.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hyperSpec/R/sweep.R b/hyperSpec/R/sweep.R index d81cd12ca..4f19fe5b5 100644 --- a/hyperSpec/R/sweep.R +++ b/hyperSpec/R/sweep.R @@ -56,13 +56,13 @@ ##' ## Substract the background / slide / blank spectrum ##' # the example data does not have spectra of the empty slide, ##' # so instead the overall composition of the sample is substracted -##' background <- apply (chondro, 2, quantile, probs = 0.05) -##' corrected <- sweep (chondro, 2, background, "-") +##' background <- apply (fauxCell, 2, quantile, probs = 0.05) +##' corrected <- sweep (fauxCell, 2, background, "-") ##' plot (corrected, "spcprctl5") ##' ##' ## Offset correction -##' offsets <- apply (chondro, 1, min) -##' corrected <- sweep (chondro, 1, offsets, "-") +##' offsets <- apply (fauxCell, 1, min) +##' corrected <- sweep (fauxCell, 1, offsets, "-") ##' plot (corrected, "spcprctl5") ##' ##' ## Min-max normalization (on max amide I) From 457d9e5670653d2caadcf51af06941da9eb36c2c Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 08:16:22 -0500 Subject: [PATCH 41/55] Replace `chondro` with `fauxCell` in trellis.factory.key.R --- hyperSpec/R/trellis.factor.key.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hyperSpec/R/trellis.factor.key.R b/hyperSpec/R/trellis.factor.key.R index 9795ef54a..573b8d705 100644 --- a/hyperSpec/R/trellis.factor.key.R +++ b/hyperSpec/R/trellis.factor.key.R @@ -16,20 +16,20 @@ ##' @importFrom lattice level.colors ##' @examples ##' -##' chondro$z <- factor (rep (c("a", "a", "d", "c"), -##' length.out = nrow (chondro)), +##' fauxCell$z <- factor (rep (c("a", "a", "d", "c"), +##' length.out = nrow (fauxCell)), ##' levels = letters [1 : 4]) ##' -##' str (trellis.factor.key (chondro$z)) +##' str (trellis.factor.key (fauxCell$z)) ##' -##' plotmap (chondro, z ~ x * y) +##' plotmap (fauxCell, z ~ x * y) ##' ##' ## switch off using trellis.factor.key: ##' ## note that the factor levels are collapsed to c(1, 2, 3) rather than ##' ## c (1, 3, 4) -##' plotmap (chondro, z ~ x * y, transform.factor = FALSE) +##' plotmap (fauxCell, z ~ x * y, transform.factor = FALSE) ##' -##' plotmap (chondro, z ~ x * y, +##' plotmap (fauxCell, z ~ x * y, ##' col.regions = c ("gray", "red", "blue", "dark green")) ##' ##' @importFrom utils modifyList From 38fe4bb507afe24cc15bd8bbedc53923b96e20ae Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 08:20:25 -0500 Subject: [PATCH 42/55] Replace `chondro` with `fauxCell` in wl.R --- hyperSpec/R/wl.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hyperSpec/R/wl.R b/hyperSpec/R/wl.R index 8d4c9ae6a..7b6fc026e 100644 --- a/hyperSpec/R/wl.R +++ b/hyperSpec/R/wl.R @@ -73,9 +73,9 @@ wl <- function(x) { ##' ##' # convert from Raman shift to wavelength ##' # excitation was at 785 nm -##' plot (chondro [1]) -##' wl (chondro) <- list (wl = 1e7 / (1e7/785 - wl (chondro)), label = expression (lambda / nm)) -##' plot (chondro [1]) +##' plot (fauxCell [1]) +##' wl (fauxCell) <- list (wl = 1e7 / (1e7/785 - wl (fauxCell)), label = expression (lambda / nm)) +##' plot (fauxCell [1]) ##' "wl<-" <- function(x, label = NULL, digits = 6, value) { chk.hy(x) From bd5a0d81476e284cc92c33ad498a1bc830402dc2 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 08:25:25 -0500 Subject: [PATCH 43/55] Replace `chondro` with `fauxCell` in wl2i.R --- hyperSpec/R/wl2i.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperSpec/R/wl2i.R b/hyperSpec/R/wl2i.R index 1017bca5d..119ec6661 100644 --- a/hyperSpec/R/wl2i.R +++ b/hyperSpec/R/wl2i.R @@ -233,7 +233,7 @@ wl2i <- function(x, wavelength = stop("wavelengths are required."), unlist = TRU ##' @export ##' @examples ##' -##' i2wl (chondro, 17:20) +##' i2wl (fauxCell, 17:20) ##' i2wl <- function(x, i) { chk.hy(x) From b1429d90c30112d8d5fb9bf78870dc4574a541ad Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 08:37:04 -0500 Subject: [PATCH 44/55] Update spc.fit.poly.R --- hyperSpec/R/spc.fit.poly.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hyperSpec/R/spc.fit.poly.R b/hyperSpec/R/spc.fit.poly.R index 095881e87..ca33563e9 100644 --- a/hyperSpec/R/spc.fit.poly.R +++ b/hyperSpec/R/spc.fit.poly.R @@ -287,10 +287,11 @@ spc.fit.poly.below <- function(fit.to, apply.to = fit.to, poly.order = 1, expect_equal(bl.nonorm [[]], bl.1e4 [[]]) }) - # test_that("requesting 2 support points working - issue #58", { - # expect_warning(spc.fit.poly.below(fauxCell[103], npts.min = 2), "Stopped after") - # expect_warning(spc.fit.poly.below(fauxCell[103], npts.min = 2, stop.on.increase = TRUE), "about to increase again") - # }) + test_that("requesting 2 support points working - issue #58", { + skip("fauxCell does not produce any warnings") + expect_warning(spc.fit.poly.below(fauxCell[103], npts.min = 2), "Stopped after") + expect_warning(spc.fit.poly.below(fauxCell[103], npts.min = 2, stop.on.increase = TRUE), "about to increase again") + }) test_that("spectrum containing NA", { tmp <- fauxCell [1] From f0f5c0f6770d1040382b1521df7009098cf93d1b Mon Sep 17 00:00:00 2001 From: Claudia Beleites Date: Tue, 9 Jun 2020 16:11:50 +0200 Subject: [PATCH 45/55] example data set to check treatment of unstable solutions in spc.fit.poly.below() without the need for chondro. --- hyperSpec/R/spc.fit.poly.R | 43 ++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/hyperSpec/R/spc.fit.poly.R b/hyperSpec/R/spc.fit.poly.R index ca33563e9..1c7f043fe 100644 --- a/hyperSpec/R/spc.fit.poly.R +++ b/hyperSpec/R/spc.fit.poly.R @@ -269,9 +269,10 @@ spc.fit.poly.below <- function(fit.to, apply.to = fit.to, poly.order = 1, context("spc.fit.poly.below") test_that( - "no normalization", - bl.nonorm <- spc.fit.poly.below(flu, flu, poly.order = 3, offset.wl = FALSE, npts.min = 25) - ) + "no normalization", { + bl.nonorm <- spc.fit.poly.below(flu, flu, poly.order = 3, offset.wl = FALSE, + npts.min = 25) + }) # test effect of wavelength axis normalization # was issue 1 on github @@ -279,18 +280,38 @@ spc.fit.poly.below <- function(fit.to, apply.to = fit.to, poly.order = 1, wl(tmp) <- wl(tmp) + 1e4 test_that("normalization/offset wavelengths", { - expect_error(spc.fit.poly.below(tmp, poly.order = 3, offset.wl = FALSE, npts.min = 25)) + expect_error(spc.fit.poly.below(tmp, poly.order = 3, offset.wl = FALSE, + npts.min = 25)) - bl.1e4 <- spc.fit.poly.below(tmp, tmp, poly.order = 3, offset.wl = TRUE, npts.min = 25) - bl.nonorm <- spc.fit.poly.below(flu, flu, poly.order = 3, offset.wl = FALSE, npts.min = 25) + bl.1e4 <- spc.fit.poly.below(tmp, tmp, poly.order = 3, offset.wl = TRUE, + npts.min = 25) - expect_equal(bl.nonorm [[]], bl.1e4 [[]]) + bl.nonorm <- spc.fit.poly.below(flu, flu, poly.order = 3, offset.wl = FALSE, + npts.min = 25) + + expect_equal(bl.nonorm[[]], bl.1e4[[]]) }) - test_that("requesting 2 support points working - issue #58", { - skip("fauxCell does not produce any warnings") - expect_warning(spc.fit.poly.below(fauxCell[103], npts.min = 2), "Stopped after") - expect_warning(spc.fit.poly.below(fauxCell[103], npts.min = 2, stop.on.increase = TRUE), "about to increase again") + test_that("stoppng rules for unstable solutions - issue #58", { + # test object origninally created from chondro: + # tmp <- chondro [103,,c(600 ~ 700, 1650 ~ 1800)] + # tmp[[]] <- round(tmp[[]], digits = 1) + + tmp <- t(c(331.8, 336.7, 325.3, 313.2, 328.6, 348.5, 304.6, 286.8, 283.9, + 294.2, 323.3, 312.2, 298.8, 299.8, 299.7, 301.8, 305.2, 308.4, + 311.2, 318.2, 321, 322.1, 323, 336.7, 362.1, 776.9, 835.3, 902, + 967, 1019.3, 1020.5, 942.3, 848.8, 774.8, 701.1, 612.1, 514.4, + 420.8, 340.1, 282.5, 242.7, 220, 206, 196.8, 192.1, 189.1, 185.3, + 184, 181.8, 178.7, 178.8, 174.8, 175.6, 173.2, 174.3, 173.1, + 173.2, 171.4, 171.5, 171.9, 171.3, 171.1, 171.8)) + tmp <- as.hyperSpec(tmp) + wl(tmp) <- c(seq(602, 698, by = 4), seq(1650, 1798, by = 4)) + + expect_warning(spc.fit.poly.below(tmp, npts.min = 2), + "Reached npts.min, but the solution is not stable.") + expect_warning(spc.fit.poly.below(tmp, npts.min = 2, + stop.on.increase = TRUE), + "Number of support points is about to increase again.") }) test_that("spectrum containing NA", { From acda6784ac3bd760dab336a9aaf92d5c9a67e4eb Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 09:18:47 -0500 Subject: [PATCH 46/55] Update DESCRIPTION --- hyperSpec/DESCRIPTION | 5 ----- 1 file changed, 5 deletions(-) diff --git a/hyperSpec/DESCRIPTION b/hyperSpec/DESCRIPTION index 00fbf1998..4b3e3e2a9 100644 --- a/hyperSpec/DESCRIPTION +++ b/hyperSpec/DESCRIPTION @@ -3,13 +3,8 @@ Encoding: UTF-8 Type: Package Title: Work with Hyperspectral Data, i.e. Spectra + Meta Information (Spatial, Time, Concentration, ...) -<<<<<<< HEAD -Version: 0.99-20200522 -Date: 2020-06-09 -======= Version: 0.99-20200608 Date: 2020-06-08 ->>>>>>> develop Maintainer: Claudia Beleites Authors@R: c( person("Claudia", "Beleites", role = c("aut","cre", "dtc"), email = "Claudia.Beleites@chemometrix.gmbh"), From 294c23d15d7d1492ec830ac5ff1edb1560f043f1 Mon Sep 17 00:00:00 2001 From: Claudia Beleites Date: Tue, 9 Jun 2020 16:45:34 +0200 Subject: [PATCH 47/55] styling --- hyperSpec/R/spc.fit.poly.R | 133 ++++++++++++++++++++++--------------- 1 file changed, 81 insertions(+), 52 deletions(-) diff --git a/hyperSpec/R/spc.fit.poly.R b/hyperSpec/R/spc.fit.poly.R index 1c7f043fe..2918bc7dc 100644 --- a/hyperSpec/R/spc.fit.poly.R +++ b/hyperSpec/R/spc.fit.poly.R @@ -30,11 +30,12 @@ ##' ##' \dontrun{vignette ("baseline", package = "hyperSpec")} ##' -##' spc <- fauxCell [1 : 10] -##' baselines <- spc.fit.poly(spc [,, c (625 ~ 640, 1785 ~ 1800)], spc) +##' spc <- fauxCell[1 : 10] +##' baselines <- spc.fit.poly(spc[,, c (625 ~ 640, 1785 ~ 1800)], spc) ##' plot(spc - baselines) ##' -spc.fit.poly <- function(fit.to, apply.to = NULL, poly.order = 1, offset.wl = !(is.null(apply.to))) { +spc.fit.poly <- function(fit.to, apply.to = NULL, poly.order = 1, + offset.wl = !(is.null(apply.to))) { chk.hy(fit.to) if (!is.null(apply.to)) { chk.hy(apply.to) @@ -57,8 +58,8 @@ spc.fit.poly <- function(fit.to, apply.to = NULL, poly.order = 1, offset.wl = !( p <- apply( fit.to, 1, function(y, x) { - x <- x [!is.na(y), , drop = FALSE] - y <- y [!is.na(y)] + x <- x[!is.na(y), , drop = FALSE] + y <- y[!is.na(y)] qr.solve(x, y) }, x @@ -87,9 +88,9 @@ spc.fit.poly <- function(fit.to, apply.to = NULL, poly.order = 1, offset.wl = !( context("spc.fit.poly") test_that( - "no normalization", + "no normalization", { bl.nonorm <- spc.fit.poly(flu, flu, poly.order = 3, offset.wl = FALSE) - ) + }) # test effect of wavelength axis normalization # was issue 1 on github @@ -101,17 +102,17 @@ spc.fit.poly <- function(fit.to, apply.to = NULL, poly.order = 1, offset.wl = !( bl.1e4 <- spc.fit.poly(tmp, tmp, poly.order = 3, offset.wl = TRUE) bl.nonorm <- spc.fit.poly(flu, flu, poly.order = 3, offset.wl = FALSE) - expect_equal(bl.nonorm [[]], bl.1e4 [[]]) + expect_equal(bl.nonorm[[]], bl.1e4[[]]) }) test_that("spectrum containing NA", { - tmp <- fauxCell [1] - tmp [[, , 1600]] <- NA + tmp <- fauxCell[1] + tmp[[, , 1600]] <- NA - coefs <- spc.fit.poly(tmp, apply.to = NULL) [[]] + coefs <- spc.fit.poly(tmp, apply.to = NULL)[[]] expect_equal( coefs, - spc.fit.poly(fauxCell [1, , !is.na(tmp)], apply.to = NULL) [[]] + spc.fit.poly(fauxCell[1, , !is.na(tmp)], apply.to = NULL)[[]] ) ## bug was: all coefficients were silently 0 @@ -121,20 +122,20 @@ spc.fit.poly <- function(fit.to, apply.to = NULL, poly.order = 1, offset.wl = !( ##' ##' \code{spc.fit.poly.below} tries to fit the baseline on appropriate spectral -##' ranges of the spectra in \code{fit.to}. For details, see the -##' \code{vignette ("baseline")}. +##' ranges of the spectra in \code{fit.to}. For details, see the \code{vignette +##' ("baseline")}. ##' @rdname baselines ##' @param npts.min minimal number of points used for fitting the polynomial -##' @param noise noise level to be considered during the fit. It may be given -##' as one value for all the spectra, or for each spectrum separately. +##' @param noise noise level to be considered during the fit. It may be given as +##' one value for all the spectra, or for each spectrum separately. ##' @param max.iter stop at the latest after so many iterations. -##' @param stop.on.increase additional stopping rule: stop if the number of support points would increase, -##' regardless whether npts.min was reached or not. -##' @param debuglevel additional output: -##' \code{1} shows \code{npts.min}, -##' \code{2} plots support points for the final baseline of 1st spectrum, -##' \code{3} plots support points for 1st spectrum, -##' \code{4} plots support points for all spectra. +##' @param stop.on.increase additional stopping rule: stop if the number of +##' support points would increase, regardless whether npts.min was reached or +##' not. +##' @param debuglevel additional output: \code{1} shows \code{npts.min}, +##' \code{2} plots support points for the final baseline of 1st spectrum, +##' \code{3} plots support points for 1st spectrum, \code{4} plots support +##' points for all spectra. ##' @seealso see \code{\link[hyperSpec]{options}} for more on \code{debuglevel} ##' @export ##' @examples @@ -142,13 +143,16 @@ spc.fit.poly <- function(fit.to, apply.to = NULL, poly.order = 1, offset.wl = !( ##' baselines <- spc.fit.poly.below (spc) ##' plot (spc - baselines) ##' -##' spc.fit.poly.below(fauxCell [1:3], debuglevel = 1) -##' spc.fit.poly.below(fauxCell [1:3], debuglevel = 2) -##' spc.fit.poly.below(fauxCell [1:3], debuglevel = 3, noise = sqrt (rowMeans (fauxCell [[1:3]]))) +##' spc.fit.poly.below(fauxCell[1:3], debuglevel = 1) +##' spc.fit.poly.below(fauxCell[1:3], debuglevel = 2) +##' spc.fit.poly.below(fauxCell[1:3], debuglevel = 3, +##' noise = sqrt (rowMeans (fauxCell[[1:3]]))) ##' spc.fit.poly.below <- function(fit.to, apply.to = fit.to, poly.order = 1, - npts.min = max(round(nwl(fit.to) * 0.05), 3 * (poly.order + 1)), - noise = 0, offset.wl = FALSE, max.iter = nwl(fit.to), + npts.min = max(round(nwl(fit.to) * 0.05), + 3 * (poly.order + 1)), + noise = 0, offset.wl = FALSE, + max.iter = nwl(fit.to), stop.on.increase = FALSE, debuglevel = hy.getOption("debuglevel")) { ## for debuglevel >= 2L @@ -185,63 +189,88 @@ spc.fit.poly.below <- function(fit.to, apply.to = fit.to, poly.order = 1, } vdm <- vanderMonde(x, poly.order) - y <- t(fit.to [[]]) + y <- t(fit.to[[]]) p <- matrix(nrow = nrow(fit.to), ncol = poly.order + 1) for (i in row.seq(fit.to)) { use.old <- logical(nwl(fit.to)) - use <- !is.na(y [, i]) + use <- !is.na(y[, i]) if (debuglevel %in% c(2L, 3L) && i == 1L || debuglevel >= 4L) { - plot(fit.to [i], title.args = list(main = paste("spectrum", i))) + plot(fit.to[i], title.args = list(main = paste("spectrum", i))) message("start: ", sum(use, na.rm = TRUE), " support points") } for (iter in 1:max.iter) { p[i, ] <- qr.solve(vdm[use, ], y[use, i]) - bl <- vdm %*% p [i, ] + bl <- vdm %*% p[i, ] use.old <- use - use <- y[, i] < bl + noise [i] & !is.na(y [, i]) + use <- y[, i] < bl + noise[i] & !is.na(y[, i]) if (debuglevel == 3L && i == 1L || debuglevel >= 4L) { - plot(fit.to[i, , use], add = TRUE, lines.args = list(pch = 20, type = "p"), col = cols [iter]) - lines(fit.to@wavelength, bl, col = cols [iter]) - lines(fit.to@wavelength, bl + noise, col = cols [iter], lty = 2) - message("Iteration ", iter, ": ", sum(use, na.rm = TRUE), " support points") + + plot(fit.to[i, , use], add = TRUE, + lines.args = list(pch = 20, type = "p"), col = cols[iter]) + + lines(fit.to@wavelength, bl, col = cols[iter]) + lines(fit.to@wavelength, bl + noise, col = cols[iter], lty = 2) + + message("Iteration ", iter, ": ", sum(use, na.rm = TRUE), + " support points") } - if ((sum(use, na.rm = TRUE) < npts.min) || all(use == use.old, na.rm = TRUE)) { + if ((sum(use, na.rm = TRUE) < npts.min) || + all(use == use.old, na.rm = TRUE)) { + break } - if (sum(use, na.rm = TRUE) > sum(use.old, na.rm = TRUE) && stop.on.increase) { + if (sum(use, na.rm = TRUE) > sum(use.old, na.rm = TRUE) && + stop.on.increase) { + warning( - "Iteration ", iter, ": Number of support points is about to increase again. Stopping with ", - sum(use.old, na.rm = TRUE), " support points, but this is a local minimum only." + "Iteration ", iter,": ", + "Number of support points is about to increase again. ", + "Stopping with ", sum(use.old, na.rm = TRUE), + " support points, but this may be a local minimum." ) + break } } if (iter == max.iter) { + if ((sum(use.old, na.rm = TRUE) == npts.min) && !all(use == use.old, na.rm = TRUE) && !sum(use, na.rm = TRUE) < npts.min) { - warning("Reached npts.min, but the solution is not stable. Stopped after ", iter, " iterations.") + + warning("Reached npts.min, but the solution is not stable. ", + "Stopped after ", iter, " iterations.") + } else if (sum(use, na.rm = TRUE) >= npts.min) { - warning("Stopped after ", iter, " iterations with ", sum(use.old, na.rm = TRUE), " support points.") + + warning("Stopped after ", iter, " iterations with ", + sum(use.old, na.rm = TRUE), " support points.") } + } if (debuglevel >= 1L) { - message(sprintf("spectrum % 6i: % 5i support points, noise = %0.1f, %3i iterations", i, sum(use.old, na.rm = TRUE), noise [i], iter)) + message(sprintf("spectrum % 6i: % 5i support points, noise = %0.1f, %3i iterations", + i, sum(use.old, na.rm = TRUE), noise[i], iter)) } + if ((debuglevel == 2L) && (i == 1L)) { - plot(fit.to[i, , use.old], add = TRUE, lines.args = list(pch = 20, type = "p"), col = cols [iter]) - lines(fit.to@wavelength, bl, col = cols [iter]) - lines(fit.to@wavelength, bl + noise, col = cols [iter], lty = 2) + plot(fit.to[i, , use.old], add = TRUE, + lines.args = list(pch = 20, type = "p"), col = cols[iter]) + + lines(fit.to@wavelength, bl, col = cols[iter]) + + lines(fit.to@wavelength, bl + noise, col = cols[iter], lty = 2) } } + if (is.null(apply.to)) { fit.to <- new("hyperSpec", spc = p, wavelength = 0:poly.order) colnames(fit.to@data$spc) <- paste0("(x - minx)^", 0:poly.order) @@ -294,7 +323,7 @@ spc.fit.poly.below <- function(fit.to, apply.to = fit.to, poly.order = 1, test_that("stoppng rules for unstable solutions - issue #58", { # test object origninally created from chondro: - # tmp <- chondro [103,,c(600 ~ 700, 1650 ~ 1800)] + # tmp <- chondro[103,,c(600 ~ 700, 1650 ~ 1800)] # tmp[[]] <- round(tmp[[]], digits = 1) tmp <- t(c(331.8, 336.7, 325.3, 313.2, 328.6, 348.5, 304.6, 286.8, 283.9, @@ -315,13 +344,13 @@ spc.fit.poly.below <- function(fit.to, apply.to = fit.to, poly.order = 1, }) test_that("spectrum containing NA", { - tmp <- fauxCell [1] - tmp [[, , 1600]] <- NA + tmp <- fauxCell[1] + tmp[[, , 1600]] <- NA - coefs <- spc.fit.poly.below(tmp, apply.to = NULL) [[]] + coefs <- spc.fit.poly.below(tmp, apply.to = NULL)[[]] expect_equal( coefs, - spc.fit.poly.below(fauxCell [1, , !is.na(tmp)], apply.to = NULL) [[]] + spc.fit.poly.below(fauxCell[1, , !is.na(tmp)], apply.to = NULL)[[]] ) ## bug was: all coefficients were silently 0 From 4ba2384605f4589781bcfe25faf8d40bb72ebd16 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Tue, 9 Jun 2020 09:53:01 -0500 Subject: [PATCH 48/55] Remove update.dataset.R --- hyperSpec/DESCRIPTION | 3 +- hyperSpec/R/update.dataset.R | 231 ----------------------------------- 2 files changed, 1 insertion(+), 233 deletions(-) delete mode 100644 hyperSpec/R/update.dataset.R diff --git a/hyperSpec/DESCRIPTION b/hyperSpec/DESCRIPTION index 4b3e3e2a9..6f9eb0ef2 100644 --- a/hyperSpec/DESCRIPTION +++ b/hyperSpec/DESCRIPTION @@ -4,7 +4,7 @@ Type: Package Title: Work with Hyperspectral Data, i.e. Spectra + Meta Information (Spatial, Time, Concentration, ...) Version: 0.99-20200608 -Date: 2020-06-08 +Date: 2020-06-09 Maintainer: Claudia Beleites Authors@R: c( person("Claudia", "Beleites", role = c("aut","cre", "dtc"), email = "Claudia.Beleites@chemometrix.gmbh"), @@ -175,7 +175,6 @@ Collate: 'sweep.R' 'trellis.factor.key.R' 'units.R' - 'update.dataset.R' 'vandermonde.R' 'wc.R' 'wl.R' diff --git a/hyperSpec/R/update.dataset.R b/hyperSpec/R/update.dataset.R deleted file mode 100644 index d5d930cb0..000000000 --- a/hyperSpec/R/update.dataset.R +++ /dev/null @@ -1,231 +0,0 @@ -##' Update data sets for hyperSpec package -##' -##' -##' @return directory of edited R files and associated test logs -##' -##' @author Erick Oduniyi -##' -##' @keywords programming utilities -##' @examples -##' @export -# TODO: consider deleting .txt files every time this function is ran -# TODO: add option to switch between verbose console output -# TODO: Check if the file even has examples -# path_to_files <- "/Users/erickoduniyi/Desktop/hyperSpec/hyperSpec/hyperSpec/hyperSpec/R" -# path_to_store <- "~/Desktop/R-edits/" -update.examples <- function(old_ds, new_ds, path_to_files, path_to_store) { - - # Check the difference between the two datasets - old_ds_name <- deparse(substitute(old_ds)) - new_ds_name <- deparse(substitute(new_ds)) - ds_info <- check_ds(old_ds, new_ds, old_ds_name, new_ds_name) - - # Create directories where the files need to be saved - file_info <- create_edits_dir(path_to_files, path_to_store, old_ds_name) - - # Edit .R files - message("Would you like to edit .R files now?") - choice <- select.list(c("Yes", "No")) - if (choice == "Yes") { - make_edits_R(ds_info, file_info) - } - - # Check test for updated file - message("Would you like to check test now?") - choice <- select.list(c("Yes", "No")) - if (choice == "Yes") { - check_test_in_file(file_info) - } - - # Check updated file examples - message("Would you like to check examples now?") - choice <- select.list(c("Yes", "No")) - if (choice == "Yes") { - check_examples(file_info) - } - - # Check updated file vignettes - message("Would you like to check vignettes now?") - choice <- select.list(c("Yes", "No")) - if (choice == "Yes") { - check_vingette(file_info) - } - - # Let the user know user.examples has completed - message("update.examples.R has completed!!!") -} -# Helper(s) ----------------------------------------------- - -check_ds <- function(old_ds, new_ds, old_ds_name, new_ds_name) { - - # Check data sets - message(paste("Checking differences between", old_ds_name, "and", new_ds_name)) - - # Handle potential differences between datasets - if (!setequal(colnames(old_ds), colnames(new_ds))) { - col_diff_old <- setdiff(colnames(old_ds), colnames(new_ds)) - col_diff_new <- setdiff(colnames(new_ds), colnames(old_ds)) - ls_old_names <- paste(sort(col_diff_old), collapse = ", ") - - # Let user know about the difference between datasets - message(paste(c("The following columns appear in", old_ds_name, "but not", paste0(new_ds_name, ":"), ls_old_names), collapse= " ")) - - # Give the user options about substituting columns between datasets - message(paste("Which column in", old_ds_name, "do you want to substitute?:")) - sub_old <- select.list(sort(col_diff_old)) - if (sub_old != "") { - message(paste("Substitute", sub_old, "for which column in", paste0(new_ds_name, "?:"))) - for_new <-select.list(sort(col_diff_new)) - } - } - - # Prepare information about data sets to be passed on to subsequent functions - ds_info <- list(ds_names = c(old_ds_name, new_ds_name), sub_vals = c(sub_old, for_new)) -} - -create_edits_dir <- function(path_to_files, path_to_store, old_ds_name) { - - # Set the location of the .R files that need to be updated: - setwd(path_to_files) - - # Create a directories where the files need to be saved - loc_2_be_saved <- path_to_store - dir.create(loc_2_be_saved, showWarnings = FALSE) - dir.create(paste0(loc_2_be_saved, "test-results"), showWarnings = FALSE) - dir.create(paste0(loc_2_be_saved, "example-results"), showWarnings = FALSE) - dir.create(paste0(loc_2_be_saved, "vignette-results"), showWarnings = FALSE) - - # Get all the .R files in the current directory - R_files <- list.files() - - # Get files - files2get <- vector() - - for (i in seq_along(R_files)) { - - # Read in the file - source_code <- readLines(R_files[i]) - - # Check if file references the old data set - if (identical(grep(old_ds_name, source_code, value = TRUE), character(0))) { - - # Skip this file - message(paste(R_files[i],"does not contain", old_ds_name, "data set...")) - - } else { - - # "Just throw it in the bag" - Fabolous ft. The-Dream - files2get <- c(files2get, R_files[i]) - } - } - - cat("-----------------------------------------------------------------------------------------","\n") - # Prepare information about files - # Collect subset of filenames - R_files <- files2get - file_info <- list(file_loc = loc_2_be_saved, R_files = R_files) -} - -make_edits_R <- function(ds_info, file_info) { - - # Setup - loc_2_be_saved <- file_info$file_loc - filenames <- file_info$R_files - old_ds_name <- ds_info$ds_names[1] - new_ds_name <- ds_info$ds_names[2] - sub_old <- ds_info$sub_vals[1] - for_new <- ds_info$sub_vals[2] - - # Edit - message("== Making edits =========================================================================") - - # Edit each file - for (i in seq_along(filenames)) { - - # Read in the file - cat(paste0("**Reading in file: ", filenames[i]), "\n") - source_code <- readLines(filenames[i]) - - # Prepare substitute pattern for specific case - old <- paste0(old_ds_name,"\\$", sub_old) - new <- paste0(new_ds_name,"$", for_new) - - # Specific case - cat(paste("Replacing occurences of", old, "with", new), "\n") - code_edited <- gsub(old, new, source_code) - - # Generic case - cat(paste("Replacing occurences of", old_ds_name, "with", new_ds_name), "\n") - code_edited <- gsub(old_ds_name, new_ds_name, code_edited) - - # Output updated file - cat(paste("Updating", filenames[i]), "\n") - writeLines(code_edited, paste0(loc_2_be_saved, filenames[i])) - - # Move to the next file - cat(paste0("**Done editing: ", filenames[i]), "\n") - } - - # Tell user - message("Done editing all files!!..") - cat("-----------------------------------------------------------------------------------------","\n") -} - -check_test_in_file <- function(file_info) { - - # Setup - loc_2_be_saved <- file_info$file_loc - filenames <- file_info$R_files - - # Check test - message("== Checking unittest ====================================================================") - - # Check test of each file - for (i in seq_along(filenames)) { - - # Run test in file and output the results to a text file - test_res_here <- paste0(loc_2_be_saved, "test-results/", gsub(".R", ".txt", filenames[i])) - verify_output(test_res_here, with_reporter(reporter = SummaryReporter$new(), start_end_reporter = TRUE, get.test(.aggregate)())) - cat(paste0("**Logging results to...", gsub(".R", ".txt", filenames[i])), "\n") - } - - # Tell user - message("Done checking all test!!..") - cat("-----------------------------------------------------------------------------------------","\n") -} - -check_examples <- function(file_info) { - - # Setup - filenames <- file_info$R_files - - # Check examples - message("== Checking examples ====================================================================") - - # Check examples in each file - for (i in seq_along(filenames)) { - - cat(paste0("**Logging results to...", gsub(".R", ".Rd", filename)), "\n") - - # Move to the next file - message(paste0("Done checking examples for: ", filenames[i])) - } - - # Tell user - message("Done checking all examples!...") - cat("-----------------------------------------------------------------------------------------","\n") -} - -check_vingette <- function(file_info) { - - # Setup - filenames <- file_info$R_files - - # Check vignette - message("== Checking vignettes ===================================================================") - cat(paste0("**Logging results to...", gsub(".R", ".txt", filename)), "\n") - - # Tell user - message("Done checking vignettes!!..") - cat("-----------------------------------------------------------------------------------------","\n") -} \ No newline at end of file From 885667c8addc37d517e0307b7ed1633b2cce9363 Mon Sep 17 00:00:00 2001 From: Claudia Beleites Date: Tue, 9 Jun 2020 16:57:20 +0200 Subject: [PATCH 49/55] translate documentation to markdown --- hyperSpec/R/spc.fit.poly.R | 39 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/hyperSpec/R/spc.fit.poly.R b/hyperSpec/R/spc.fit.poly.R index 2918bc7dc..21ec6101e 100644 --- a/hyperSpec/R/spc.fit.poly.R +++ b/hyperSpec/R/spc.fit.poly.R @@ -1,29 +1,30 @@ ##' Polynomial Baseline Fitting ##' These functions fit polynomal baselines. ##' -##' Both functions fit polynomials to be used as baselines. If \code{apply.to} -##' is \code{NULL}, a \code{hyperSpec} object with the polynomial coefficients +##' Both functions fit polynomials to be used as baselines. If `apply.to` +##' is `NULL`, a hyperSpec object with the polynomial coefficients ##' is returned, otherwise the polynomials are evaluated on the spectral range -##' of \code{apply.to}. +##' of `apply.to`. ##' -##' \code{spc.fit.poly} calculates the least squares fit of order -##' \code{poly.order} to the \emph{complete} spectra given in \code{fit.to}. -##' Thus \code{fit.to} needs to be cut appropriately. +##' `spc.fit.poly()` calculates the least squares fit of order +##' `poly.order` to the *complete* spectra given in `fit.to`. +##' Thus `fit.to` needs to be cut appropriately. ##' ##' @rdname baselines ##' @concept baseline -##' @param fit.to \code{hyperSpec} object on which the baselines are fitted -##' @param apply.to \code{hyperSpec} object on which the baselines are evaluted -##' If \code{NULL}, a \code{hyperSpec} object containing the polynomial +##' @param fit.to hyperSpec object on which the baselines are fitted +##' @param apply.to hyperSpec object on which the baselines are evaluted +##' If `NULL`, a hyperSpec object containing the polynomial ##' coefficients rather than evaluted baselines is returned. ##' @param poly.order order of the polynomial to be used ##' @param offset.wl should the wavelength range be mapped to -> [0, delta wl]? ##' This enhances numerical stability. -##' @return \code{hyperspec} object containing the baselines in the spectra +##' @return hyperSpec object containing the baselines in the spectra ##' matrix, either as polynomial coefficients or as polynomials evaluted on -##' the spectral range of \code{apply.to} +##' the spectral range of `apply.to` ##' @author C. Beleites -##' @seealso \code{vignette ("baseline", package = "hyperSpec")} +##' @md +##' @seealso `vignette ("baseline", package = "hyperSpec")` ##' @keywords manip datagen ##' @export ##' @examples @@ -121,9 +122,9 @@ spc.fit.poly <- function(fit.to, apply.to = NULL, poly.order = 1, } ##' -##' \code{spc.fit.poly.below} tries to fit the baseline on appropriate spectral -##' ranges of the spectra in \code{fit.to}. For details, see the \code{vignette -##' ("baseline")}. +##' `spc.fit.poly.below()` tries to fit the baseline on appropriate spectral +##' ranges of the spectra in `fit.to`. For details, see the `vignette +##' ("baseline")`. ##' @rdname baselines ##' @param npts.min minimal number of points used for fitting the polynomial ##' @param noise noise level to be considered during the fit. It may be given as @@ -132,11 +133,11 @@ spc.fit.poly <- function(fit.to, apply.to = NULL, poly.order = 1, ##' @param stop.on.increase additional stopping rule: stop if the number of ##' support points would increase, regardless whether npts.min was reached or ##' not. -##' @param debuglevel additional output: \code{1} shows \code{npts.min}, -##' \code{2} plots support points for the final baseline of 1st spectrum, -##' \code{3} plots support points for 1st spectrum, \code{4} plots support +##' @param debuglevel additional output: `1` shows `npts.min`, +##' `2` plots support points for the final baseline of 1st spectrum, +##' `3` plots support points for 1st spectrum, `4` plots support ##' points for all spectra. -##' @seealso see \code{\link[hyperSpec]{options}} for more on \code{debuglevel} +##' @seealso see [hyperSpec::options()] for more on `debuglevel` ##' @export ##' @examples ##' From a49f1e26e14303b98be4f3943fd9900939f0c85b Mon Sep 17 00:00:00 2001 From: Claudia Beleites Date: Tue, 9 Jun 2020 17:20:41 +0200 Subject: [PATCH 50/55] buxfix: use of labels() instead of @label avoids error on empty label --- hyperSpec/R/mergeextra.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hyperSpec/R/mergeextra.R b/hyperSpec/R/mergeextra.R index 2a2739c81..c12430000 100644 --- a/hyperSpec/R/mergeextra.R +++ b/hyperSpec/R/mergeextra.R @@ -43,10 +43,10 @@ mergeextra <- function(x, y) { if ((is.null(ylabels[[colname]]) | # no label or as.character(ylabels[[colname]]) == colname | # default label or - as.character(ylabels[[colname]]) == as.character(x@label[[colname]])) & # same label + as.character(ylabels[[colname]]) == as.character(labels(x, colname))) & # AND - identical(y[[col]], x@data[[colname]]) # content identical + identical(y[[col]], x@data[[colname]]) # content identical ) { y[[col]] <- NULL @@ -150,4 +150,10 @@ mergeextra <- function(x, y) { .sortbyname(c(labels(flu), list(c.y = expression(c / mg * l))))) }) + test_that("x missing labels", { + spc <- fauxCell[1:3] + spc@label$region <- NULL + spc - spc + }) + } From 1e54e188eee84832e63e3a4ad509dd73b8cab302 Mon Sep 17 00:00:00 2001 From: Claudia Beleites Date: Tue, 9 Jun 2020 17:28:51 +0200 Subject: [PATCH 51/55] fix LaTeX -> markdown translation error --- hyperSpec/R/spc.fit.poly.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperSpec/R/spc.fit.poly.R b/hyperSpec/R/spc.fit.poly.R index 21ec6101e..05cd4bf96 100644 --- a/hyperSpec/R/spc.fit.poly.R +++ b/hyperSpec/R/spc.fit.poly.R @@ -17,7 +17,7 @@ ##' If `NULL`, a hyperSpec object containing the polynomial ##' coefficients rather than evaluted baselines is returned. ##' @param poly.order order of the polynomial to be used -##' @param offset.wl should the wavelength range be mapped to -> [0, delta wl]? +##' @param offset.wl should the wavelength range be mapped to -> \[0, delta wl\]? ##' This enhances numerical stability. ##' @return hyperSpec object containing the baselines in the spectra ##' matrix, either as polynomial coefficients or as polynomials evaluted on From 0e6ff2ccb4690cd74eb6c32bcef754bae72188bb Mon Sep 17 00:00:00 2001 From: Claudia Beleites Date: Tue, 9 Jun 2020 17:43:05 +0200 Subject: [PATCH 52/55] change one last occurence of chondro -> fauxCell --- hyperSpec/R/quantile.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperSpec/R/quantile.R b/hyperSpec/R/quantile.R index fe9225066..86bb58a37 100644 --- a/hyperSpec/R/quantile.R +++ b/hyperSpec/R/quantile.R @@ -31,5 +31,5 @@ ##' @export ##' @examples ##' -##' plot (quantile (chondro)) +##' plot (quantile (fauxCell)) setMethod("quantile", signature = signature(x = "hyperSpec"), .quantile) From 8440c6bb1c6e15f0d243472fdbd339d0111207f5 Mon Sep 17 00:00:00 2001 From: Erick Oduniyi Date: Mon, 15 Jun 2020 12:07:05 -0500 Subject: [PATCH 53/55] Update DESCRIPTION --- hyperSpec/DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperSpec/DESCRIPTION b/hyperSpec/DESCRIPTION index 6f9eb0ef2..1ff6648de 100644 --- a/hyperSpec/DESCRIPTION +++ b/hyperSpec/DESCRIPTION @@ -4,7 +4,7 @@ Type: Package Title: Work with Hyperspectral Data, i.e. Spectra + Meta Information (Spatial, Time, Concentration, ...) Version: 0.99-20200608 -Date: 2020-06-09 +Date: 2020-06-15 Maintainer: Claudia Beleites Authors@R: c( person("Claudia", "Beleites", role = c("aut","cre", "dtc"), email = "Claudia.Beleites@chemometrix.gmbh"), From 167b847aaa134647df1976989ed4ac909803c509 Mon Sep 17 00:00:00 2001 From: Vilmantas Gegzna Date: Mon, 22 Jun 2020 00:25:13 +0300 Subject: [PATCH 54/55] Fix typo --- hyperSpec/R/spc.fit.poly.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperSpec/R/spc.fit.poly.R b/hyperSpec/R/spc.fit.poly.R index 05cd4bf96..fcebffd7f 100644 --- a/hyperSpec/R/spc.fit.poly.R +++ b/hyperSpec/R/spc.fit.poly.R @@ -322,7 +322,7 @@ spc.fit.poly.below <- function(fit.to, apply.to = fit.to, poly.order = 1, expect_equal(bl.nonorm[[]], bl.1e4[[]]) }) - test_that("stoppng rules for unstable solutions - issue #58", { + test_that("stopping rules for unstable solutions - issue #58", { # test object origninally created from chondro: # tmp <- chondro[103,,c(600 ~ 700, 1650 ~ 1800)] # tmp[[]] <- round(tmp[[]], digits = 1) From a77363be978165292174fc9c3e002c10657165df Mon Sep 17 00:00:00 2001 From: Vilmantas Gegzna Date: Mon, 22 Jun 2020 00:38:01 +0300 Subject: [PATCH 55/55] Fix documentation: multiline md might not work --- hyperSpec/R/spc.fit.poly.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hyperSpec/R/spc.fit.poly.R b/hyperSpec/R/spc.fit.poly.R index fcebffd7f..aaecbe7ef 100644 --- a/hyperSpec/R/spc.fit.poly.R +++ b/hyperSpec/R/spc.fit.poly.R @@ -123,8 +123,8 @@ spc.fit.poly <- function(fit.to, apply.to = NULL, poly.order = 1, ##' ##' `spc.fit.poly.below()` tries to fit the baseline on appropriate spectral -##' ranges of the spectra in `fit.to`. For details, see the `vignette -##' ("baseline")`. +##' ranges of the spectra in `fit.to`. For details, see the +##' `vignette("baseline")`. ##' @rdname baselines ##' @param npts.min minimal number of points used for fitting the polynomial ##' @param noise noise level to be considered during the fit. It may be given as