Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant Andersen committed Mar 23, 2019
0 parents commit 1c82c33
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
58 changes: 58 additions & 0 deletions lahman_etl.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require(DBI)
require(readr)
require(dplyr)


tables <- c('AllstarFull',
'Appearances',
'AwardsManagers',
'AwardsPlayers',
'AwardsShareManagers',
'AwardsSharePlayers',
'Batting',
'BattingPost',
'CollegePlaying',
'Fielding',
'FieldingOF',
'FieldingOFsplit',
'FieldingPost',
'HallOfFame',
'HomeGames',
'Managers',
'ManagersHalf',
'Parks',
'People',
'Pitching',
'PitchingPost',
'Salaries',
'Schools',
'SeriesPost',
'Teams',
'TeamsFranchises',
'TeamsHalf')

foo<-dbConnect(MySQL(), host="localhost", dbname="lahman",user="root",port=3306)

y=Sys.time()
for (t in tables) {
print(t)
if (t != "AwardsSharePlayers"){
a <- read_csv(paste0("https://github.com/chadwickbureau/baseballdatabank/raw/master/core/",
t,
".csv"))
} else {
a <- read_csv(paste0("https://github.com/chadwickbureau/baseballdatabank/raw/master/core/",
t,
".csv"),col_names = c("awardID","yearID","lgID","playerID",
"pointsWon","pointsMax","votesFirst"),
skip=1,
col_types = "ciccdid")
}

dbSendQuery(foo, paste0("drop table if exists ",t,";"))
dbWriteTable(foo, name=t, value=a %>% as.data.frame(a))

}
Sys.time()-y

dbDisconnect(foo)
13 changes: 13 additions & 0 deletions lahman_etl.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

0 comments on commit 1c82c33

Please sign in to comment.