This might also be titled, "How do I use R as a streaming process?"
I would like to use R as a streaming processor, but it seems to have trouble
capturing all the input.
Can someone explain why this script skips the first few lines of input?
Is this a bug in R or some interaction with line buffering on /dev/stdin?
$ R --slave --no-site-file --no-init-file -e
'readLines("/dev/stdin")'> a
> b
> c
> d
> e
> f
> ^D
> [1] "d" "e" "f"
I would use something like 'readLines(stdin())' but stdin() doesn't
seem to
be hooked up to the tty in slave mode (doesn't wait for input).
$ R --slave -e 'readLines(stdin())'> [1] ""
This odd behavior is not limited to slave sessions, and seems to be skipping
a minimum number of characters rather than skipping a certain number of
lines.
$ R --no-site-file --no-init-file -q> > readLines("/dev/stdin")
> a
> b
> c
> d
> e
> f
> g
> ^D
> [1] "d" "e" "f" "g"
> > readLines("/dev/stdin")
> aaaaaaaaaa
> b
> ^D
> [1] "b"
> >
Thanks in advance, -csw
[Thx also to Yihui Xie for helping identify this as a behavior in base R,
not in a package]
----------------
> $ uname -a
> Linux xxxxxx 3.5.0-43-generic #66~precise1-Ubuntu SMP Thu Oct 24 14:52:23
> UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
> $ R --slave --no-site-file --no-init-file -e 'sessionInfo()'
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-unknown-linux-gnu (64-bit)
> locale:
> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
> [9] LC_ADDRESS=C LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
[[alternative HTML version deleted]]