forked from dabreegster/odjitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
107 lines (82 loc) · 2.48 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
# odjitter R package
<!-- badges: start -->
<!-- badges: end -->
The goal of this {odjitter} R package is to provide an R interface to the [odjitter](https://github.com/dabreegster/odjitter) Rust crate for processing origin-destination data.
Install the development version as follows
```{r, eval=FALSE}
remotes::install_github("dabreegster/odjitter", subdir = "r")
```
## R interface to `odjitter` Rust crate via system commands
```{r}
library(odjitter)
```
```{r jitter, out.width="50%", fig.show='hold'}
od = readr::read_csv("https://github.com/dabreegster/odjitter/raw/main/data/od.csv")
zones = sf::read_sf("https://github.com/dabreegster/odjitter/raw/main/data/zones.geojson")
names(zones)[1] = "geo_code"
road_network = sf::read_sf("https://github.com/dabreegster/odjitter/raw/main/data/road_network.geojson")
od_unjittered = od::od_to_sf(od, zones)
set.seed(42) # for reproducibility
od_jittered = jitter(od, zones, subpoints = road_network)
nrow(od_unjittered)
nrow(od_jittered)
plot(od_unjittered)
plot(od_jittered)
```
## Allowing duplicate OD pairs
By default the `jitter` function will remove duplicate OD pairs.
This can be disabled by setting `deduplicate_pairs = FALSE`.
```{r}
# Default behaviour (no duplicates):
od_jittered = jitter(
od,
zones,
subpoints = road_network,
disaggregation_threshold = 1,
show_command = TRUE,
)
summary(duplicated(od_jittered$geometry))
```
```{r}
```{r}
# Larger example:
od_jittered = jitter(
od,
zones,
subpoints = road_network,
disaggregation_threshold = 1,
show_command = TRUE,
deduplicate_pairs = FALSE
)
summary(duplicated(od_jittered$geometry))
```
## R interface to Rust via rextendr (not currently working)
The development of the package was done using the development version of the `rextendr` package.
```{r, eval=FALSE}
remotes::install_github("extendr/rextendr")
```
The package template was created as follows:
```{r, eval=FALSE}
usethis::use_description()
rextendr::use_extendr()
```
The odjitter Rust crate ported into the src/rust folder.
```{r, eval=FALSE, echo=FALSE}
list.files("src/rust/")
file.edit("~/orgs/atumWorld/odjitter/src/lib.rs")
file.edit("~/orgs/atumWorld/odjitter/Cargo.toml")
file.edit("src/rust/Cargo.toml")
```
```{bash, echo=FALSE, eval=FALSE}
cp -Rv ~/orgs/atumWorld/odjitter/src/scrape.rs src/rust/src/
```