-
Notifications
You must be signed in to change notification settings - Fork 1
/
tables.R
55 lines (41 loc) · 1.66 KB
/
tables.R
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
library(tidyverse)
# function to fix hickory/oak species groups to match labels in species table
# we will assume all red oak and hickory species are "select"
filter_reference_tables <- function(x) {
x %>%
filter(
!species_group %in% c("Other red oak", "Other hickory")
) %>%
mutate(
species_group = case_when(
species_group == "Select red oak" ~ "Red oak",
species_group == "Select white oak" ~ "White oak",
species_group == "Select hickory" ~ "Hickory",
TRUE ~ species_group
)
)
}
# function to make sure species groups line up with groups in species table
check_reference_tables <- function(x) {
check1 <- all(x$species_group %in% species$species_group)
check2 <- all(species$species_group %in% x$species_group)
check1 & check2
}
# import all tables from csv, apply filter, check species groups
table1 <- vroom::vroom("inst/csv/table1.csv") %>%
filter_reference_tables()
assertthat::assert_that(check_reference_tables(table1))
table2 <- vroom::vroom("inst/csv/table2.csv") %>%
filter_reference_tables()
assertthat::assert_that(check_reference_tables(table2))
table3 <- vroom::vroom("inst/csv/table3.csv") %>%
filter_reference_tables()
assertthat::assert_that(check_reference_tables(table3))
table4 <- vroom::vroom("inst/csv/table4.csv") %>%
filter_reference_tables()
assertthat::assert_that(check_reference_tables(table4))
# add to package data
usethis::use_data(table1, overwrite = TRUE, internal = FALSE)
usethis::use_data(table2, overwrite = TRUE, internal = FALSE)
usethis::use_data(table3, overwrite = TRUE, internal = FALSE)
usethis::use_data(table4, overwrite = TRUE, internal = FALSE)