How to assign the result of the previous expression to a variable?
19,149
.Last.value
is an answer.
It was answered once but you have better title.
Author by
Ryan C. Thompson
Updated on July 12, 2022Comments
-
Ryan C. Thompson almost 2 years
Suppose I'm using R's interactive console, and I've just done something like this:
long_running_command()
That long-running command returns a value, and I've just realized that I wanted to assign that value to a variable instead of discard it. So how can I get that value without running the command again? Is there a command like this?
result = get_last_return_value()
-
Daniel Que over 9 yearsIs there a more concise expression for this, or a way to configure one?
-
Ryan C. Thompson over 9 years
lv <- function() .Last.value
. Then uselv()
to get the last value. -
Paul FREAKN Baker about 7 yearsI like the use of this lambda, but I used
ans
instead oflv
so I could mimic my TI calculator. -
Martin Ueding almost 7 yearsOne could type
.La
and hit the Tab key, that would also work. -
lmo over 6 yearsAs a side note, rstudio users can see this value in their environment panel by going to
Global options > General
and then clicking on the box labelled "Show .Last.value." -
stevec over 4 years
.Last.value
is very cool. Out of interest. Is there a short hand way to call it? I know ruby has the incredibly succinct_
, which does the same as.Last.value
in one character! - extremely convenient. Is there any short hand for.Last.value
?