Skip to content

Commit

Permalink
Merge pull request #78 from r-hyperspec/feature-38/rename-functions-2
Browse files Browse the repository at this point in the history
Feature 38/rename functions (39, 46)
  • Loading branch information
GegznaV authored Dec 14, 2021
2 parents 20131c8 + 7561cfa commit 12c597b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 24 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@
`spc.fit.poly()` | `spc_fit_poly()` | cbeleites/hyperSpec#208, cbeleites/hyperSpec#301
`spc.fit.poly.below()` | `spc_fit_poly_below()` | cbeleites/hyperSpec#208, cbeleites/hyperSpec#301
`spc.identify()` | `identify_spc()` | #40
`spc.label.default()` | `format_label_ispc_wl()` | #39
`spc.label.wlonly()` | `format_label_wl_only()` | #39
`spc.loess()` | `spc_loess()` | cbeleites/hyperSpec#208, cbeleites/hyperSpec#301
`spc.NA.approx()` | `spc_na_approx()` | cbeleites/hyperSpec#208, cbeleites/hyperSpec#301
`spc.point.default()` | `locate_spc_point_clicked()` | #46
`spc.point.max()` | `locate_spc_point_max()` | #46
`spc.point.min()` | `locate_spc_point_min()` | #46
`spc.point.sqr()` | `locate_spc_point_parabola_max()`| #46
`spc.rubberband()` | `spc_rubberband()` | cbeleites/hyperSpec#208, cbeleites/hyperSpec#301
`spc.smooth.spline()` | `spc_smooth_spline()` | cbeleites/hyperSpec#208, cbeleites/hyperSpec#301
`wl.eval()` | `wl_eval()` | cbeleites/hyperSpec#208, cbeleites/hyperSpec#309
Expand Down
56 changes: 55 additions & 1 deletion R/DEPRECATED-spc.identify.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
#' Please, use the suggested alternative functions instead:
#'
#' - [hyperSpec::identify_spc()]
#' - [hyperSpec::format_label_wl_only()]
#' - [hyperSpec::format_label_ispc_wl()]
#' - [hyperSpec::locate_spc_point_parabola_max()]
#' - [hyperSpec::locate_spc_point_min()]
#' - [hyperSpec::locate_spc_point_max()]
#' - [hyperSpec::locate_spc_point_clicked()]
#'
#'
#' @param ... arguments to [hyperSpec::identify_spc()].
#' @param ... arguments to [hyperSpec::identify_spc()] and other functions.
#'
#' @include identify_spc.R
#' @export
Expand All @@ -23,6 +29,48 @@ spc.identify <- function(...) {
identify_spc(...)
}

#' @rdname DEPRECATED-spc.identify
#' @export
spc.label.wlonly <- function(...) {
hySpc_deprecated("format_label_wl_only")
format_label_wl_only(...)
}

#' @rdname DEPRECATED-spc.identify
#' @export
spc.label.default <- function(...) {
hySpc_deprecated("format_label_ispc_wl")
format_label_ispc_wl(...)
}

#' @rdname DEPRECATED-spc.identify
#' @export
spc.point.sqr <- function(...) {
hySpc_deprecated("locate_spc_point_parabola_max")
locate_spc_point_parabola_max(...)
}

#' @rdname DEPRECATED-spc.identify
#' @export
spc.point.min <- function(...) {
hySpc_deprecated("locate_spc_point_min")
locate_spc_point_min(...)
}

#' @rdname DEPRECATED-spc.identify
#' @export
spc.point.max <- function(...) {
hySpc_deprecated("locate_spc_point_max")
locate_spc_point_max(...)
}

#' @rdname DEPRECATED-spc.identify
#' @export
spc.point.default <- function(...) {
hySpc_deprecated("locate_spc_point_clicked")
locate_spc_point_clicked(...)
}


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

Expand All @@ -31,5 +79,11 @@ hySpc.testthat::test(spc.identify) <- function() {

test_that("spc.identify() is deprecated", {
expect_error(expect_warning(spc.identify(), "deprecated"))
expect_error(expect_warning(spc.label.wlonly(), "deprecated"))
expect_error(expect_warning(spc.label.default(), "deprecated"))
expect_error(expect_warning(spc.point.sqr(), "deprecated"))
expect_error(expect_warning(spc.point.min(), "deprecated"))
expect_error(expect_warning(spc.point.max(), "deprecated"))
expect_error(expect_warning(spc.point.default(), "deprecated"))
})
}
46 changes: 23 additions & 23 deletions R/identify_spc.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#' @rdname identify_spc
#'
#' @aliases identify_spc
#' spc.label.default
#' spc.label.wlonly
#' spc.point.default
#' spc.point.max
#' spc.point.min
#' spc.point.sqr
#' format_label_ispc_wl
#' format_label_wl_only
#' locate_spc_point_clicked
#' locate_spc_point_max
#' locate_spc_point_min
#' locate_spc_point_parabola_max
#'
#' @details
#' Function [identify_spc()] first finds the spectrum with a point closest
Expand All @@ -26,13 +26,13 @@
#' label maxima (or minima) without demanding too precise clicks. Currently,
#' the following functions to determine the precise point:
#'
#' - [spc.point.default()]
#' - [locate_spc_point_clicked()]
#' uses the clicked wavelength together with its spectral intensity;
#' - [spc.point.max()]
#' - [locate_spc_point_max()]
#' the point with the highest intensity in the wavelength window;
#' - [spc.point.min()]
#' - [locate_spc_point_min()]
#' the point with the lowest intensity in the wavelength window;
#' - [spc.point.sqr()]
#' - [locate_spc_point_parabola_max()]
#' maximum of a parabola fit through the point with highest intensity
#' and the two surrounding points.
#'
Expand All @@ -47,8 +47,8 @@
#' using [text()][graphics::text()]. Currently, the following `formatter`s are
#' available:
#' \tabular{ll}{
#' [spc.label.default()] \tab spectrum number, wavelength \cr
#' [spc.label.wlonly()] \tab wavelength \cr
#' [format_label_ispc_wl()] \tab spectrum number, wavelength \cr
#' [format_label_wl_only()] \tab wavelength \cr
#' }
#'
#' `formatter` functions receive the number of the spectrum `ispc`,
Expand Down Expand Up @@ -96,7 +96,7 @@
#' If `FALSE`, the resulting data.frame will have a row of `NA`s
#' instead.
#'
#' @param delta `spc.point.sqr` fits the parabola in the window wlclick
#' @param delta `locate_spc_point_parabola_max` fits the parabola in the window wlclick
#' \eqn{\pm}{+-} delta points.
#'
#' @return [identify_spc()] returnsa `data.frame` with columns:
Expand Down Expand Up @@ -143,13 +143,13 @@
#' xoffset = 1100,
#' wl.range = c(600 ~ 1700, 2900 ~ 3150)
#' ),
#' formatter = spc.label.wlonly
#' formatter = format_label_wl_only
#' )
#'
#' ## looking for minima
#' identify_spc(
#' plot(-paracetamol, wl.reverse = TRUE),
#' point.fn = spc.point.min, adj = c(1, 0.5)
#' point.fn = locate_spc_point_min, adj = c(1, 0.5)
#' )
#'
#' }}
Expand All @@ -158,8 +158,8 @@ identify_spc <- function(x, y = NULL,
ispc = NULL,
tol.wl = diff(range(x)) / 200,
tol.spc = diff(range(y)) / 50,
point.fn = spc.point.max, # function to find the maximum
formatter = spc.label.default, # NULL: suppress labels
point.fn = locate_spc_point_max, # function to find the maximum
formatter = format_label_ispc_wl, # NULL: suppress labels
...,
cex = 0.7,
adj = c(0, 0.5),
Expand Down Expand Up @@ -274,28 +274,28 @@ identify_spc <- function(x, y = NULL,
#' @param wlclick The clicked wavelength.
#'
#' @export
spc.point.max <- function(wl, spc, wlclick) {
locate_spc_point_max <- function(wl, spc, wlclick) {
i <- which.max(spc)
c(wl = wl[i], spc = spc[i])
}

#' @rdname identify_spc
#' @export
spc.point.default <- function(wl, spc, wlclick) {
locate_spc_point_clicked <- function(wl, spc, wlclick) {
i <- round(approx(wl, seq_along(wl), wlclick, rule = 2)$y)
c(wl = wl[], spc = spc[i])
}

#' @rdname identify_spc
#' @export
spc.point.min <- function(wl, spc, wlclick) {
locate_spc_point_min <- function(wl, spc, wlclick) {
i <- which.min(spc)
c(wl = wl[i], spc = spc[i])
}

#' @rdname identify_spc
#' @export
spc.point.sqr <- function(wl, spc, wlclick, delta = 1L) {
locate_spc_point_parabola_max <- function(wl, spc, wlclick, delta = 1L) {
i <- which.max(spc)

## points (wl [i], spc [i])
Expand Down Expand Up @@ -325,12 +325,12 @@ spc.point.sqr <- function(wl, spc, wlclick, delta = 1L) {
#' @param digits How many digits of the wavelength should be displayed?
#'
#' @export
spc.label.default <- function(ispc, wl, spc, digits = 3) {
format_label_ispc_wl <- function(ispc, wl, spc, digits = 3) {
sprintf(" %i, %s ", ispc, format(wl, digits = digits))
}

#' @rdname identify_spc
#' @export
spc.label.wlonly <- function(ispc, wl, spc, digits = 3) {
format_label_wl_only <- function(ispc, wl, spc, digits = 3) {
sprintf(" %s ", format(wl, digits = digits))
}

0 comments on commit 12c597b

Please sign in to comment.