0

I have a few large datasets say fam1997,fam1998,fam1999. When I load for example

load("fam1997")

it returns a data frame called x. Even when I instead use

fam1997 <- load("fam1997")

then

print(fam1997)

it still returns "x"

I don't know why. Is this a bug in load()? or I missed some points? This is quite annoying when I want to load multiple data sets at the same time.

sindri_baldur
  • 25,109
  • 3
  • 30
  • 57
tobinz
  • 175
  • 6
  • Read [`?load`](https://stat.ethz.ch/R-manual/R-devel/library/base/html/load.html), where it states that it returns *"A character vector of the names of objects created, invisibly."* `load` works primarily in side-effect, loading its variables into an environment (defaults to the `.GlobalEnv`). So instead of looking at `fam1997`, look at `x` (since that's what it appears to be loading). – r2evans Mar 17 '21 at 13:33
  • If you want to load raw data directly into a variable like that, you have two options: (1) save a single variable with `saveRDS` and load with `fam1997 – r2evans Mar 17 '21 at 13:35
  • Bottom line, this is not a bug in `load`, it is operating as it was designed to do: in side-effect. Realize that `.rda` files can contain more than one object; if it contained two frames `x` and `y`, what would you expect `fam1997 – r2evans Mar 17 '21 at 13:42
  • Related: https://stackoverflow.com/q/21370132/3358272 – r2evans Mar 17 '21 at 13:45
  • 1
    Thanks! It makes sense! – tobinz Mar 17 '21 at 14:05

0 Answers0