system3: A customized wrapper for 'system2()'

View source: R/command.R

system3R Documentation

A customized wrapper for system2()

Description

If system2() returns character output (e.g., with the argument stdout = TRUE), check if the output is encoded in UTF-8. If it is, mark it with UTF-8 explicitly. If it returns an integer, treat it as an error code and throw an error if it is non-zero.

Usage

system3(command, args = character(), ...)

Arguments

command, args, ...

Passed to system2(). Note that args will always be quoted with shQuote() before passing to system2(), so you don't need to quote it yourself.

Value

The value returned by system2().

Examples


a = c("-e", "print(intToUtf8(c(20320, 22909)))")
x2 = system2("Rscript", shQuote(a), stdout = TRUE)
Encoding(x2)  # unknown

x3 = xfun::system3("Rscript", a, stdout = TRUE)
# encoding of x3 should be UTF-8 if the current locale is UTF-8
!l10n_info()[["UTF-8"]] || Encoding(x3) == "UTF-8"  # should be TRUE


xfun documentation built on June 19, 2026, 9:06 a.m.