Import data into R: Overwritten object names

Spotting the problem

First, I create a small dataset for the demonstration. The following dataset represents the Happiness index for five countries.

happy <- data.frame(
  country = c("Finland", "Norway", "Denmark", "Iceland", "Netherlands"),
  score = c(7.76, 7.60, 7.55, 7.49, 7.48))

happy
      country score
1     Finland  7.76
2      Norway  7.60
3     Denmark  7.55
4     Iceland  7.49
5 Netherlands  7.48

Save the dataset as shown below.

save(happy, file="happyindex.rda")

Let’s load the dataset with,

load("happyindex.rda")
happyindex

The following error message pops up,

Error: object ‘happyindex’ not found

Tackling the problem

loadHappy <- load("happyindex.rda")
happyDataloaded <- get(loadHappy)
happyDataloaded

Related