Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.A41.4.61b.0411081452410.249440@homer11.u.washington.edu>
Date: 2004-11-08T22:58:57Z
From: Thomas Lumley
Subject: can one evaluate an expression in a comment? (or insert resultsinto history?)
In-Reply-To: <12AE52872B5C5348BE5CF47C707FF53A3277E2@rhosvr02.rhotrading.com>

On Mon, 8 Nov 2004 davidr at rhotrading.com wrote:

> But that doesn't put the result into the history buffer, to be written
> to a file only later when I savehistory(filename).
>
> Bert Gunter also suggested ?capture.output and ?textConnection,
> but I cannot see how to get text into the history buffer as comments,
> but with evaluated expressions (values).

You can cheat by writing out the history to a file, appending to the file, 
then reading the history back in.

> rewriteHistory <- function(comment){
  file1 <- tempfile("Rrawhist")
  on.exit(unlink(file1))
  savehistory(file1)
  conn<-file(file1,open="a")
  writeLines(comment, con=conn)
  close(conn)
  loadhistory(file1)
}

I now can get from history()

rewriteHistory("## 1984-4-12 13:00:00 GMT")
## 1984-4-12 13:00:00 GMT
rewriteHistory("TRUE == FALSE")
TRUE == FALSE

You still get the rewriteHistory() calls, though.


 	-thomas