-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_info.R
executable file
·34 lines (27 loc) · 1 KB
/
generate_info.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
#!/usr/bin/env Rscript
out_dir <- "00058 - nswla"
preflib_series_number <- "00058"
# This file generates the required summaries of the dataset files for "info.txt"
data_files <- list.files("00058 - nswla")
data_files <- data_files[grep("info.txt", data_files, invert = TRUE)]
summaries <- data.frame(file_name = data_files)
summaries$modification_type <- "original"
summaries$relates_to <- ""
data_file_indices <- as.integer(
do.call(
rbind,
strsplit(summaries$file_name, "[.-]")
)[, 2]
)
la <- read.csv("nsw_legislative_assembly_elections.csv")
summaries$title <- la[, "title"]
summaries$description <- ""
summaries$publication_date <- la[, "published"]
out_file <- file.path(out_dir, "info.txt")
# If the destination file exists, delete it.
if (file.exists(out_file)) {
file.remove(out_file)
}
# Copy the info template and append the csv data to the bottom
file.copy(file.path("info_template.txt"), out_file)
write.table(summaries, out_file, append = TRUE, row.names = FALSE, quote = FALSE, sep = ", ")