This creates an interesting database using data from the Lahman baseball data source, provided by Sean Lahman at http://www.seanlahman.com/baseball-archive/statistics/, and made easily available in R through the Lahman package by Michael Friendly, Dennis Murphy and Martin Monkman. See the documentation for that package for documentation of the inidividual tables.

lahman_sqlite(path = NULL)

lahman_postgres(dbname = "lahman", host = "localhost", ...)

lahman_mysql(dbname = "lahman", ...)

lahman_df()

copy_lahman(src, ...)

has_lahman(type, ...)

lahman_srcs(..., quiet = NULL)

Arguments

...

Other arguments passed to src on first load. For mysql and postgresql, the defaults assume you have a local server with lahman database already created. For lahman_srcs(), character vector of names giving srcs to generate.

type

src type.

quiet

if TRUE, suppress messages about databases failing to connect.

Examples

# Connect to a local sqlite database, if already created
if (has_lahman("sqlite")) { lahman_sqlite() batting <- tbl(lahman_sqlite(), "Batting") batting }
#> Creating table: AllstarFull
#> Creating table: Appearances
#> Creating table: AwardsManagers
#> Creating table: AwardsPlayers
#> Creating table: AwardsShareManagers
#> Creating table: AwardsSharePlayers
#> Creating table: Batting
#> Creating table: BattingPost
#> Creating table: CollegePlaying
#> Creating table: Fielding
#> Creating table: FieldingOF
#> Creating table: FieldingPost
#> Creating table: HallOfFame
#> Creating table: LahmanData
#> Creating table: Managers
#> Creating table: ManagersHalf
#> Creating table: Master
#> Creating table: Pitching
#> Creating table: PitchingPost
#> Creating table: Salaries
#> Creating table: Schools
#> Creating table: SeriesPost
#> Creating table: Teams
#> Creating table: TeamsFranchises
#> Creating table: TeamsHalf
#> # Source: table<Batting> [?? x 22] #> # Database: sqlite 3.22.0 [/tmp/RtmpMBy62n/lahman.sqlite] #> playerID yearID stint teamID lgID G AB R H X2B X3B HR #> <chr> <int> <int> <chr> <chr> <int> <int> <int> <int> <int> <int> <int> #> 1 abercda… 1871 1 TRO NA 1 4 0 0 0 0 0 #> 2 addybo01 1871 1 RC1 NA 25 118 30 32 6 0 0 #> 3 allisar… 1871 1 CL1 NA 29 137 28 40 4 5 0 #> 4 allisdo… 1871 1 WS3 NA 27 133 28 44 10 2 2 #> 5 ansonca… 1871 1 RC1 NA 25 120 29 39 11 3 0 #> 6 armstbo… 1871 1 FW1 NA 12 49 9 11 2 1 0 #> 7 barkeal… 1871 1 RC1 NA 1 4 0 1 0 0 0 #> 8 barnero… 1871 1 BS1 NA 31 157 66 63 10 9 0 #> 9 barrebi… 1871 1 FW1 NA 1 5 1 1 1 0 0 #> 10 barrofr… 1871 1 BS1 NA 18 86 13 13 2 1 0 #> # … with more rows, and 10 more variables: RBI <int>, SB <int>, CS <int>, #> # BB <int>, SO <int>, IBB <int>, HBP <int>, SH <int>, SF <int>, GIDP <int>
# Connect to a local postgres database with lahman database, if available if (has_lahman("postgres")) { lahman_postgres() batting <- tbl(lahman_postgres(), "Batting") }
#> Error: RS-DBI driver: (could not connect postgres@localhost:5432 on dbname "lahman": FATAL: database "lahman" does not exist #> )