You can save objects from drowning in the console using .Last.Value . See the following example.
sum(c(2,2,3,4)) #[1] 11 y <- .Last.value y #[1] 11
We learn from ?.Last.Value that
The internal evaluation value of the top-level R expression is always assigned .Last.Value (in package:base ) before further processing (for example, printing).
This also works for functions:
function(x){ sqrt(x) } .Last.value
An interesting note from lmo in the comments:
As an additional note, RStudio users can see this value in their environment panel by going to Tools > Global Options > General , and then select the "Show .Last.value in the environment list" checkbox
loki
source share