From 48654b1d600ed5e10184a16c37a04478f91f7126 Mon Sep 17 00:00:00 2001 From: Robin Lovelace Date: Mon, 25 Apr 2022 22:40:25 +0100 Subject: [PATCH] Add docs to test compatibility with other classes for #13 --- data-raw/si-classes.Rmd | 30 ++++++++++++++++++++++++++++++ data-raw/si-classes.md | 26 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 data-raw/si-classes.Rmd create mode 100644 data-raw/si-classes.md diff --git a/data-raw/si-classes.Rmd b/data-raw/si-classes.Rmd new file mode 100644 index 0000000..16f16c3 --- /dev/null +++ b/data-raw/si-classes.Rmd @@ -0,0 +1,30 @@ +--- +title: "Using the si package with different input classes" +output: github_document +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup} +# remotes::install_github("robinlovelace/si") +library(si) +# ?si_predict +``` + +```{r} +od = si_to_od(si_zones, si_zones, max_dist = 4000) +m = lm(od$origin_all ~ od$origin_bicycle) +od_updated = si_predict(od, m) +class(od_updated) +od_dt = data.table::data.table(od) +class(od_dt) +od_updated_dt = si_predict(od_dt, m) +class(od_updated_dt) +identical(od_updated$interaction, od_updated_dt$interaction) +``` + diff --git a/data-raw/si-classes.md b/data-raw/si-classes.md new file mode 100644 index 0000000..a682a29 --- /dev/null +++ b/data-raw/si-classes.md @@ -0,0 +1,26 @@ +Using the si package with different input classes +================ + +``` r +# remotes::install_github("robinlovelace/si") +library(si) +# ?si_predict +``` + +``` r +od = si_to_od(si_zones, si_zones, max_dist = 4000) +#> 1695 OD pairs remaining after removing those with a distance greater than 4000 meters: +#> 15% of all possible OD pairs +m = lm(od$origin_all ~ od$origin_bicycle) +od_updated = si_predict(od, m) +class(od_updated) +#> [1] "sf" "data.frame" +od_dt = data.table::data.table(od) +class(od_dt) +#> [1] "data.table" "data.frame" +od_updated_dt = si_predict(od_dt, m) +class(od_updated_dt) +#> [1] "data.table" "data.frame" +identical(od_updated$interaction, od_updated_dt$interaction) +#> [1] TRUE +```