-1

I'm missing something very basic here. I want to retrieve saved .RData using load command but could not figured out it.

X <- seq(from=1, 10, by=1)
Y <- seq(from=1, 20, by=2)
df1 <- data.frame(X, Y)
df1

save(object=df1, file = "mdf.RData")
load(file = "mdf.RData")
mdf

Error: object 'mdf' not found

load(file = "mdf.RData", .GlobalEnv)
mdf

Error: object 'mdf' not found
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
  • 1
    The object you saved was `df1`. That's the object that gets loaded when you run `load(file = "mdf.RData")`. So do `rm(df1); load(file = "mdf.RData"); df1`. – eipi10 Oct 17 '15 at 16:29
  • 1
    Another option is `saveRDS` which you can use to just save a single object. `saveRDS(df1, "mdf.rds"); mdf = readRDS("mdf.rds")`. When you do it this way, you can assign the object to a new name when you load it into your workspace. – eipi10 Oct 17 '15 at 16:32

1 Answers1

1

mdf.RData is a file in the hard disk of your computer. The R variable you saved in this file is df1. So after you load(file="mdf.RData"), the R variable df1 will be loaded into R. The right code:

load(file = "mdf.RData")
df1
Ven Yao
  • 3,680
  • 2
  • 27
  • 42