shell(cmd, shell, flag = "/c", intern = FALSE, wait = TRUE, translate = FALSE, mustWork = FALSE, ...)
cmd | a character string giving the command to be invoked. |
shell | a character string giving the shell to invoke cmd. If it is missing, the environment variable "SHELL"(if defined) or "COMSPEC"(if defined) will be used. |
flag | a character string giving the flag of a shell command. The default is "/c" in Windows OS platform, or "-c" for Unix shell "bash", "tcsh", or "sh". |
intern | a logical value. If TRUE, the output of command is returned visibly. If FALSE (the default), the output of command is returned invisibly when command is run successfully, or an error or warning is given when command is run with fail. |
wait | a logical value. If TRUE (the default), the cmd is run in synchronous mode and system is not returned until cmd completes. If FALSE, the cmd is run in asynchronous mode. This option is useful when you want to use the engine and the application (command invoked) concurrently. If intern is TRUE, this argument is ignored and cmd is always run in "wait" mode. |
translate | a logical value to indicate if translate character "/" to "\" in the string of cmd. The default is FALSE. |
mustWork | a logical value or NA. This argument is ignored if intern is TRUE or cmd is run successfully. It defines the behavior when the command is run with fail: if TRUE, the function will be stopped with error message; if FALSE, the function won't stopped but with warning message; if NA, no any error or warning message is given. |
... | other optional arguments pass to system function. |
## Not run: # Windows examples: ret <- shell("dir") ret # 0 ret <- shell("dir", intern = TRUE) ret # character vector contains the result of "dir" command.ret <- shell("mycmd", mustWork = TRUE) ## Error in shell("mycmd", mustWork = TRUE) : ## 'mycmd' execution failed with error code 1
# Run notepad in "wait" mode. shell("Notepad abc.txt")
# Run notepad concurrently shell("Notepad", wait = FALSE)
shell("c:/windows/system32/Notepad", translate = TRUE) ## End(Not run)