-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.R
30 lines (23 loc) · 1.09 KB
/
config.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
# File 1:R-Script
# contains a loop that iteratively calls an Rmarkdown file (i.e. File 2)
# load packages
library(knitr)
library(markdown)
library(rmarkdown)
library(readxl)
#Load Water Quality Data File
data <- read.csv("C:/Users/vanes/Documents/Report/waterqualitydata.csv")
# remove NA
row.has.na <- apply(data, 1, function(x){any(is.na(x))})
sum(row.has.na)
final_data <- data[!row.has.na,]
head(final_data)
data <- final_data
# for each type of state in the data - created a report
# these reports are saved in output_dir with the name specified by output_file
for (state in unique(data$STATE)){
if (state == "ANDHRA PRADESH" || state == "ASSAM" || state == "GOA" || state == "HIMACHAL PRADESH" || state == "KERALA" || state == "MAHARASHTRA" || state == "ODISHA" || state == "RAJASTHAN" || state == "UTTAR PRADESH" || state == "WEST BENGAL")
rmarkdown::render('C:/Users/vanes/Documents/Report/State-wise.Rmd', # file 2
output_file = paste("report_", state, '_', Sys.Date(), ".html", sep=''),
output_dir = 'C:/Users/vanes/Documents/Report/States')
}