-
Notifications
You must be signed in to change notification settings - Fork 12
/
get_agrichange.R
57 lines (50 loc) · 1.43 KB
/
get_agrichange.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
#' @rdname db_getter_backend
#' @export
get_agrichange <- function(db_url = get_db_url("agrichange")) {
check_if_packages_are_available("readxl")
check_connection_to_url(db_url)
# download data
temp <- tempfile(fileext = ".xlsx")
utils::download.file(db_url, temp, mode = "wb", quiet = TRUE)
# read data
db_raw <- temp %>%
readxl::read_excel(
sheet = 1,
col_names = TRUE,
col_types = "text",
na = c("<<notfound>>", "nd", "--", "---"),
trim_ws = TRUE
)
# delete temporary file
unlink(temp)
# final data preparation
agrichange <- db_raw %>%
dplyr::transmute(
labnr = .data[["LabCode"]],
c14age = .data[["BP"]],
c14std = .data[["SD"]],
method = .data[["Method"]],
c13val = .[["\u03B413"]],
material = .data[["Sample"]],
species = .data[["Genus / specie"]],
site = .data[["Site"]],
country = .data[["Country"]],
sitetype = .data[["TypeSite"]],
lat = .data[["Lat"]],
lon = .data[["Lon"]],
region = .data[["Georegion"]],
period = .data[["ChronoPhase"]],
culture = paste_ignore_na(
.data[["CultI"]], .data[["CultII"]],
sep = ";"
),
shortref = .data[["Date_reference"]],
comment = .data[["Observations"]]
) %>%
dplyr::mutate(
sourcedb = "agrichange",
sourcedb_version = get_db_version("agrichange")
) %>%
as.c14_date_list()
return(agrichange)
}