-
Notifications
You must be signed in to change notification settings - Fork 0
/
master.Rmd
188 lines (124 loc) · 5.39 KB
/
master.Rmd
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
---
title: "Master"
output: html_document
author: Ryan Yost
---
```{r setup}
# change this to find whereever the current file is
#mainDir <- "C:/Users/ryost/Box Sync/RA_Loop"
mainDir <- "C:/Users/ryost/Box Sync/00- Main/Internal/02 - Work/Projects/RA - Primer/git_RA_primer/draft_fake/"
# set up file
# this will call all utility files and load packages needed
source(file = "requirements.R")
source(file = "utilities.R")
MIN_DATE <- 2000
MAX_DATE <- 2021
# do we want two filters for the comparison group, e.g. LIDC + WHD
# This has to be 1,
# 2 layer filtering not currently supported
COMP_FILTER = 1
```
```{r data paths}
dataDir <- "data/02-Clean/"
# tables for chart
ALL_TABLE <- read.csv(file.path(mainDir, dataDir, "ALL_TABLE.csv"))
WEO_PATH <- file.path(mainDir, dataDir, "weo.csv")
DOTS_PATH <- file.path(mainDir, dataDir, "DOTS.csv")
RATES_PATH <- file.path(mainDir, dataDir, "rates.csv")
WORLD_PATH <- file.path(mainDir, dataDir, "world.csv")
DUTIES_PATH <- file.path(mainDir, dataDir, "wto_duties_data.csv")
# country list used for loop
COUNTRY_CLASS_PATH <- file.path(mainDir, dataDir ,"CountryClassifications.xlsx")
country_list <- read.xlsx(file = COUNTRY_CLASS_PATH, sheetIndex = 1, stringsAsFactors = F)
```
```{r loop}
for (i in 1:length(country_list$Value)){
COS_ISO3 <- country_list$WEO_ISO_3[i]
COS_WEO3 <- country_list$WEO_Code[i]
COS_ISO2 <- country_list$WEO_ISO_2[i]
# this is a column header in the country classification.xlsx input file
COS_NAME <- country_list$Value[i]
# this is a column header in the country classification.xlsx input file
COMP_CODE <- "IMF_Region"
# this will get each country's division to filter by
COMP_VALUE <- country_list$IMF_Region[i]
subDir <- paste(COS_NAME, "_", COMP_VALUE, "_", sep = "")
COMP_DF <- getCompInfo(Codetype = COMP_CODE,
CodeValue = COMP_VALUE,
longOrWide = "wide",
path = COUNTRY_CLASS_PATH)
rmarkdown::render(
input = file.path("output.Rmd"),
output_file = paste(subDir, ".pdf", sep = ""),
output_format = "pdf_document",
# start fresh environment for each render
envir = new.env(),
params = list(
# country of study information
COS_NAME = as.character(COS_NAME),
COS_ISO3 = as.character(COS_ISO3),
COS_WEO3 = as.character(COS_WEO3),
COS_ISO2 = as.character(COS_ISO2),
# comparator information
COMP_CODE = COMP_CODE,
COMP_VALUE = COMP_VALUE,
COMP_DF = COMP_DF,
# list of countries
ALL_TABLE = ALL_TABLE,
# dates
MAX_DATE = MAX_DATE,
MIN_DATE = MIN_DATE,
# list to datasets
WEO_PATH = WEO_PATH,
DOTS_PATH = DOTS_PATH,
RATES_PATH = RATES_PATH,
WORLD_PATH = WORLD_PATH,
DUTIES_PATH = DUTIES_PATH,
)
)
}
```
```{r one - report }
COS_NAME <- "RandomData"
COS_ISO3 <- "ARM"
COS_WEO3 <- "911"
COS_ISO2 <- "AM"
# this is a column header in the country classification.xlsx input file
COMP_CODE <- "IMF_Region"
# this will get each country's division to filter by
COMP_VALUE <- "MCD"
subDir <- paste(COS_NAME, "_", COMP_VALUE, "_", sep = "")
COMP_DF <- getCompInfo(Codetype = COMP_CODE,
CodeValue = COMP_VALUE,
longOrWide = "wide",
path = COUNTRY_CLASS_PATH)
rmarkdown::render(
input = file.path("output.Rmd"),
output_file = paste(subDir, ".pdf", sep = ""),
output_format = "pdf_document",
# start fresh environment for each render
envir = new.env(),
params = list(
# country of study information
COS_NAME = as.character(COS_NAME),
COS_ISO3 = as.character(COS_ISO3),
COS_WEO3 = as.character(COS_WEO3),
COS_ISO2 = as.character(COS_ISO2),
# comparator information
COMP_CODE = COMP_CODE,
COMP_VALUE = COMP_VALUE,
COMP_DF = COMP_DF,
# list of countries
ALL_TABLE = ALL_TABLE,
# dates
MAX_DATE = MAX_DATE,
MIN_DATE = MIN_DATE,
# list to datasets
WEO_PATH = WEO_PATH,
DOTS_PATH = DOTS_PATH,
RATES_PATH = RATES_PATH,
WORLD_PATH = WORLD_PATH,
DUTIES_PATH = DUTIES_PATH
)
)
```