From 1a927052c5de24908bc82591bde94a2fa37ee649 Mon Sep 17 00:00:00 2001 From: "Win Cowger, PhD" Date: Fri, 5 Jan 2024 09:50:01 -0800 Subject: [PATCH] allow for vectors, required in shiny app --- R/smooth_intens.R | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/R/smooth_intens.R b/R/smooth_intens.R index d613616b..5be3d5d2 100644 --- a/R/smooth_intens.R +++ b/R/smooth_intens.R @@ -88,19 +88,13 @@ calc_window_points <- function(x, ...) { #' @rdname smooth_intens #' #' @export -calc_window_points.default <- function(x, ...) { - stop("object 'x' needs to be of class 'OpenSpecy'") -} - -#' @rdname smooth_intens -#' -#' @export -calc_window_points.OpenSpecy <- function(x, wavenum_width = 70){ +calc_window_points.default <- function(x, wavenum_width = 70, ...) { raw_points <- floor(wavenum_width/spec_res(x)) + if(raw_points %% 2 == 0){ raw_points <- raw_points - 1 } - if(raw_points > length(x$wavenumber)){ + if(raw_points > length(x)){ stop("The wavenum_width must be shorter than the full spectrum.") } if(raw_points <= 3){ @@ -109,6 +103,13 @@ calc_window_points.OpenSpecy <- function(x, wavenum_width = 70){ return(raw_points) } +#' @rdname smooth_intens +#' +#' @export +calc_window_points.OpenSpecy <- function(x, wavenum_width = 70, ...){ + do.call("calc_window_points", list(x = x$wavenumber, wavenum_width = wavenum_width)) +} + #' @importFrom signal filter sgolay .sgfilt <- function(y, p, n, m, abs = F, ...) {