I need to check the exit status of a piped command from R on Debian, like here, but cannot make run echo "${pipestatus[1]}"
successfully from R using system2
/system
function. The command works properly when I use command line.
The command I am trying to use in R can look like this (the shell I use is zsh):
system2("false", args = "|true;echo '${pipestatus[1]}'")
After some testing I can see that the exit status checking command cannot be quoted properly but I cannot figure out the correct way to do so.
Am I right that quoting this command properly is the issue? How to run this (echo "${pipestatus[1]}"
) command from R? Are there any alternatives to using the command in question to check exit status?
You can’t use zsh features here, since system2
doesn’t invoke a shell.
Instead, you’ll either need to use a raw system
call or, better, explicitly invoke the shell in system2
. You’ll also need to use double quotes instead of single quotes around ${pipestatus[1]}
to allow expansion — otherwise zsh will interpret it as a literal string.
system2('zsh', c('-c', shQuote('false|true; echo "${pipestatus[1]}"')))