Here are some related discussions. But I don't think the answers are relevant to my question.
Piping Rscript gives error after output
Normal linux commands work just fine upon receiving SIGPIPE
$ seq 10 |head -n 1
1
But Rscript behaves differently as shown in the above discussion URL. But littler's r does not have this problem.
Is there a way to make Rscript use the default SIGPIPE handler so that it will have a similar behavior to other linux programs?
Here mentions how to set it a the C level? But is there a way to set so in R code? Thanks.
https://colinfay.me/writing-r-extensions/linking-guis-and-other-front-ends-to-r.html
You may also want to consider how signals are handled: R sets signal handlers for several signals, including SIGINT, SIGSEGV, SIGPIPE, SIGUSR1 and SIGUSR2, but these can all be suppressed by setting the variable R_SignalHandlers (declared in Rinterface.h) to 0.