CommandlineWrapper: R6 Class representing a commandline tool

CommandlineWrapperR Documentation

R6 Class representing a commandline tool

Description

This class is designed for automating creation of R functions wrapping commandline tools

Public fields

base_command

name of base command (e.g. grep) (string)

cli_arg_list

a list of the flags (–verbose), arguments (–threads <num_threads>), and positional arguments (base_command <positional_arg>) of the commandline tool (list)

function_name

name of the R function that will wrap the commandline tool (string)

tool_title

name of the tool we are wrapping. Used only for roxygen documentation - doesn't need to match the tool specs one to one (string)

tool_description

what does the commandline tool we're wrapping actually do (string) Initialise CommandLineWrapperClass

Methods

Public methods


Method new()

Usage
CommandlineWrapper$new(
  base_command,
  tool_title,
  tool_description,
  function_name
)
Arguments
base_command

name of base command (e.g. grep) (string)

tool_title

name of the tool we are wrapping. Used only for roxygen documentation - doesn't need to match the tool specs one to one (string)

tool_description

what does the cli tool we're wrapping actually do (string)

function_name

name of the R function that will wrap the commandline tool (string)

cli_arg_list

cli_arg_list object

Returns

run for its side effects (writes a simple CLI tool wrapping R function to the clipboard) Add Argument

Adds an argument to cli_arg_list. Here, an arg is defined as something like –threads <num_threads>


Method add_arg()

Usage
CommandlineWrapper$add_arg(
  name,
  prefix,
  default = "NULL",
  help_message = "<no help message available>"
)
Arguments
name

name of argument/option. Does NOT need to match the commandline tools native option names (string)

prefix

prefix of the argument/option. e.g. –threads. This needs to match one of the commandline tools prefixes (string)

default

what is the default value. Specifying a non-null default here implies that the argument should always be included in the commandline. To let the user specify the argument value when running the wrapping R function, leave as null (string)

help_message

description of what this argument/option does (string)

Returns

run for its side effects (updates objects cli_arg_list) Add Positional Argument

Adds a position argument to cli_arg_list. Here, a positional argument is defined as something like base_command <positional_argument_1>


Method add_pos()

Usage
CommandlineWrapper$add_pos(
  name,
  required,
  help_message = "<no help message available>"
)
Arguments
name

name of argument/option. Does NOT need to match the commandline tools native option names (string)

required

is this positional argument required (bool)

help_message

description of what this argument/option does (string)

Returns

run for its side effects (updates objects cli_arg_list) Add flag

Adds a flag to the cli_arg_list. Here, a flag is defined as something like base_command –verbose


Method add_flag()

Usage
CommandlineWrapper$add_flag(
  name,
  prefix,
  default = FALSE,
  help_message = "<no help message available>"
)
Arguments
name

name of argument/option. Does NOT need to match the commandline tools native option names (string)

prefix

prefix of the argument/option. e.g. –verbose. This needs to match one of the commandline tools prefixes (string)

default

what is the default value - should the flag be present/absent by default (boolean)

help_message

description of what this argument/option does (string)

Returns

run for its side effects (updates objects cli_arg_list) Create R Function Wrapping Commandline Tool

Creates an r function wrapping a commandline tool and saves it to clipboard


Method create_function_wrapping_commandline_tool()

Usage
CommandlineWrapper$create_function_wrapping_commandline_tool()
Returns

Run for its side-effects (copies R function definition to clipboard)


Method clone()

The objects of this class are cloneable with this method.

Usage
CommandlineWrapper$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

## Not run: 
# Step 1: Load library

library(utilitybeltcli)


# Step 2: Define basic components of the tool (and the R function we want to produce that wraps it)

MosdepthWrapper <- CommandlineWrapper$new(
  base_command = "mosdepth",
  tool_title = "Mosdepth",
  tool_description = "simple R wrapper",
  function_name = "run_mosdepth"
)


# Step 3: describe the paramaters of the tool including:
#   (a) flags (–-verbose)
#   (b) arguments (-–threads <num_threads>)
#   (c) positional arguments (base_command <positional_arg>)

MosdepthWrapper$add_arg(name = "threads", prefix = "--threads")
MosdepthWrapper$add_flag(name = "d4", prefix = "--d4", default = FALSE)
MosdepthWrapper$add_pos(name = "prefix", required = TRUE)
MosdepthWrapper$add_pos(name = "bam_or_cram", required = TRUE)


# Step 4: produce the R function wrapper for the tool
MosdepthWrapper$create_function_wrapping_commandline_tool()

## End(Not run)


selkamand/utilitybeltcli documentation built on July 30, 2022, 5:45 p.m.