1
1
# !/usr/bin/env Rscript
2
2
3
- # # Combine and compress contingency tables by aggregation .
3
+ # # Combine and compress contingency tables by grouping variable set .
4
4
# #
5
5
# # Usage:
6
6
# #
@@ -45,13 +45,13 @@ run_rollup <- function(input_dir, output_dir, pattern = "^[0-9]{8}_[0-9]{8}.*[.]
45
45
seen_files <- load_seen_file(seen_file )
46
46
47
47
for (output_name in names(files )) {
48
- browser
48
+
49
49
newly_seen_files <- combine_and_save_tables(
50
50
seen_files ,
51
51
input_dir ,
52
52
files [[output_name ]],
53
53
file.path(output_dir , output_name ))
54
- browser()
54
+
55
55
write(newly_seen_files , seen_file , append = TRUE )
56
56
}
57
57
@@ -138,8 +138,8 @@ combine_and_save_tables <- function(seen_files, input_dir, input_files, output_f
138
138
write_csv(input_df , output_file , append = file.exists(output_file ))
139
139
} else {
140
140
assert(file.exists(output_file ),
141
- paste0(" The output file " , output_file , " does not exist, but " ,
142
- " non-zero files using the same grouping have been seen before." ))
141
+ paste0(" The output file " , output_file , " does not exist, but non-zero " ,
142
+ " files using the same grouping variables have been seen before." ))
143
143
144
144
output_df <- read_csv(output_file , col_types = cols )
145
145
@@ -158,7 +158,8 @@ combine_and_save_tables <- function(seen_files, input_dir, input_files, output_f
158
158
arrange(issue_date ) %> %
159
159
group_by(across(all_of(group_names ))) %> %
160
160
slice_tail() %> %
161
- ungroup()
161
+ ungroup() %> %
162
+ arrange(period_start )
162
163
163
164
# Automatically uses gzip compression based on output file name.
164
165
write_csv(output_df , output_file )
@@ -178,4 +179,7 @@ if (length(args) < 2) {
178
179
input_path <- args [1 ]
179
180
output_path <- args [2 ]
180
181
182
+ input_path <- " ~/Downloads/0418_tables/"
183
+ output_path <- " ~/Downloads/0418_tables/cache"
184
+
181
185
invisible (run_rollup(input_path , output_path ))
0 commit comments