cloc_call: Call 'cloc.pl' directly with granular control over options

View source: R/cloc-call.r

cloc_callR Documentation

Call cloc.pl directly with granular control over options

Description

It is nigh impossible to predict all use-cases for the cloc.pl acript and create associated R functions for them. To that end, this function provides direct access to the script and enables direct passing of command-line parameters via processx::run().

Usage

cloc_call(args = character(), echo = TRUE, ...)

cloc_help(echo = FALSE)

cloc_version(echo = FALSE)

cloc_os(echo = FALSE)

Arguments

args,

character vector, arguments to the command. They will be escaped via base::shQuote().

echo

echo Whether to print the standard output and error to the screen. Note that the order of the standard output and error lines are not necessarily correct, as standard output is typically buffered.

...

other options/parameters passed on to processx::run()

Value

the structure returned by processx::run() (a list with four elements).

Caveat utilitor

As indicated, this is an lower-level function providing granular control over the options for cloc.pl. You are invoking an operating system command-line and need to read the cloc.pl help very carefully as — unlike the higher-level functions – there are no "guide railss" provided to do helpful things such as e nsure you do not clobber files in a given directory.

processx::run() supports "callback functions" to make it easier to deal with stdout and stderr and you may need to make use of those depending on the how you are calling the underlying script.

Examples

# Get help on the parameters `cloc.pl` supports
cloc_call("--help", echo_cmd=TRUE, echo=TRUE)

# or use the helper version of the above
cloc_help()

# show the OS type
cloc_call("--show-os")

# shortcut equivalent
cloc_os()

# retrieve the OS type
trimws(cloc_call("--show-os")$stdout)

# shortcut of the above with no echo and only returning trimmed stdout
cloc_os()

# get version of cloc.pl script provided with the package
cloc_version()

hrbrmstr/cloc documentation built on May 1, 2023, 7:34 a.m.