#' find peak with curve fitting
#'
#' @param x
#' @param mode
#' @param config
#'
#' @return
#' @export
#'
#' @examples
find.peak <- function(x, mode = 'fit.smooth', config) {
# Ver 3.4.1
curve <- fit.curve(x, mode = mode, config)
if (is.null(curve)) {
cat(sprintf('Curve fit failed, no peak found!'))
return(NULL)
}
# Ver 3.4.1
curve.max <- curve[curve.max.p <- get.peak(curve)]
curve.min <- curve[curve.min.p <- get.valley(curve)]
if(is.nothing(curve.max)|is.nothing(curve.min)) return(NULL)
return(c(curve.max - curve.min, curve.min.p, curve.max.p))
# poi <- floor((curve.max.p + curve.min.p) / 2)
# voi <- curve[poi]
# if(is.na(poi)|is.na(voi)) return(NULL) # VER 3.3.2
# if (curve[1] < voi) {
# # Positive Peak
# return(c(curve.max - curve.min, curve.max.p))
# } else if (voi < curve[1]) {
# # Negative Peak
# return(c(curve.max - curve.min, curve.min.p))
# } else {
# warning('find.peak() UNKNOWN ERROR \n')
# return(NULL)
# }
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.