Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restore default R dataset after edits

Tags:

r

statistics

If I am using a dataset that comes supplied in a package and I accidentally edit it and overwrite some values, how can I restore it back to its original form? Is there a command for this other than unloading the package?

like image 465
runningbirds Avatar asked Feb 12 '23 07:02

runningbirds


1 Answers

Just delete the variable:

library("ISwR")
typeof(alkfos)  # list
alkfos <- 3
typeof(alkfos)  # double
rm(alkfos)
typeof(alkfos)  # list 

This works because of the way R environments are set up: your R_GlobalEnv environment ("global variable environment") is hiding the variables in the library, but they aren't overwritten. Once you clear the variable with the colliding name from your GlobalEnv, the library is again the default result of evaluating that name.

like image 194
Guy Adini Avatar answered Feb 15 '23 10:02

Guy Adini