[R] A shorter version of ".Last.value"?

Gabor Grothendieck ggrothendieck at gmail.com
Mon Jul 7 20:16:08 CEST 2008


Try this:

> makeActiveBinding("ans", function() .Last.value, .GlobalEnv)
NULL
> yy <- 3
> ans
[1] 3


On Mon, Jul 7, 2008 at 2:03 PM, Jon Zadra <zadra at virginia.edu> wrote:
> Hi,
>
> There is an object, ".Last.value" to which the result of the most recent
> evaluation is assigned.  This is similar to "ans" in Matlab.  In Matlab
> "ans" can be very useful and time-saving, but typing the larger R version is
> somewhat clunky and takes away from the usefulness.
>
> Is it possible to reassign '.Last.value' to something simpler, like 'ans' ?
>
> I'm aware of this thread:
> http://tolstoy.newcastle.edu.au/R/help/00b/1598.html, where a function such
> as:
>
> ans <- function() {
>  return(.Last.value)
>  }
>
> is discussed, however it would be nice not to have to type the () every
> time.  Is it possible to change something in R to essentially replace the
> location where ".Last.value" has the recent evaluation assigned to it with
> 'ans' instead?  Or might it be possible to make an object 'ans' that updates
> its value from ".Last.value" each time it is called?
>
> Thanks,
>
> Jon
> --
> Jon Zadra
> Department of Psychology
> University of Virginia
> P.O. Box 400400
> Charlottesville VA 22904
> (434) 982-4744
> email: zadra at virginia.edu
> <http://www.google.com/calendar/embed?src=jzadra%40gmail.com>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list