knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
library(caRey)

GitHub R package version DOI R-CMD-check Codecov test coverage

The caRey package is a collection of handy R functions that may be useful in general data management or processing.

Installation

caRey can be installed using the devtools package:

install.packages("devtools")
devtools::install_github("nicholascarey/caRey")

Functions

progress()

A simple progress bar function for use in loops or operations where you want some indication of progress and how long it will take.

## Simple example with custom message
for(i in 1:1000) {
    Sys.sleep(0.01) # pause or this example will be too quick
    progress(i, total = 1000, message = "Operation progress")
    }
    progress(500, total = 1000, message = "Operation progress")

smoother()

A general data smoothing function with several methods including moving average, splines, and loess regression.

smoother(sine_noisy.rd, method = "spline")
smoother(sine_noisy.rd, method = "spline")

peaks()

A function that automatically identifies peaks (and troughs) in oscillating data, with several options for adjusting the detection sensitivity.

peaks(swim_y.rd, span = 5, smooth.method = "spline", smooth.n = 0.4, plot.which = "p")
peaks(swim_y.rd, span = 5, smooth.method = "spline", smooth.n = 0.4, plot.which = "p")

replace_tail(), replace_head()

replace_tail is a simple solution for replacing the last n values in a vector. There are lots of ways of extracting the last n values, and a few of these can be used to replace them, but can be somewhat inelegant, leading to difficult to read code such as:

## change last n values in x with 100
x[(length(x)-n+1):length(x)] <- 100

Instead, this function does the same job with either a value or vector

# # Replace last 5 numeric values with single value
x <- 1:10
replace_tail(x, 5, 100)

``` {r eval = T}

# Replace tail with a vector

x <- 1:20 replace_tail(x, r = 100:96) ```

Replacing the initial n values is much more straightforward in R syntax but replace_head makes a nice partner function and works the same way.

Bug reports

If you find any bugs, weird behaviour, or other issues please let me know or open an issue.



nicholascarey/caRey documentation built on Sept. 30, 2023, 3:47 a.m.