-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdataprep.R
50 lines (37 loc) · 1.3 KB
/
dataprep.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
# ------------------------------------------------------------------------
#
# Title : Fetch Stashed Loss and Exposure Data from Github Release
# By : Jimmy Briggs
# Date : 2022-01-03
#
# ------------------------------------------------------------------------
library(dplyr)
require(piggyback)
fs::dir_create("data-raw/original/downloaded")
fs::dir_create("data-raw/original/extracted")
piggyback::pb_download(
file = "loss_and_exposure_data.zip",
dest = "data-raw/original/downloaded",
repo = "jimbrig/lossrx",
tag = "v0.0.2",
overwrite = TRUE
)
unzip(
file.path("data-raw", "original", "downloaded", "loss_and_exposure_data.zip"),
exdir = file.path("data-raw", "original", "extracted")
)
exposures <- qs::qread("data-raw/original/extracted/exposures_scrubbed")
losses <- qs::qread("data-raw/original/extracted/loss_data_scrubbed")
losses <- losses |>
mutate(
occurrence_number = extract_num(occurrence_number)
)
losses_by_eval <- split(losses, losses$eval_date)
csv_dir <- fs::path("data-raw", "working", "lossruns", "CSV")
fs::dir_create(csv_dir)
csv_files <- paste0(csv_dir, "/", names(losses_by_eval), ".csv")
purrr::walk2(losses_by_eval, csv_files, vroom::vroom_write)
usethis::use_data(exposures)
usethis::use_data(losses, overwrite = TRUE)
doc_data(losses)
doc_data(exposures)