Katelynn ruan
Katelynn ruan

Reputation: 332

Rscript does not support newline?

I try to incorporate R script in bash script like

  #!/bin/bash
  ...some bash command
  Rscript -e 'a=1;
  print(a)';

but it complain

ARGUMENT 'print(a)' __ignored__

How to include newline in Rscript?

Upvotes: 1

Views: 202

Answers (2)

flodel
flodel

Reputation: 89097

I also think the best approach would be to write a R script. With that in mind, you can create one in cache: just replace -e 'code' with <(echo 'code'):

Rscript <(echo 'a=1;
  print(a);')

Upvotes: 1

IRTFM
IRTFM

Reputation: 263481

I was able to get what I think is the desired behavior with:

 Rscript -e 'print(123)' -e '
         print(234)'

So using the -e flag repeatedly and the second argument being incomplete by virtue of the leading single quote. Repeated lines are possible:

Rscript -e 'print(123)' -e '
print(234)' -e '
a=2222222' -e '
print(a)'
##------ 2013-02-11 ------##
[1] 123
[1] 234
[1] 2222222

Upvotes: 1

Related Questions