-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
112 lines (81 loc) · 3.46 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
title: "`caRey`"
output:
github_document:
toc: true
toc_depth: 4
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
```{r load-packages, include=FALSE}
library(caRey)
```
<!-- badges: start -->
[![GitHub R package version](https://img.shields.io/github/r-package/v/nicholascarey/caRey)](https://github.com/nicholascarey/caRey)
[![DOI](https://zenodo.org/badge/277777549.svg)](https://zenodo.org/badge/latestdoi/277777549)
[![R-CMD-check](https://github.com/nicholascarey/caRey/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nicholascarey/caRey/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/nicholascarey/caRey/branch/master/graph/badge.svg)](https://app.codecov.io/gh/nicholascarey/caRey?branch=master)
<!-- badges: end -->
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:
```r
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.
```{r eval = F}
## 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")
}
```
```{r eval = T, echo = F}
progress(500, total = 1000, message = "Operation progress")
```
#### `smoother()`
A general data smoothing function with several methods including moving average, splines, and loess regression.
```{r eval = F}
smoother(sine_noisy.rd, method = "spline")
```
```{r eval = T, echo = F, out.width = '60%', fig.align='center', results='hide', fig.keep='all'}
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.
```{r eval = F}
peaks(swim_y.rd, span = 5, smooth.method = "spline", smooth.n = 0.4, plot.which = "p")
```
```{r eval = T, echo = F, out.width = '60%', fig.align='center', results='hide', fig.keep='all'}
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:
```{r eval = F}
## 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
```{r eval = T}
# # 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](mailto:[email protected]) or [open an issue](https://github.com/nicholascarey/caRey/issues).