From e7bed5029b3669715229d2682a9de1508fe856b7 Mon Sep 17 00:00:00 2001 From: Pedro Aphalo Date: Sun, 12 Nov 2023 20:19:31 +0200 Subject: [PATCH] Prepare for CRAN tests --- DESCRIPTION | 2 +- R/stat-peaks.R | 25 +++++++++++++++++-------- _pkgdown.yml | 9 +++++---- man/find_peaks.Rd | 25 +++++++++++++++++-------- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 29d5e84..ef64e7d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: ggpmisc Type: Package Title: Miscellaneous Extensions to 'ggplot2' -Version: 0.5.4-1.9001 +Version: 0.5.5 Date: 2023-11-12 Authors@R: c( diff --git a/R/stat-peaks.R b/R/stat-peaks.R index 91ac5d8..ea01fa3 100644 --- a/R/stat-peaks.R +++ b/R/stat-peaks.R @@ -3,9 +3,11 @@ #' This method finds peaks (local maxima) in a vector, using a user selectable #' span and size threshold relative to the tallest peak (global maximum). #' -#' @param x numeric vector +#' @param x numeric vector. #' @param ignore_threshold numeric value between 0.0 and 1.0 indicating the size -#' threshold below which peaks will be ignored. +#' threshold below which peaks will be ignored, or a negative value >= -1, +#' to ignore peaks above a threshold. These values are relative to the range +#' of \code{x}. #' @param span a peak is defined as an element in a sequence which is greater #' than all other elements within a window of width span centered at that #' element. The default value is 3, meaning that a peak is bigger than both of @@ -20,12 +22,12 @@ #' peaks in vector \code{x} and can be used to extract the rows corresponding #' to peaks from a data frame. #' -#' @details This function is a wrapper built on function +#' @details This function is a wrapper built onto function #' \code{\link[splus2R]{peaks}} from \pkg{splus2R} and handles non-finite #' (including NA) values differently than \code{peaks}, instead of giving an -#' error when \code{na.rm = FALSE} they are replaced with the smallest finite -#' value in \code{x}. \code{span = NULL} is treated as a special case and -#' returns \code{max(x)}. +#' error when \code{na.rm = FALSE} and \code{x} contains \code{NA} values, +#' \code{NA} values are replaced with the smallest finite value in \code{x}. +#' \code{span = NULL} is treated as a special case and returns \code{max(x)}. #' #' @note The default for parameter \code{strict} is \code{FALSE} in functions #' \code{peaks()} and \code{find_peaks()}, as in \code{stat_peaks()} and in @@ -44,14 +46,21 @@ #' as.numeric = TRUE) # years -> as numeric #' #' which(find_peaks(lynx_num.df$lynx, span = 31)) -#' lynx_num.df[find_peaks(lynx_num.df$lynx, span = 31), ] +#' lynx_num.df[find_peaks(lynx_num.df$lynx, span = 15), ] +#' lynx_num.df[find_peaks(lynx_num.df$lynx, span = NULL), ] +#' lynx_num.df[find_peaks(lynx_num.df$lynx, +#' span = 31, +#' ignore_threshold = 0.75), ] #' #' lynx_datetime.df <- #' try_tibble(lynx, #' col.names = c("year", "lynx")) # years -> POSIXct #' #' which(find_peaks(lynx_datetime.df$lynx, span = 31)) -#' lynx_datetime.df[find_peaks(lynx_num.df$lynx, span = 31), ] +#' lynx_datetime.df[find_peaks(lynx_datetime.df$lynx, span = 31), ] +#' lynx_datetime.df[find_peaks(lynx_datetime.df$lynx, +#' span = 31, +#' ignore_threshold = 0.75), ] #' find_peaks <- function(x, diff --git a/_pkgdown.yml b/_pkgdown.yml index 55e95b0..b435189 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -42,15 +42,16 @@ reference: - stat_multcomp - use_label - title: Utilities - desc: Low level functions that can be useful to developers of other ggplot2 extensions. + desc: Low level functions used to build some of the functions above, but possibly useful also in other contexts. contents: - - swap_xy - - keep_tidy + - find_peaks - coef.lmodel2 - confint.lmodel2 - predict.lmodel2 + - keep_tidy + - swap_xy - title: Changes - desc: Geometries, statistics and functions moved to package 'gginnards'. + desc: List of geometries, statistics and functions moved to package 'gginnards'. contents: - Moved diff --git a/man/find_peaks.Rd b/man/find_peaks.Rd index 3877733..7690e83 100644 --- a/man/find_peaks.Rd +++ b/man/find_peaks.Rd @@ -7,10 +7,12 @@ find_peaks(x, ignore_threshold = 0, span = 3, strict = FALSE, na.rm = FALSE) } \arguments{ -\item{x}{numeric vector} +\item{x}{numeric vector.} \item{ignore_threshold}{numeric value between 0.0 and 1.0 indicating the size -threshold below which peaks will be ignored.} +threshold below which peaks will be ignored, or a negative value >= -1, +to ignore peaks above a threshold. These values are relative to the range +of \code{x}.} \item{span}{a peak is defined as an element in a sequence which is greater than all other elements within a window of width span centered at that @@ -34,12 +36,12 @@ This method finds peaks (local maxima) in a vector, using a user selectable span and size threshold relative to the tallest peak (global maximum). } \details{ -This function is a wrapper built on function +This function is a wrapper built onto function \code{\link[splus2R]{peaks}} from \pkg{splus2R} and handles non-finite (including NA) values differently than \code{peaks}, instead of giving an - error when \code{na.rm = FALSE} they are replaced with the smallest finite - value in \code{x}. \code{span = NULL} is treated as a special case and - returns \code{max(x)}. + error when \code{na.rm = FALSE} and \code{x} contains \code{NA} values, + \code{NA} values are replaced with the smallest finite value in \code{x}. + \code{span = NULL} is treated as a special case and returns \code{max(x)}. } \note{ The default for parameter \code{strict} is \code{FALSE} in functions @@ -55,14 +57,21 @@ lynx_num.df <- as.numeric = TRUE) # years -> as numeric which(find_peaks(lynx_num.df$lynx, span = 31)) -lynx_num.df[find_peaks(lynx_num.df$lynx, span = 31), ] +lynx_num.df[find_peaks(lynx_num.df$lynx, span = 15), ] +lynx_num.df[find_peaks(lynx_num.df$lynx, span = NULL), ] +lynx_num.df[find_peaks(lynx_num.df$lynx, + span = 31, + ignore_threshold = 0.75), ] lynx_datetime.df <- try_tibble(lynx, col.names = c("year", "lynx")) # years -> POSIXct which(find_peaks(lynx_datetime.df$lynx, span = 31)) -lynx_datetime.df[find_peaks(lynx_num.df$lynx, span = 31), ] +lynx_datetime.df[find_peaks(lynx_datetime.df$lynx, span = 31), ] +lynx_datetime.df[find_peaks(lynx_datetime.df$lynx, + span = 31, + ignore_threshold = 0.75), ] } \seealso{