I can\'t find something to the effect of an undo command in R (neither on An Introduction to R nor in R in a Nutshell). I am particularly interested in undoing/deleting when
You should consider a different approach which leads to reproducible work:
All this works tremendously well in ESS which is why many experienced R users like this environment. But editors are a subjective and personal choice; other people like Eclipse with StatET better. There are other solutions for Mac OS X and Windows too, and all this has been discussed countless times before here on SO and on other places like the R lists.
In general I do adopt Dirk's strategy. You should aim for your code to be a completely reproducible record of how you have transformed your raw data into output.
However, if you have complex code it can take a long time to re-run it all. I've had code that takes over 30 minutes to process the data (i.e., import, transform, merge, etc.). In these cases, a single data-destroying line of code would require me to wait 30 minutes to restore my workspace. By data destroying code I mean things like:
x <- merge(x, y)
df$x <- df$x^2
e.g., merges, replacing an existing variable with a transformation, removing rows or columns, and so on. In these cases, it's easy, especially when first learning R to make a mistake.
To avoid having to wait this 30 minutes, I adopt several strategies:
temp <- merge(x, y);
check that it worked str(temp); head(temp); tail(temp)
and if everything looks good x <- merge(x, y)
save(x, y, z , file = 'backup.Rdata')
That way, If I make a mistake, I only have to reload these objects. df$x <- NULL
is a handy way of removing a variable in a data frame that you did not want to createHowever, in the end I still run all the code from scratch to check that the result is reproducible.