generated from edgi-govdata-archiving/Template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_state_reportcards.R
58 lines (44 loc) · 1.42 KB
/
run_state_reportcards.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
library(pagedown)
library(here)
library(purrr)
library(dplyr)
library(optparse)
option_list = list(
make_option(c("-s", "--states"), type="character", default=NULL,
help="Regular Expression of states", metavar="character")
);
opt_parser = OptionParser(option_list=option_list);
opt = parse_args(opt_parser);
if (is.null(opt$states)){
print_help(opt_parser)
stop("A regular expression identifying states to be selected must be supplied.n", call.=FALSE)
}
load("names.rda")
names <- cd2
rm(cd2)
param_table <- names %>%
rename(
region = Region,
state = State
) %>% select(region,state,full_name)
render_report <- function(region,
full_name,
state) {
template <- "State_template.rmd"
out_file <- paste0(state, "_2021")
parameters <- list(full_name=full_name,
state=state)
tryCatch ({
message( full_name )
pagedown::chrome_print(rmarkdown::render(template, params = parameters,
envir = new.env(),clean = TRUE, output_dir = ("Output"), output_file = out_file,
))
}, error=function( cond ) {
message( "Error condition" )
message( cond )
})
# invisible(TRUE)
}
#use these two if you want to run multiple reports
params_list <- as.list(param_table %>% filter(param_table$region == "state" & grepl(opt$states,param_table$state)))
pmap(params_list, render_report)