-
Notifications
You must be signed in to change notification settings - Fork 0
/
mulder.R
78 lines (71 loc) · 1.76 KB
/
mulder.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
suppressPackageStartupMessages(library(tidyverse))
suppressPackageStartupMessages(library(testthat))
library(readxl)
load_data <- function(sheet) {
d <- read_xlsx(
"newdata/mulder/Who eats whom in our ten soil food webs.xlsx",
sheet = sheet
)
ans <- d |>
transmute(
res.taxonomy = Resource,
con.taxonomy = Consumer,
res.mass = 10 ^ Mres,
con.mass = 10 ^ Mconsumer,
foodweb.name = paste("A", sheet, sep = "-")
)
return (ans)
}
# interactions ---------
sheets <- as.character(243:252)
d <- lapply(sheets, load_data)
d <- d |>
bind_rows() |>
distinct_all()
# environmental data --------
env <- read_xlsx(
"newdata/mulder/Who eats whom in our ten soil food webs.xlsx",
sheet = "Table S1"
)
xy <- env |>
transmute(
foodweb.name = `Site number`,
longitude = `Degrees E` + `Minutes E` / 60,
latitude = `Degrees N` + `Minutes N` / 60,
ecosystem.type = "terrestrial belowground",
geographic.location = "Dutch agroecosystems"
)
test_that(
"All sites in geo table",
expect_identical(
sort(unique(d[["foodweb.name"]])),
sort(unique(xy[["foodweb.name"]]))
)
)
test_that(
"All sites in interaction table",
expect_identical(
sort(unique(xy[["foodweb.name"]])),
sort(unique(d[["foodweb.name"]]))
)
)
# write interactions to table ----------
d <- d |> left_join(xy, by = "foodweb.name")
test_that(
"Rows are unique",
expect_equal(
d |> nrow(),
d |> distinct_all() |> nrow()
)
)
d |> write_csv("newdata/mulder.csv")
# literature sources ------
suppressMessages(
sources <- read_xlsx(
"newdata/mulder/Who eats whom in our ten soil food webs.xlsx",
sheet = "Literature",
col_names = FALSE
) |>
pull(`...1`)
)
writeLines(sources, "newdata/mulder-sources.txt")