Sometimes this works, sometimes not. It seems to depend on whether the system needs to prompt for a password. The more general question would be: is there a way for the user to provide input to a shell command from within R?
system('sudo npm install gitbook -g')
Note that my specific case is trying to install a node.js module. However, I think you can replicate it using a more trivial command.
system('sudo mkdir testdir')
Please note that this will sometimes work depending on whether sudo
requires you to re-enter a password. Thanks.