Running examples in ‘Lahman-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: Batting
> ### Title: Batting table
> ### Aliases: Batting
> ### Keywords: datasets
> 
> ### ** Examples
> 
> data(Batting)
> head(Batting)
   playerID yearID stint teamID lgID  G  AB  R  H X2B X3B HR RBI SB CS BB SO
1 abercda01   1871     1    TRO   NA  1   4  0  0   0   0  0   0  0  0  0  0
2  addybo01   1871     1    RC1   NA 25 118 30 32   6   0  0  13  8  1  4  0
3 allisar01   1871     1    CL1   NA 29 137 28 40   4   5  0  19  3  1  2  5
4 allisdo01   1871     1    WS3   NA 27 133 28 44  10   2  2  27  1  1  0  2
5 ansonca01   1871     1    RC1   NA 25 120 29 39  11   3  0  16  6  2  2  1
6 armstbo01   1871     1    FW1   NA 12  49  9 11   2   1  0   5  0  1  0  1
  IBB HBP SH SF GIDP
1  NA  NA NA NA   NA
2  NA  NA NA NA   NA
3  NA  NA NA NA   NA
4  NA  NA NA NA   NA
5  NA  NA NA NA   NA
6  NA  NA NA NA   NA
> require("dplyr")
Loading required package: dplyr

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

> 
> ## Prelude: Extract information from Salaries and Master
> ## to be merged with the batting data.
> 
> # Subset of Salaries data
> salaries <- Salaries %>%
+               select(playerID, yearID, teamID, salary)
> 
> # Subset of Master table (player metadata)
> masterInfo <- Master %>%
+               select(playerID, birthYear, birthMonth, nameLast,
+                      nameFirst, bats)
> 
> # Left join salaries and masterInfo to batting data,
> # create an age variable and sort by playerID, yearID and stint
> # Returns an ignorable warning.
> batting <- battingStats() %>% 
+              left_join(salaries, 
+                        by =c("playerID", "yearID", "teamID")) %>%
+              left_join(masterInfo, by = "playerID") %>%
+              mutate(age = yearID - birthYear - 
+                             1L *(birthMonth >= 10)) %>%
+              arrange(playerID, yearID, stint)
Warning: Column `teamID` joining factors with different levels, coercing to character vector
> 
> ## Generate a ggplot similar to the NYT graph in the story about Ted
> ## Williams and the last .400 MLB season 
> # http://www.nytimes.com/interactive/2011/09/18/sports/baseball/WILLIAMS-GRAPHIC.html
> 
> # Restrict the pool of eligible players to the years after 1899 and
> # players with a minimum of 450 plate appearances (this covers the
> # strike year of 1994 when Tony Gwynn hit .394 before play was suspended
> # for the season - in a normal year, the minimum number of plate appearances is 502)
> 
> eligibleHitters <- batting %>%
+                      filter(yearID >= 1900 & PA > 450)
> 
> # Find the hitters with the highest BA in MLB each year (there are a
> # few ties).  Include all players with BA > .400, whether they
> # won a batting title or not, and add an indicator variable for
> # .400 average in a season.
> 
> topHitters <- eligibleHitters %>%
+                  group_by(yearID) %>%
+                  filter(BA == max(BA)| BA >= .400) %>%
+                  mutate(ba400 = BA >= 0.400) %>%
+                  select(playerID, yearID, nameLast, 
+                         nameFirst, BA, ba400)
> 
> # Sub-data frame for the .400 hitters plus the outliers after 1950
> # (averages above .380) - used to produce labels in the plot below
> bignames <- topHitters %>%
+               filter(ba400 | (yearID > 1950 & BA > 0.380)) %>%
+               arrange(desc(BA))
> 
> # Variable to provide a vertical offset to certain
> # labels in the ggplot below
> bignames$yoffset <-  c(0, 0, 0, 0, 0.002, 0, 0, 0,
+                        0.001, -0.001, 0, -0.002, 0, 0,
+                        0.002, 0, 0)
> 
> # Produce the plot
> 
> require("ggplot2")                               
Loading required package: ggplot2
Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘ggplot2’
> ggplot(topHitters, aes(x = yearID, y = BA)) +
+   geom_point(aes(colour = ba400), size = 2.5) +
+   geom_hline(yintercept = 0.400, size = 1, colour = "gray70") +
+   geom_text(data = bignames, aes(y = BA + yoffset,
+                                  label = nameLast), 
+                              size = 3, hjust = 1.2) +
+   scale_colour_manual(values = c("FALSE" = "black", "TRUE" = "red")) +
+   xlim(1899, 2015) +
+   xlab("Year") +
+   scale_y_continuous("Batting average",
+                      limits = c(0.330, 0.430),
+                      breaks = seq(0.34, 0.42, by = 0.02),
+                      labels = c(".340", ".360", ".380", ".400", ".420")) +
+   geom_smooth() +
+   theme(legend.position = "none")
Error in ggplot(topHitters, aes(x = yearID, y = BA)) : 
  could not find function "ggplot"
Execution halted