R: Using system command to move all files in a folder except one in MacOS
<p>I am trying to move files using R through the system command.  But I am unable to do so. Any insights on why would help. I know it is a convoluted way of doing it...  But i was curious and decided to try this through R. (It works through the command line directly.)</p>

<p>I tried both the system and system2 command. The command will execute the following: Move all files in the directory except <code>zplots</code> into the <code>./Resfiles</code> directory. </p>

<pre><code>system('shopt -s extglob')
system('mv !(zplots) ./Resfiles')
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `mv !(zplots) ./Resfiles'

system2('mv !(zplots) ./Resfiles')
sh: mv -r !(zplots) ./Resfiles: No such file or directory
</code></pre>