29

In matlab, you can re-use the result of the (non affected) preceding calculous: it is stored in variable ans. Does R has something equivalent ?

robin girard
  • 561
  • 1
  • 7
  • 13
  • You are right. I did not notice that. I guess I went with the popularity of the question which apparently misled me. No harm done though. Duplicated questions act as reference. There is no problem in having your question duped. People even answer dupes and then close them. However, If you want I can reverse this and dupe the other one instead. – Sotos Jan 04 '18 at 17:01
  • 1
    Thanks Sotos, no that's fine ! not a big deal if it is still referenced. – robin girard Jan 08 '18 at 09:39

2 Answers2

46
.Last.value

See also this and this

gd047
  • 29,749
  • 18
  • 107
  • 146
  • 2
    I find typing this to be time consuming and hard to remember, are there any ways to change this or create a macro that is shorter, perhaps even use _ans_? – mindless.panda Nov 29 '11 at 22:51
  • 5
    in R Studio it's just ".la" tab and it expands to .Last.value. I do know what you mean as it's so easy to use the MATLAB terminal as a play-thing using ans[1] and ans*xyz etc etc. You could try ans <- function(){return(.Last.value)}" in R. then ans() gives you a similar thing. I'm aware this is 7 years too late... – Kushal Jul 06 '17 at 21:05
9

The value of the internal evaluation of a top-level R expression is always assigned to .Last.value before further processing.

rcs
  • 67,191
  • 22
  • 172
  • 153