Hi, I am writing a custom reader function that should read from a connection
and execute each line on the connection in a separate process. It turned out
to be quite simple, but I have problems to restore the standard reader back
when I am done.
Here are the details. I have a function myReader(con), which does nothing
but evaluates next line on a connection. When it encounters "q()" in the
input line it resets the connection back to the standardReader.
"myReader" <-
function(con)
{
x <- readLines(con)
if(x == "q()") {
setReader(con, standardReader)
}
else {
print(eval(parse(text = x)))
cat("my> ") # custom prompt
}
}
And here is a sample annotated session:
Version 5.1 Release 1 for Sun SPARC, SunOS 5.5 : 1999
Working data will be in .Data
> setReader(stdin(), myReader)
[1] 1
> showReaders()
Tag Connection Class Action
1 /dev/tty terminal myReader
NULL
my> q()
# here I had to hit RETURN a couple of times before I got the prompt
> seq(1)
# notice that the output appears AFTER the prompt
> [1] 1
seq(1)
> [1] 1
My feeling that setting the stdin() to the standard reader did not go clean.
There are some other side effects that show up in S-mode under Emacs.
Any suggestion?
Thanks,
Vadim
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|