R .Last.call feature - similar to .Last.value -
similarly .last.value there way access last call? below expected results of potential .last.call.
sum(1, 2) # [1] 3 str(.last.call) # language sum(1, 2) the bests if not require parse file file system.
the last.call package no longer on cran, can still code:
# ----------------------------------------------------------------------- # function: last.call # retrieves call history , returns unevaluated # call. # # there 2 uses such abilities. # - able recall previous commands, pressing key # on terminal. # - ability line called function. # # todo: # - not handle commands seperated ';' # # ----------------------------------------------------------------------- last.call <- function(n=1) { f1 <- tempfile() try( savehistory(f1), silent=true ) try( rawhist <- readlines(f1), silent=true ) unlink(f1) if( exists('rawhist') ) { # max(n)+ lines until have n commands cmds <- expression() n.lines <- max(abs(n)) while( length(cmds) < max(abs(n)) ) { lines <- tail( rawhist, n=n.lines ) try( cmds <- parse( text=lines ), silent=true ) n.lines <- n.lines + 1 if( n.lines > length(rawhist) ) break } ret <- rev(cmds)[n] if( length(ret) == 1 ) return(ret[[1]]) else return(ret) } return(null) } now, use it:
sum(1, 2) # [1] 3 last.call(2) # sum(1, 2)
Comments
Post a Comment