CommandlineWrapper | R Documentation |
This class is designed for automating creation of R functions wrapping commandline tools
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
new()
CommandlineWrapper$new( base_command, tool_title, tool_description, function_name )
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
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>
add_arg()
CommandlineWrapper$add_arg( name, prefix, default = "NULL", help_message = "<no help message available>" )
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)
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>
add_pos()
CommandlineWrapper$add_pos( name, required, help_message = "<no help message available>" )
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)
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
add_flag()
CommandlineWrapper$add_flag( name, prefix, default = FALSE, help_message = "<no help message available>" )
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)
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
create_function_wrapping_commandline_tool()
CommandlineWrapper$create_function_wrapping_commandline_tool()
Run for its side-effects (copies R function definition to clipboard)
clone()
The objects of this class are cloneable with this method.
CommandlineWrapper$clone(deep = FALSE)
deep
Whether to make a deep clone.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.