Can't find the Dataset Boston in MASS

I am trying to load Boston into the environment from package MASS. For some reason, it keeps telling me there's no such data. I have tried:

library(MASS)
data(Boston)

library(MASS)
boston <- Boston
dim(boston)

The result is NULL

I downloaded the newest version of R-studio.

Could anyone help me with this problem? Thank you.

Weird works fine for me. Maybe trying reinstalling MASS?

library(MASS)
boston <- Boston
dim(boston)
#> [1] 506  14

Created on 2018-10-10 by the reprex package (v0.2.1)

I have redownloaded it, but still not working.

Well that's about the extent of my troubleshooting knowledge. For the sake of others, can you post the output of sessionInfo()

The data() function doesn't return a loaded object. It loads the objects into your environment, assigns it the predetermined name, and then returns a character vector of the name(s).

So Boston <- data(Boston) does the following:

  1. data(Boston) loads the dataset and assigns it to the Boston variable. Then it returns the vector "Boston".
  2. Boston <- ... takes that character vector and assigns it to the Boston variable, replacing the dataset with "Boston".

If you just use data(Boston) as it's own line, it'll work how you want.

Both:
library(MASS)
Boston <- Boston
dim(Boston)

library(MASS)
Boston <- "Boston"
dim(Boston)

return to Null

If dim(Boston) returns NULL, that means the Boston object already exists. Otherwise, you'd get an error. Because there's a local version, R uses that instead of looking into any attached packages.

Restart your R session (CTRL + SHIFT + F10) and try it again.

1 Like

Thank you so much for the help!