start a process in r

To start a process in R, you can make use of the system() function. This function is used to execute a system command in a shell environment.

Here's an example of starting a process using the system() function:

main.r
# Defining the command to be executed 
command <- "ls -la"

# Starting the process using `system()` function
system(command, intern = TRUE)
140 chars
6 lines

In the above example, we defined a command to be executed (ls -la to list all files and directories in the current working directory) and passed it to the system() function. The intern argument is set to TRUE to capture the output of the command as a character vector.

You can also run a process in the background by appending & to the command:

main.r
# Starting a process in background
command <- "sleep 10 &"
system(command)
75 chars
4 lines

In the above example, we are running the sleep command in the background for 10 seconds. The & symbol at the end of the command allows the process to run in the background.

Note: Be careful when executing system commands as they can potentially be dangerous and cause harm to your system.

gistlibby LogSnag