-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspreadsheet_creation.R
94 lines (80 loc) · 3.46 KB
/
spreadsheet_creation.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
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
library(tidyverse)
library(openxlsx)
message("Running spreadsheet_creation.R")
# setup
nfl_teams <- c("ARI", "ATL", "BAL", "BUF", "CAR", "CHI", "CIN", "CLE",
"DAL", "DEN", "DET", "GB", "HOU", "IND", "JAX", "KC",
"LAC", "LAR", "LV", "MIA", "MIN", "NE", "NO", "NYG",
"NYJ", "PHI", "PIT", "SEA", "SF", "TB", "TEN", "WAS")
df <- read.csv("players_2023.csv")
roster <- read.csv("2024_rosters.csv")
glance <- read.csv("team_stats_2023.csv")
#fix washington
roster <- roster %>%
mutate(team = if_else(team == "WSH", "WAS", team))
# start
wb <- createWorkbook()
for(team_ in nfl_teams){
# 2023 results insertion
team_df <- df %>%
filter(recent_team == team_)%>%
select(-X)
addWorksheet(wb, sheetName = team_)
writeDataTable(wb, sheet = team_, x = team_df, startRow = 1,startCol = 1)
# 2023-24 season at a glance
at_glance <- glance %>%
filter(team == team_)%>%
select(-X)
writeDataTable(wb, sheet = team_, x = at_glance, startRow = 30, startCol = 1)
#template for 2024-25 at a glance
glance_23 <- data.frame(
team = character(),off_yd = numeric(),p_yd = numeric(),car = numeric(),
r_yd = numeric(),r_td = numeric(),p_ff = numeric(),p_att = numeric(),
cmp_pct = numeric(),p_td = numeric(),int = numeric(),fmb = numeric())
writeDataTable(wb, sheet = team_, x = glance_23, startRow = 32, startCol = 1)
#fixing washington
ifelse(team_ == "WAS", "WSH", team_)
# 2024-25 QB's
qb_roster <- roster %>%
filter(team == team_,
POS == "QB")%>%
add_column(g = 0, p_att = 0, cmp = 0, p_yd = 0, p_td = 0, int = 0,
car = 0, r_yd = 0, r_td = 0, tgt = 0, rec = 0, rec_yd = 0,
rec_td = 0, fmb = 0, tp_c = 0, f_ppr = 0, tgt_share = 0,
ypc = 0, ypr = 0, cmp_pct = 0, td_rate = 0, f_custom = 0)%>%
select(-X)
writeDataTable(wb, sheet = team_, x = qb_roster,startRow = 35,startCol = 1)
# 2024-25 RB's
rb_roster <- roster %>%
filter(team == team_,
POS == "RB")%>%
add_column(g = 0, p_att = 0, cmp = 0, p_yd = 0, p_td = 0, int = 0,
car = 0, r_yd = 0, r_td = 0, tgt = 0, rec = 0, rec_yd = 0,
rec_td = 0, fmb = 0, tp_c = 0, f_ppr = 0, tgt_share = 0,
ypc = 0, ypr = 0, cmp_pct = 0, td_rate = 0, f_custom = 0)%>%
select(-X)
writeDataTable(wb, sheet = team_, x = rb_roster,startRow = 45,startCol = 1)
# 2024-25 WR's
wr_roster <- roster %>%
filter(team == team_,
POS == "WR")%>%
add_column(g = 0, p_att = 0, cmp = 0, p_yd = 0, p_td = 0, int = 0,
car = 0, r_yd = 0, r_td = 0, tgt = 0, rec = 0, rec_yd = 0,
rec_td = 0, fmb = 0, tp_c = 0, f_ppr = 0, tgt_share = 0,
ypc = 0, ypr = 0, cmp_pct = 0, td_rate = 0, f_custom = 0)%>%
select(-X)
writeDataTable(wb, sheet = team_, x = wr_roster,startRow = 60,startCol = 1)
# 2024-25 TE's
te_roster <- roster %>%
filter(team == team_,
POS == "TE")%>%
add_column(g = 0, p_att = 0, cmp = 0, p_yd = 0, p_td = 0, int = 0,
car = 0, r_yd = 0, r_td = 0, tgt = 0, rec = 0, rec_yd = 0,
rec_td = 0, fmb = 0, tp_c = 0, f_ppr = 0, tgt_share = 0,
ypc = 0, ypr = 0, cmp_pct = 0, td_rate = 0, f_custom = 0)%>%
select(-X)
writeDataTable(wb, sheet = team_, x = te_roster,startRow = 75,startCol = 1)
}
# Saving the workbook to test_xlsx.xlsx
saveWorkbook(wb, "test_xlsx_aug12.xlsx",overwrite = T)
message("spreadsheet_creation.R complete")