From c1646056b678bab0d04f28c89c4cf59c94063b5c Mon Sep 17 00:00:00 2001 From: Lukas Schneiderbauer <lukas.schneiderbauer@gmail.com> Date: Fri, 27 Dec 2024 15:25:54 +0100 Subject: [PATCH] add a bunch of roxygen examples --- R/fcwt.R | 20 +++++++++--------- R/fcwtr_scalogram.R | 35 ++++++++++++++++++++++++++++++++ man/as.matrix.fcwtr_scalogram.Rd | 9 ++++++++ man/fcwt.Rd | 17 ++++++++-------- man/rbind.fcwtr_scalogram.Rd | 21 +++++++++++++++++++ man/sub-.fcwtr_scalogram.Rd | 8 ++++++++ 6 files changed, 91 insertions(+), 19 deletions(-) diff --git a/R/fcwt.R b/R/fcwt.R index 14d9fbe..5be4caa 100644 --- a/R/fcwt.R +++ b/R/fcwt.R @@ -76,15 +76,14 @@ #' @examples #' ts_sin_440 <- sin((1:5000) * 2 * pi * 440 / 44100) #' -#' res <- -#' fcwt( -#' ts_sin_440, -#' sample_freq = u(44.1, "kHz"), -#' freq_begin = u(50, "Hz"), -#' freq_end = u(1000, "Hz"), -#' n_freqs = 10, -#' sigma = 5 -#' ) +#' fcwt( +#' ts_sin_440, +#' sample_freq = u(44.1, "kHz"), +#' freq_begin = u(50, "Hz"), +#' freq_end = u(1000, "Hz"), +#' n_freqs = 10, +#' sigma = 5 +#' ) #' @export fcwt <- function(signal, sample_freq, @@ -134,7 +133,8 @@ fcwt <- function(signal, sc <- fcwtr_scalogram( - output, time_offset = u(0, "s"), sample_freq, freq_begin, freq_end, + output, + time_offset = u(0, "s"), sample_freq, freq_begin, freq_end, freq_scale, sigma ) diff --git a/R/fcwtr_scalogram.R b/R/fcwtr_scalogram.R index 6455b50..d0ac999 100644 --- a/R/fcwtr_scalogram.R +++ b/R/fcwtr_scalogram.R @@ -196,6 +196,26 @@ sc_agg <- function(x, wnd) { #' #' @return Returns a new time-wise combined "fcwtr_scalogram" object. #' +#' @examples +#' ts_sin_440 <- sin((1:5000) * 2 * pi * 440 / 44100) +#' +#' res <- +#' fcwt( +#' ts_sin_440, +#' sample_freq = u(44.1, "kHz"), +#' freq_begin = u(50, "Hz"), +#' freq_end = u(1000, "Hz"), +#' n_freqs = 10, +#' sigma = 5 +#' ) +#' +#' print(res) +#' +#' # doubled scalogram +#' res_doubled <- rbind(res, res) +#' +#' print(res_doubled) +#' #' @export rbind.fcwtr_scalogram <- function(...) { args <- list(...) @@ -322,6 +342,14 @@ as.data.frame.fcwtr_scalogram <- function(x, ...) { #' An "fcwtr_scalogram" object resulting from [fcwt()]. #' @inheritParams base::as.matrix #' +#' @examples +#' fcwt( +#' sin((1:5000) * 2 * pi * 440 / 44100), +#' sample_freq = 44100, +#' n_freqs = 10 +#' ) |> +#' as.matrix() +#' #' @export as.matrix.fcwtr_scalogram <- function(x, ...) { attributes(x) <- NULL @@ -352,6 +380,13 @@ as.matrix.fcwtr_scalogram <- function(x, ...) { #' @return #' Another "fcwtr_scalogram" object that contains only part of the data. #' +#' @examples +#' fcwt( +#' sin((1:5000) * 2 * pi * 440 / 44100), +#' sample_freq = 44100, +#' n_freqs = 10 +#' )[1:1000, 2:7] +#' #' @export `[.fcwtr_scalogram` <- function(x, i, j) { if (!missing(i)) { diff --git a/man/as.matrix.fcwtr_scalogram.Rd b/man/as.matrix.fcwtr_scalogram.Rd index c312316..e9c58f9 100644 --- a/man/as.matrix.fcwtr_scalogram.Rd +++ b/man/as.matrix.fcwtr_scalogram.Rd @@ -15,3 +15,12 @@ Strips attributes and class from a scalogram object to retrieve a pure matrix. } +\examples{ +fcwt( + sin((1:5000) * 2 * pi * 440 / 44100), + sample_freq = 44100, + n_freqs = 10 +) |> + as.matrix() + +} diff --git a/man/fcwt.Rd b/man/fcwt.Rd index 469b4be..9a88b25 100644 --- a/man/fcwt.Rd +++ b/man/fcwt.Rd @@ -86,13 +86,12 @@ Nat Comput Sci 2, 47–58 (2022). \doi{10.1038/s43588-021-00183-z} \examples{ ts_sin_440 <- sin((1:5000) * 2 * pi * 440 / 44100) -res <- - fcwt( - ts_sin_440, - sample_freq = u(44.1, "kHz"), - freq_begin = u(50, "Hz"), - freq_end = u(1000, "Hz"), - n_freqs = 10, - sigma = 5 - ) +fcwt( + ts_sin_440, + sample_freq = u(44.1, "kHz"), + freq_begin = u(50, "Hz"), + freq_end = u(1000, "Hz"), + n_freqs = 10, + sigma = 5 +) } diff --git a/man/rbind.fcwtr_scalogram.Rd b/man/rbind.fcwtr_scalogram.Rd index 8465634..40e3818 100644 --- a/man/rbind.fcwtr_scalogram.Rd +++ b/man/rbind.fcwtr_scalogram.Rd @@ -23,3 +23,24 @@ The scalograms are stitched together in chronological fashion (i.e. the first argument will the initial piece, etc.). Time offset information is kept from the first piece. } +\examples{ +ts_sin_440 <- sin((1:5000) * 2 * pi * 440 / 44100) + +res <- + fcwt( + ts_sin_440, + sample_freq = u(44.1, "kHz"), + freq_begin = u(50, "Hz"), + freq_end = u(1000, "Hz"), + n_freqs = 10, + sigma = 5 + ) + +print(res) + +# doubled scalogram +res_doubled <- rbind(res, res) + +print(res_doubled) + +} diff --git a/man/sub-.fcwtr_scalogram.Rd b/man/sub-.fcwtr_scalogram.Rd index c57d7d6..53c8f41 100644 --- a/man/sub-.fcwtr_scalogram.Rd +++ b/man/sub-.fcwtr_scalogram.Rd @@ -30,3 +30,11 @@ Another "fcwtr_scalogram" object that contains only part of the data. \description{ Extract parts of a scalogram } +\examples{ +fcwt( + sin((1:5000) * 2 * pi * 440 / 44100), + sample_freq = 44100, + n_freqs = 10 +)[1:1000, 2:7] + +}