If you want to routinely apply an R analysis to a lot of separate data files, or provide a repeatable analysis method to other people, an executable R script is a user-friendly way to do so. Instead of you or your user having to call
R and execute your script inside R via
source(.) or a function call, your user may simply call the script itself as if it was a program.
To represent the standard input-/output channels, use the functions
file("stdin") (input from terminal or other program via pipe),
stdout() (standard output) and
stderr() (standard error). Note that while there is the function
stdin(), it can not be used when supplying a ready-made script to R, because it will read the next lines of that script instead of user input.