Why do some datasets need us to do `data(somedataset)` before we can use them?
dataset, lazy-loading, package, r
Solution
R includes a range of datasets, mainly for use in examples. Some of these datasets are directly available (e.g. `iris` or `cars`), in some packages they are not automatically available requiring a call to `data` to attach them to the current workspace, e.g. `meuse` from the `gstat` package. So you experience in `ElemStatLearn` is valid, `spam` is automatically available.
Problem
Why do we have to use `data(spam)` before we can run `lda` on it ? `spam` is a dataset in the `ElemsStatLearn` package. ``` library(ElemStatLearn) library(MASS) # for lda spam[5] # is ok spam.lda = lda(spam ~ . , data = spam) # not ok data(spam) spam.lda = lda(spam ~ . , data = spam) # ok ``` We can access `spam[5]` even before we run `data(spam)`.