• Stars
    star
    102
  • Rank 323,878 (Top 7 %)
  • Language
    C
  • License
    Other
  • Created over 7 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Powerful replacements for base::system2

sys

Portable System Utilities

CRAN_Status_Badge CRAN RStudio mirror downloads

Powerful replacements for base system2 with consistent behavior across platforms. Supports interruption, background tasks, and full control over STDOUT / STDERR binary or text streams.

Hello World

Run a blocking process

# Blocks until done, interrupt with ESC or CTRL+C
res <- exec_wait("ping", "google.com")

To run as a background process:

# Run as a background process
pid <- exec_background("ping", "google.com")

# Kill it after a while
sleep(4)
tools::pskill(pid)

See the ?sys manual page for details.

Details

The exec_wait function runs a system command and waits for the child process to exit. When the child process completes normally (either success or error) it returns with the program exit code. Otherwise (if the child process gets aborted) R raises an error. The R user can interrupt the program by sending SIGINT (press ESC or CTRL+C) in which case the child process tree is properly terminated. Output streams STDOUT and STDERR are piped back to the parent process and can be sent to a connection or callback function. See the section on Output Streams below for details.

The exec_background function starts the program and immediately returns the PID of the child process. Because this is non-blocking, std_out and std_out can only be TRUE/FALSE or a file path. The state of the process is not controlled by R but the child can be killed manually with [tools::pskill]. This is useful for running a server daemon or background process.

The exec_internal function is a convenience wrapper around exec_wait which automatically captures output streams and raises an error if execution fails. Upon success it returns a list with status code, and raw vectors containing stdout and stderr data (use as_text for converting to text).

Output Streams:

The std_out and std_err parameters are used to control how output streams of the child are processed. Possible values for both foreground and background processes are:

  • TRUE: print child output in R console
  • FALSE: suppress output stream
  • string: name or path of file to redirect output

In addition the exec_wait function also supports the following std_out and std_err types:

  • connection a writable R [connection] object such as [stdout] or [stderr]
  • function: callback function with one argument accepting a raw vector (use as_text to convert to text).

When using exec_background with std_out = TRUE or std_err = TRUE on Windows, separate threads are used to print output. This works in RStudio and RTerm but not in RGui because the latter has a custom I/O mechanism. Directing output to a file is usually the safest option.

More Repositories

1

jsonlite

A Robust, High Performance JSON Parser and Generator for R
C
361
star
2

mongolite

Fast and Simple MongoDB Client for R
C
281
star
3

curl

A Modern and Flexible Web Client for R
C
207
star
4

resttesttest

A native in-browser tool for testing REST/CORS services. Builds on jQuery and Bootstrap.
HTML
195
star
5

V8

Embedded JavaScript Engine for R
C++
188
star
6

js

Tools for Working with JavaScript in R
R
67
star
7

openssl

OpenSSL bindings for R
R
62
star
8

RAppArmor

R interfaces to Linux and AppArmor security methods
TeX
52
star
9

protolite

Fast and Simple Object Serialization to Protocol Buffers
C++
47
star
10

opencpu-legacy

This version is no longer maintained. Switch to "opencpu" repository.
R
41
star
11

solarisvm

VMware image with R on Solaris
32
star
12

webutils

Utility functions for web applications
R
23
star
13

shinymagick

Simple Demo of using Magick with Shiny
R
22
star
14

unix

R bindings to system utilities found in most Unix systems
R
21
star
15

agent

Store sensitive data such as API tokens
R
19
star
16

gpg

Bindings to gpgme for R
C
19
star
17

bcrypt

Wrapper for bcrypt in R
C
17
star
18

webp

R bindings for libwebp
R
14
star
19

tidyhtml

R bindings to html-tidy C interface
C
14
star
20

maketools

Exploring and Testing your Toolchain Configuration and System Packages
R
14
star
21

ipfs

R bindings to IPFS
R
10
star
22

popplertest

Example code to test string encoding in poppler-cpp
C++
10
star
23

build-v8-static

Building static v8-monolith library for various distros
Dockerfile
10
star
24

imwidgets

HTML widgets for viewing images
JavaScript
9
star
25

user2021

Slides from UseR-2021 keynote presentation about R-universe
HTML
7
star
26

snapshot

Create snapshots of R package repositories
R
6
star
27

rjade

R Bindings to the Jade Templating Engine
R
6
star
28

yeroon

yeroon.net webapps
JavaScript
5
star
29

badgen

R
5
star
30

Ohmage

Ohmage R package
R
5
star
31

betty

Some experimental rOpenSci infrastructure plumbing
R
5
star
32

ndjson-benchmark

Simple benchmark to compare jsonlite, ndjson, corpus
4
star
33

yeroon-setup

JavaScript
4
star
34

r-dependency-versioning

CSS
4
star
35

opencpu.tools

some tools for the opencpu project
R
4
star
36

backup

4
star
37

markdownit

Bindings to markdown-it JavaScript library
R
3
star
38

minimist

R binding to minimist JavaScript library
R
3
star
39

lmergm

lmergm R package
R
2
star
40

slides

Slides for the defense presentation
CSS
2
star
41

Mobilize

Mobilize R package
R
2
star
42

ohmage-ubuntu

ohmage-ubuntu
Shell
2
star
43

base64

R
2
star
44

debugcurl

How to debug curl (because I keep forgetting)
2
star
45

pacmantools

Tools for pacman repos
R
1
star
46

JJcorr

Git repo for the JJcorr package
R
1
star
47

interactivity

cran-interactivity
C
1
star
48

maintest

Test with main repository
HTML
1
star
49

r-security

R
1
star
50

r-universe

1
star
51

autobrew-old

Scripts for brewing static libs on CRAN MacOS builder
Roff
1
star
52

testinterrupt

Package + readme to demonstrate the user interruption problem in R
C
1
star
53

brotli

C
1
star
54

uptest

C++
1
star
55

grenoble2015

Automatically exported from code.google.com/p/io-2012-slides
CSS
1
star