-
Notifications
You must be signed in to change notification settings - Fork 9
/
README.Rmd
87 lines (58 loc) · 2.71 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r options, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
set.seed(1337)
```
RDP
===
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/RDP)](https://CRAN.R-project.org/package=RDP)
[![R build status](https://github.com/robertdj/RDP/workflows/R-CMD-check/badge.svg)](https://github.com/robertdj/RDP/actions)
[![Codecov test coverage](https://codecov.io/gh/robertdj/RDP/branch/main/graph/badge.svg)](https://codecov.io/gh/robertdj/RDP)
<!-- badges: end -->
The {RDP} package contains an implementation of the [Ramer–Douglas–Peucker algorithm
](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm) for reducing the number of points in a curve.
There are other R packages that offer implementations of the Ramer–Douglas–Peucker algorithm, but {RDP} has only a single dependency and it executes pretty fast.
# Installation
{RDP} is [available on CRAN](https://cran.r-project.org/package=RDP) and can be installed with the command
``` r
install.packages("RDP")
```
{RDP} can also be installed from GitHub with the [{remotes} package](https://remotes.r-lib.org) using this command:
``` r
remotes::install_github("robertdj/RDP")
```
# Example
There is a single function in the {RDP} package.
Here is an example from the Wikipedia page linked to above with a description of the algorithm.
The original line is black and the approximating line is red.
```{r example}
x <- seq(from = 0, to = 5, by = 0.01)
y <- exp(-x) * cos(2 * pi * x)
plot(x, y, type = "l")
lines(RDP::RamerDouglasPeucker(x, y, 0.06), col = "red", lty = 2)
```
# Performance
Here is a comparison of the execution speed and memory usage of the {RDP} implementation and a pure R implementation from the [{kmlShape} package](https://cran.r-project.org/package=kmlShape):
```{r timing}
x <- as.double(1:10^4)
y <- rnorm(length(x))
bench::mark(
RDP = RDP::RamerDouglasPeucker(x, y, epsilon = 0.1),
kmlShape = kmlShape::DouglasPeuckerEpsilon(x, y, epsilon = 0.1)
)
```
In this example we see from the [{bench} package](https://bench.r-lib.org) summary that {RDP} is several 1000 times faster and only use a fraction of the memory.
# Acknowledgements
The C++ code was *originally* based on [a Gist from TimSC](https://gist.github.com/TimSC/0813573d77734bcb6f2cd2cf6cc7aa51), but over time it has been almost completely rewritten.
# License
This package is almost exclusively C++ code that is linked against R.
[As explained in Rcpp's FAQ](http://dirk.eddelbuettel.com/code/rcpp/Rcpp-FAQ.pdf) this leaves me no option but to use GPL.