Skip to contents

This function executes a system command, using either shell on Windows or system on Linux. It allows the output of the command to be captured into an R object.

Usage

System(command, RObj = TRUE, ...)

Arguments

command

A string representing the bash command to be executed.

RObj

A logical indicating whether to capture the output of the command as an R object. If TRUE (Default), the output is captured; if FALSE, the output is printed to the console.

...

Additional arguments passed to either shell or system function, depending on the operating system.

Value

Depending on the value of RObj, either the output of the executed command as an R object or NULL if RObj is FALSE and the output is printed to the console.

Author

Ahmed El-Gabbas

Examples

# print working directory
System("pwd")
#> [1] "/home/runner/work/IASDT.R/IASDT.R/docs/reference"

# first 5 files on the working directory
(A <- System("ls | head -n 5"))
#> [1] "AddImg2Plot-1.png" "AddImg2Plot.html"  "AddLine-1.png"    
#> [4] "AddLine-2.png"     "AddLine.html"     

(A <- System("ls | head -n 5", RObj = FALSE))
#> [1] 0