2

I have an RData "E.g.RData" I loaded it into R console using the load function.

load("E.g.RData")

it has a variable e.g. in RData. I am doing like this -

e <- load("E.g.RData")

then e gets the character vector as "e.g." but I want the contents of e.g. into e.

Is there a way to do it in R?

user1021713
  • 2,133
  • 8
  • 27
  • 40

3 Answers3

3

This can be done using:

y <- get(load("path/E.g.RData"))

y will contain the contents of the e.g. variable.

user1021713
  • 2,133
  • 8
  • 27
  • 40
3

Yeah, the problem is that E.g maintains its name during the saving of the object. You could try assigning the new name "e" to the E.g. object and then remove the E.g. object:

E.g <- runif(100)
save(E.g, file="E.g.Rdata")
load("E.g.Rdata")
assign("e", E.g)
rm(E.g)
Marc in the box
  • 11,769
  • 4
  • 47
  • 97
1

Rather than using the load function with its defaults, which overwrites anything of the same name in the global workspace, you may prefer to use attach to attach the workspace, then copy just the object(s) of interest with the names you want, then detach the workspace.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110