MyNixOS website logo
Description

Simplify Parameters.

An interface to simplify organizing parameters used in a package, using external configuration files. This attempts to provide a cleaner alternative to options().

p a r a m s

sahilseth.github.io/params

Rationale

Setting/loading and extracting various options from/into the R environment

A package level alternative for options and getOptions, to prevent cluttering the space.

Main Features

  • load from files: ability to store all default options as a tab delimited OR comma delimited files
  • check options: if a option relates to a file path, automatically check if it exists
  • embeddable set OR retrieve multiple options as list
  • clean: print all or few options as a pretty table

Main functions

  • set_opts(): set options into a custom environment
  • get_opts(): retrieve options from a custom environment
  • load_opts(): Read a tab/comma delimited file using read_sheet() and load them using set_opts()
  • new_opts(): create a options manager (to be used in a R package etc...)
  • print.opts(): print options as a pretty table, used by get_opts()

Examples:

Setting up some options

library(params)
set_opts(
	name = "John",
	verbose = TRUE, 
	my_dir = "~/mypath")
get_opts()	

Retrieving all options using get_opts()

name            value        
--------------  -------------
default_regex   (.*)         
my_conf_path    ~/flowr/conf 
my_dir          ~/mypath     
my_path         ~/flowr      
my_tool_exe     /usr/bin/ls  
name            John        
verbose         TRUE  

Retrieving a specific option

get_opts("my_dir")

Loading several options from a conf file

conf = system.file("conf/params.conf", package = "params")
load_opts(conf)

Nested options, re-use options as part of other options

  • This feature is based on logic-less templating using a R implementation of mustache.
  • Say we define two options first_name and last_name; to create full_name, either we could again use the actual values or first and last names or define full_name as {{{first_name}}} {{{last_name}}}
set_opts(first = "John", last = "Doe",
	full = "{{{first}}} {{{last}}}")
get_opts('full')
"John Doe"
  • both set_opts and load_opts, support auto-complete
  • this is especially useful in case of paths, and is really inspired by BASH environment variable system

Using params in your own package

Params creates a environment object and stores all parameters in that object. Thus multiple packages using params packages may be loaded each with a separate set of options.

Setup: One liner to to be included in a package !

myopts = new_opts()

The above object provides three functions to load, set and fetch params:

  • myopts$get()
  • myopts$set()
  • myopts$load()

Installation

## stable version from CRAN
install.packages("params") 

## latest, development version
devtools::install_github("sahilseth/params")

Updates

This package is under active-development, you may watch for changes using the watch link above.

Here is a example conf file::

## ----------------------- p a r a m s     config ------------------------ ##
## the file by default, sits in the R pacakge
## --------------------------------------------------------------------- ##

## Following lines, as a tab delimited table, with two columns
## Always use load_conf(); after editing this file !

## options ending with path, exe or dir are checked for existence. file.exists
my_path	~/flowr
my_tool_exe	/usr/bin/ls
my_dir	path/to/a/folder


## you can define nested options
## these are parsed line by line

my_conf_path	{{{my_path}}}/conf

## --- all options are parsed as chracter
default_regex	(.*)
Metadata

Version

0.7.3

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows