-
Notifications
You must be signed in to change notification settings - Fork 12
/
get_palmisano.R
105 lines (96 loc) · 2.43 KB
/
get_palmisano.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
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
#' @rdname db_getter_backend
#' @export
get_palmisano <- function(db_url = get_db_url("palmisano")) {
check_connection_to_url(db_url)
# download and unzip data
temp <- tempfile()
utils::download.file(db_url, temp, quiet = TRUE)
radiocarbon_path <- utils::unzip(
temp,
file.path(
"Palmisanoetal", "csv", "radiocarbon.csv"
),
exdir = tempdir()
)
sites_path <- utils::unzip(
temp,
file.path(
"Palmisanoetal", "csv", "sites.csv"
),
exdir = tempdir()
)
# read data
radiocarbon_raw <- data.table::fread(
radiocarbon_path,
sep = ",",
encoding = "UTF-8",
drop = c(
"DateID",
"LocQual"
),
colClasses = "character",
showProgress = FALSE
)
sites_raw <- data.table::fread(
sites_path,
sep = ",",
encoding = "UTF-8",
drop = c(
"Toponyms",
"Longitude",
"Latitude",
"LocQual",
"SizeHa",
"SizeQual",
"Source",
"Source_id"
),
colClasses = "character",
showProgress = FALSE
)
# remove files in file system
unlink(temp)
file.remove(radiocarbon_path)
file.remove(sites_path)
# merge data
radiocarbon_additional_info <- radiocarbon_raw %>%
dplyr::left_join(
sites_raw,
by = c("SiteID" = "Id")
) %>%
dplyr::mutate(
CRA_bc = 1950 - as.numeric(.data[["CRA"]]),
StartDate = as.numeric(.data[["StartDate"]]),
EndDate = as.numeric(.data[["EndDate"]])
) %>%
dplyr::filter(
.data[["CRA_bc"]] >= .data[["StartDate"]] & .data[["CRA_bc"]] < .data[["EndDate"]]
)
palmisano_raw <- radiocarbon_raw %>%
dplyr::left_join(
radiocarbon_additional_info,
by = c("LabID", "CRA", "Error", "Material", "Species",
"SiteID", "SiteName", "Longitude", "Latitude", "Source")
)
# final data preparation
palmisano <- palmisano_raw %>%
base::replace(., . == "", NA) %>%
dplyr::transmute(
labnr = .data[["LabID"]],
c14age = .data[["CRA"]],
c14std = .data[["Error"]],
site = .data[["SiteName"]],
sitetype = .data[["Type"]],
material = .data[["Material"]],
species = .data[["Species"]],
period = .data[["Period"]],
lat = .data[["Latitude"]],
lon = .data[["Longitude"]],
shortref = .data[["Source"]]
) %>% dplyr::mutate(
sourcedb = "palmisano",
sourcedb_version = get_db_version("palmisano")
) %>%
as.c14_date_list()
return(palmisano)
}