[R] Multiple line commands in R scripting

Neil Stewart neil.stewart at warwick.ac.uk
Sun Oct 25 13:53:37 CET 2009


I'm wondering whether there is a character to let R know to expect more
input for a command on subsequent lines. Here is an example:

test_1.R:
x <- c(1,2,3,4)
    / c(1,2,3,4)
x

R CMD BATCh test_1.R produces test_1.Rout:
> x <- c(1,2,3,4)
>   / c(1,2,3,4)
Error: unexpected '/' in "  /"
Execution halted


test_2.R:
x <- c(1,2,3,4) /
    c(1,2,3,4)
x

R CMD BATCh test_1.R produces test_2.Rout:
> x <- c(1,2,3,4) /
+   c(1,2,3,4)
> x
[1] 1 1 1 1

test_2.R works as expected but test_1.R fails because the "/" operator is at
the start of line 2 not the end of line 1.

Is the some kind of continuation charater one can include in a script so R
is expecting input on the next line? For example, in other languages, "\"
works. Without this, one is forced to break lines carefully in the middle of
a function, for example, to ensure R is expecting more. Any comments very
welcome.

Thank you,
Neil.




More information about the R-help mailing list