-
Notifications
You must be signed in to change notification settings - Fork 12
/
get_pacea.R
57 lines (51 loc) · 1.39 KB
/
get_pacea.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_pacea <- function(db_url = get_db_url("pacea")) {
check_connection_to_url(db_url)
# download and unzip data
temp <- tempfile()
utils::download.file(db_url, temp, quiet = TRUE)
db_path <- utils::unzip(
temp,
file.path("PA20110001_S01.txt"),
exdir = tempdir()
)
# read data
db_raw <- data.table::fread(
db_path,
sep = "\t",
encoding = "Latin-1",
skip = 1,
colClasses = "character",
showProgress = FALSE
)
# remove files in file system
unlink(temp)
file.remove(db_path)
# final data preparation
pacea <- db_raw %>%
base::replace(., . == "", NA) %>%
dplyr::transmute(
method = .data[["Date Type"]],
labnr = .data[["Code"]],
c14age = .data[["Age"]],
c14std = .data[["s.dev."]],
site = .data[["Site"]],
sitetype = .data[["Site Type"]],
feature = .data[["Site Function"]],
period = .data[["Cultural Attribution 1"]],
culture = .data[["Cultural Attribution 2"]],
material = .data[["Sample"]],
region = .data[["Region"]],
country = .data[["Country"]],
lat = .data[["Latitude"]],
lon = .data[["Longitude"]],
shortref = .data[["Biblio"]],
comment = .data[["Notes"]]
) %>% dplyr::mutate(
sourcedb = "pacea",
sourcedb_version = get_db_version("pacea")
) %>%
as.c14_date_list()
return(pacea)
}