To R-helpers,

Running
  R version 2.10.0 (2009-10-26)
  Linux ... 2.6.25.20-0.5-default #1 SMP 2009-08-14 01:48:11 +0200 x86_64 
x86_64 x86_64 GNU/Linux
  openSUSE 11.0 (X86-64)
and having difficulties reading a fifo from within R.

A short example that I find simply haning is shown as 'SHORT SCRIPT' below. I expected R to print a data set read from the fifo with the numbers 0,1,...7 and then gracefully exit. Any ideas why not?

A longer script that actually does the job in its 2nd clause is shown in 'LONG SCRIPT' below ... I'm confused that the open call is needed. Any comments on this?

Regards MJ

--- SHORT SCRIPT BEGIN
#!/bin/bash

mkfifo chops
gawk 'BEGIN {for (i=0;i<8;i++){print i}}' > chops &

R --slave --no-save <<EOF
print ("Hello from R")
con.data <- read.table ("chops")
con.data
EOF

unlink chops
--- SHORT SCRIPT END


--- LONG SCRIPT BEGIN
#!/bin/bash

DO_1st=no
DO_2nd=yes
DO_3rd=yes

# 1 Hoped for this to work but fails
if [[ $DO_1st =~ [yY][eE][sS] ]] ; then

  echo "With R 1"
  mkfifo chops
  gawk 'BEGIN {for (i=0;i<8;i++){print i}}' > chops &

  R --slave --no-save <<EOF
print ("Hello from R 1")
con.data <- read.table ("chops")
con.data
EOF
  unlink chops

fi

# 2 Works but with an unexpected open call
if [[ $DO_2nd =~ [yY][eE][sS] ]] ; then

  echo "With R 2"
  mkfifo chops
  gawk 'BEGIN {for (i=0;i<8;i++){print i}}' > chops &

  R --slave --no-save <<EOF
print ("Hello from R 2")
theFifo <- fifo(description="chops", open="read")
open(theFifo)  # without this read.table raises error of no lines available
con.data <- read.table (theFifo)
close(theFifo)
con.data
EOF
  unlink chops

fi

# 3 Works - just for reference
if [[ $DO_3rd =~ [yY][eE][sS] ]] ; then

  echo "With cat"
  mkfifo chops
  gawk 'BEGIN {for (i=0;i<8;i++){print i}}' > chops &
  cat chops
  unlink chops

fi
--- LONG SCRIPT END

______________________________________________
R-help@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.

Reply via email to