Skip to content

Commit

Permalink
Merge pull request #331 from cbeleites/bugfix/321-unit-tests-failing-…
Browse files Browse the repository at this point in the history
…R-release

Clean depracated functions and unit tests
  • Loading branch information
cbeleites authored Jul 12, 2021
2 parents 63decdc + 922e173 commit a5eee67
Show file tree
Hide file tree
Showing 29 changed files with 294 additions and 946 deletions.
12 changes: 6 additions & 6 deletions hyperSpec/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Type: Package
Title: Work with Hyperspectral Data, i.e. Spectra + Meta Information (Spatial,
Time, Concentration, ...)
Version: 0.100.0
Date: 2020-08-24
Date: 2021-07-10
Maintainer: Claudia Beleites <[email protected]>
Authors@R: c(
person("Claudia", "Beleites", role = c("aut", "cre", "dtc"), email = "[email protected]"),
Expand Down Expand Up @@ -90,6 +90,7 @@ Collate:
'DEPRECATED-count_lines.R'
'hy_options.R'
'constants-regexps.R'
'extract_numbers.R'
'DEPRECATED-extract_numbers.R'
'DEPRECATED-ggplot2.R'
'DEPRECATED-read.ENVI.R'
Expand All @@ -113,14 +114,18 @@ Collate:
'DEPRECATED-scan.R'
'DEPRECATED-spc-various.R'
'DEPRECATED-spc_bin.R'
'spc_fit_poly.R'
'DEPRECATED-spc_fit_poly.R'
'DEPRECATED-spc_fix_colnames.R'
'DEPRECATED-spc_loess.R'
'DEPRECATED-spc_na_approx.R'
'spc_rubberband.R'
'DEPRECATED-spc_rubberband.R'
'DEPRECATED-spc_spline.R'
'DEPRECATED-wc.R'
'DEPRECATED-wl_convert_units.R'
'normalize01.R'
'wl_eval.R'
'DEPRECATED-wl_eval.R'
'DEPRECATED-wl_sort.R'
'DEPRECATED-write_txt_long.R'
Expand All @@ -131,7 +136,6 @@ Collate:
'all.equal.R'
'apply.R'
'as.data.frame.R'
'extract_numbers.R'
'as_hyperSpec.R'
'barbiturates.R'
'bind.R'
Expand Down Expand Up @@ -173,7 +177,6 @@ Collate:
'merge.R'
'mergeextra.R'
'mvtnorm.R'
'normalize01.R'
'palette_colorblind.R'
'palette_matlab.R'
'pearson_dist.R'
Expand All @@ -193,12 +196,10 @@ Collate:
'seq.R'
'show.R'
'spc_bin.R'
'spc_fit_poly.R'
'spc_fix_colnames.R'
'spc_identify.R'
'spc_loess.R'
'spc_na_approx.R'
'spc_rubberband.R'
'spc_spline.R'
'split.R'
'subset.R'
Expand All @@ -207,7 +208,6 @@ Collate:
'vandermonde.R'
'wl.R'
'wl_convert_units.R'
'wl_eval.R'
'wl_sort.R'
'write_txt_long.R'
'write_txt_wide.R'
Expand Down
3 changes: 2 additions & 1 deletion hyperSpec/R/DEPRECATED-count_lines.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' @name DEPRECATED-count_lines
#' @concept moved to hySpc.read.txt
#'
#' @title (DEPRECATED) Count Lines (of an ASCII File)
#' @title (DEPRECATED)
#' Count lines (of an ASCII File)
#'
#' @description
#'
Expand Down
36 changes: 10 additions & 26 deletions hyperSpec/R/DEPRECATED-extract_numbers.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' @name DEPRECATED-guess.wavlength
#' @concept deprecated
#'
#' @title (DEPRECATED) Guess Wavelengths from Character Vector
#' @title (DEPRECATED)
#' Guess wavelengths from character vector
#'
#'
#' @description
Expand All @@ -16,7 +17,7 @@
#'
#' Character vectors used for names (e.g. colnames for matrices or data.frames)
#' are often treated by [base::make.names()] or similar functions that
#' produce suitable names (e.g. by prepending "X" to numbers). Such names
#' produce suitable names (e.g. by pre-pending "X" to numbers). Such names
#' cannot be directly converted to numeric.
#'
#' `guess.wavlength()` tries to extract numbers from X which may be
Expand All @@ -35,40 +36,23 @@
#' tmp <- data.frame(flu[[, , 400 ~ 410]])
#' (wl <- colnames(tmp))
#' guess.wavelength(wl)
#' @include extract_numbers.R
guess.wavelength <- function(X) {
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hySpc_deprecated("extract_numbers")
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

wl <- regmatches(X, regexpr(.PATTERN.number, X))
wl <- as.numeric(wl)

if (is.null(wl) || length(wl) == 0L || any(is.na(wl))) {
if (hy.getOption("debuglevel") >= 1L) {
message("could not guess wavelengths")
}
wl <- NULL
}

wl
extract_numbers(X)
}

#' @include constants-regexps.R
#' @include hy_options.R
hySpc.testthat::test(guess.wavelength) <- function() {
context("guess.wavelength")

test_that("simple test", {
expect_equal(guess.wavelength(1:5), 1:5)
})

test_that("wavelengths containing characters", {
wl <- seq(600, 602, length.out = 11)
expect_equal(guess.wavelength(make.names(wl)), wl)
})

test_that("return NULL if could not guess wavelenths", {
expect_equal(guess.wavelength(colnames(matrix(1:12, 3))), NULL)
expect_equal(guess.wavelength(letters[1:4]), NULL)
test_that("deprecated", {
expect_warning(
guess.wavelength(1:5),
"Function 'guess.wavelength' is deprecated."
)
})
}
14 changes: 13 additions & 1 deletion hyperSpec/R/DEPRECATED-ggplot2.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @concept moved to hySpc.ggplot2
#'
#' @title (DEPRECATED)
#' Spectra Plotting with \pkg{ggplot2} Was Moved to \pkg{hySpc.ggplot2}
#' Spectra plotting with \pkg{ggplot2} was moved to \pkg{hySpc.ggplot2}
#'
#' @description
#'
Expand Down Expand Up @@ -609,3 +609,15 @@ colmix.rgb <- function(x, purecol, against = 1, sub = TRUE,

cols
}

# Unit tests -----------------------------------------------------------------

hySpc.testthat::test(qplotspc) <- function() {
context("ggplot2")

test_that("deprecated", {
expect_warning(res <- qplotspc(flu), "deprecated")
expect_warning(res <- qplotmap(flu), "deprecated")
expect_warning(res <- qplotc(flu), "deprecated")
})
}
4 changes: 2 additions & 2 deletions hyperSpec/R/DEPRECATED-read.asc.Andor.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#' @concept moved to hySpc.read.txt
#'
#' @title (DEPRECATED)
#' Import Raman Spectra/Maps from Andor Cameras/Solis ASCII Files
#' @description
#' Import Raman spectra/maps from Andor cameras/solis ASCII files
#'
#' @description
#' These data input functions are **deprecated** and they will be removed in
#' the next release of \pkg{hyperspec} package.
#' Now functions in package \pkg{hySpc.read.txt}
Expand Down
3 changes: 2 additions & 1 deletion hyperSpec/R/DEPRECATED-read.asc.PerkinElmer.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' @name DEPRECATED-read.asc.PerkinElmer
#' @concept moved to hySpc.read.txt
#'
#' @title (DEPRECATED) File import filter PerkinElmer ASCII spectra
#' @title (DEPRECATED)
#' File import filter PerkinElmer ASCII spectra
#'
#' @description
#'
Expand Down
3 changes: 2 additions & 1 deletion hyperSpec/R/DEPRECATED-read.ini.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' @name DEPRECATED-read.ini
#' @concept moved to hySpc.read.txt
#'
#' @title (DEPRECATED) Read INI files
#' @title (DEPRECATED)
#' Read INI files
#'
#' @description
#'
Expand Down
22 changes: 21 additions & 1 deletion hyperSpec/R/DEPRECATED-read.spe.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,23 @@ read.spe <- function(filename, xaxis = "file", acc2avg = F, cts_sec = F,
.spc_io_postprocess_optional(spc, filename)
}

#' Read XML footer from SPE file format version 3.0.

#' @name DEPRECATED-read.spe.xml
#' @concept moved to hySpc.read.spe
#'
#' @title (DEPRECATED)
#' Read XML footer from SPE file format version 3.0
#'
#' @description
#'
#' These data input functions are **deprecated** and they will be removed in
#' the next release of \pkg{hyperspec} package.
#' Now functions in package \pkg{hySpc.read.spe}
#' ([link](https://r-hyperspec.github.io/hySpc.read.spe/reference/index.html))
#' should be used as the alternatives.
#'
#'
#' **Old description:**
#'
#' The new SPE file format, introduced in 2012, was designed to be backwards compatible with the
#' previous format 2.5. The most prominent change is the new plain text XML footer holding vast
Expand All @@ -176,6 +192,10 @@ read.spe <- function(filename, xaxis = "file", acc2avg = F, cts_sec = F,
#' @importFrom xml2 as_list read_xml
#'
.read.spe.xml <- function(filename) {
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
deprecated_read_spe()
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

as_list(read_xml(.read.spe.xml_string(filename)))
}

Expand Down
3 changes: 2 additions & 1 deletion hyperSpec/R/DEPRECATED-read.txt.Horiba.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' @name DEPRECATED-read.txt.Horiba
#' @concept moved to hySpc.read.txt
#'
#' @title (DEPRECATED) Import Horiba Labspec exported ASCII files
#' @title (DEPRECATED)
#' Import Horiba Labspec exported ASCII files
#'
#' @description
#' These data input functions are **deprecated** and they will be removed in
Expand Down
3 changes: 2 additions & 1 deletion hyperSpec/R/DEPRECATED-read.txt.Renishaw.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' @name DEPRECATED-read.txt.Renishaw
#' @concept moved to hySpc.read.txt
#'
#' @title (DEPRECATED) Import Raman measurements from Renishaw ASCII-files
#' @title (DEPRECATED)
#' Import Raman measurements from Renishaw ASCII-files
#'
#' @description
#'
Expand Down
3 changes: 2 additions & 1 deletion hyperSpec/R/DEPRECATED-read.txt.Shimadzu.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' @name DEPRECATED-read.txt.Shimadzu
#' @concept moved to hySpc.read.txt
#'
#' @title (DEPRECATED) Reads Shimadzu GCxGC-qMS - Spectra Files (`.txt`)
#' @title (DEPRECATED)
#' Read Shimadzu GCxGC-qMS - spectra files (`.txt`)
#'
#' @description
#'
Expand Down
Loading

0 comments on commit a5eee67

Please sign in to comment.