How to get the result if you forgot to name a function or object

I have a very large function that takes several hours to give me the result. I forgot to call it. Is there a way to show the result of my function?

Thanks in advance.

+8
variable-assignment r assign
source share
1 answer

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 # function(x){ # sqrt(x) # } 

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

+18
source share

All Articles