当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R dbplyr lahman 缓存并检索 Lahman 棒球数据库的 src_sqlite。


这将使用来自 Lahman 棒球数据源的数据创建一个有趣的数据库,该数据源由 Sean Lahman 提供,位于http://seanlahman.com/download-baseball-database/,并且可以通过以下方式轻松地在 R 中使用拉赫曼迈克尔·弗兰德利、丹尼斯·墨菲和马丁·蒙克曼的作品集。有关各个表的文档,请参阅该包的文档。

用法

lahman_sqlite(path = NULL)

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

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

copy_lahman(con, ...)

has_lahman(type, ...)

lahman_srcs(..., quiet = NULL)

参数

...

其他参数在首次加载时传递给src。对于 MySQL 和 PostgreSQL,默认情况下假设您有一个本地服务器,并且已经创建了 lahman 数据库。对于 lahman_srcs() ,提供要生成的 src 的名称的字符向量。

type

源代码类型。

quiet

如果是 TRUE ,则禁止显示有关数据库连接失败的消息。

例子

# Connect to a local sqlite database, if already created
# \donttest{
library(dplyr)

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: FieldingOFsplit
#> Creating table: FieldingPost
#> Creating table: HallOfFame
#> Creating table: HomeGames
#> Creating table: LahmanData
#> Creating table: Managers
#> Creating table: ManagersHalf
#> Creating table: Parks
#> Creating table: People
#> 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.41.2 [/tmp/Rtmp5JwGfx/lahman.sqlite]
#>    playerID  yearID stint teamID lgID      G    AB     R     H   X2B   X3B
#>    <chr>      <int> <int> <chr>  <chr> <int> <int> <int> <int> <int> <int>
#>  1 abercda01   1871     1 TRO    NA        1     4     0     0     0     0
#>  2 addybo01    1871     1 RC1    NA       25   118    30    32     6     0
#>  3 allisar01   1871     1 CL1    NA       29   137    28    40     4     5
#>  4 allisdo01   1871     1 WS3    NA       27   133    28    44    10     2
#>  5 ansonca01   1871     1 RC1    NA       25   120    29    39    11     3
#>  6 armstbo01   1871     1 FW1    NA       12    49     9    11     2     1
#>  7 barkeal01   1871     1 RC1    NA        1     4     0     1     0     0
#>  8 barnero01   1871     1 BS1    NA       31   157    66    63    10     9
#>  9 barrebi01   1871     1 FW1    NA        1     5     1     1     1     0
#> 10 barrofr01   1871     1 BS1    NA       18    86    13    13     2     1
#> # ℹ more rows
#> # ℹ 11 more variables: HR <int>, 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: connection to server at "localhost" (::1), port 5432 failed: Connection refused
#> 	Is the server running on that host and accepting TCP/IP connections?
#> connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
#> 	Is the server running on that host and accepting TCP/IP connections?
# }
源代码:R/data-lahman.R

相关用法


注:本文由纯净天空筛选整理自Hadley Wickham等大神的英文原创作品 Cache and retrieve an src_sqlite of the Lahman baseball database.。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。