bash 쉘을 사용할 수있는 경우 bash 스크립트 내에서 R 코드를 실행하고 stdout 및 stderr 스트림을 파일로 파이프하는 것을 고려할 수 있습니다. heredoc를 사용한 예는 다음과 같습니다.
파일: test.sh
echo "Hello World, this is bash"
test1=$(echo "This is a test")
echo "Here is some R code:"
Rscript --slave --no-save --no-restore - "$test1" <<EOF
cat("\nHello World, this is R\n")
args <- commandArgs(TRUE)
bash_message<-args[1]
cat("\nThis is a message from bash:\n")
cat("\n",paste0(bash_message),"\n")
EOF
그런 다음 로그 파일에 파이프 된 stderr 및 stdout을 모두 사용하여 스크립트를 실행할 때 :
$ chmod +x test.sh
$ ./test.sh
$ ./test.sh &>test.log
$ cat test.log
Hello World, this is bash
Here is some R code:
Hello World, this is R
This is a message from bash:
This is a test
이를 위해 살펴볼 다른 사항은 R heredoc에서 stdout과 stderr를 로그 파일로 바로 파이핑하는 것입니다. 나는 이것을 아직 시도하지 않았지만 아마도 작동 할 것입니다.