1

So, I'm trying to reproduce the example here

So the first three examples:

echo 'cat(pi^2,"\n")' | r

and

r -e 'cat(pi^2, "\n")'

and

ls -l /boot | awk '!/^total/ {print $5}' | \
             r -e 'fsizes <- as.integer(readLines());
                print(summary(fsizes)); stem(fsizes)'

work great. The third one:

$ cat examples/fsizes.r
        #!/usr/bin/env r

        fsizes <- as.integer(readLines())
        print(summary(fsizes))
        stem(fsizes)

How do you run this? Sorry for the dumb question I am no bash guru...

MrFlick
  • 195,160
  • 17
  • 277
  • 295
user189035
  • 5,589
  • 13
  • 52
  • 112

1 Answers1

2

If the file is in examples/fsizes.r, then make it executable:

chmod +x examples/fsizes.r

And then run it with:

./examples/fsizes.r

The script expects input, one integer per line. When you run it, you can enter line by line, and press control-d to end the input. Or, you can create a file with numbers, and use input redirection, for example:

./examples/fsizes.r < input.txt
janos
  • 120,954
  • 29
  • 226
  • 236
  • But *how* do you make them work? Do you copy that script somewhere? How do you launch it? For example, for that script, what are the incantations? – user189035 Oct 17 '15 at 08:40
  • But this is not an R script, it is a littler script. Is it the same? – user189035 Oct 17 '15 at 08:47
  • Littler can do things rscript can't which is why I'm trying to learn to use it. But this is beside the point. So does it mean I have to substitute the shebang at the top of your script by the one they use? – user189035 Oct 17 '15 at 08:54
  • Ok. It launches now, but it does nothing~ Have you been able to get it to do anything? – user189035 Oct 17 '15 at 10:21
  • The script expects input, one integer per line. When you run it, you can enter line by line, and press control d to end the input. Or, you can create a file with numbers, and use input redirection. Does this answer your question, or did you mean something else? – janos Oct 17 '15 at 11:05
  • It's perfect now! Thanks! (I'm starting from a very low base) – user189035 Oct 17 '15 at 13:15
  • 1
    @user189035 You **quote** the example for launching it: `ls -l /boot | awk '!/^total/ {print $5}'` produces output which the script then consumes. This obviously assumes you have a directory `/boot` as most Linux systems would. – Dirk Eddelbuettel Oct 17 '15 at 13:49
  • @DirkEddelbuettel: yes, thanks for the help here and at the other question. As I said, I'm really starting from a low base. I am not a programmer and my package is, as you put it, taken hostage by a CRAN bug report which I don't understand. Trying to fix those leaks with very little knowledge and in high seas! – user189035 Oct 18 '15 at 08:32