Learn R Programming

options (version 0.3.0)

naming: Define Naming Conventions

Description

Option naming conventions use sensible defaults so that you can get started quickly with minimal configuration.

Usage

set_envvar_name_fn(fn, env = parent.frame())

set_option_name_fn(fn, env = parent.frame())

Value

The callback function fn

Arguments

fn

A callback function which expects two arguments, the package name and option name, and returns a single character value to use as an environment variable name.

env

An environment in which to search for options settings

Functions

  • set_envvar_name_fn(): Set a callback function to use to format environment variable names.

  • set_option_name_fn(): Set a callback function to use to format option names.

Defaults

Given a package mypackage and option myoption, the default settings will generate options and environment variables using the convention:

option:

mypackage.myoption

environment variable:

R_MYPACKAGE_MYOPTION

This convention is intended to track closely with how options and environment variables are handled frequently in the wild. Perhaps in contrast to the community conventions, an R_ prefix is tacked on to the default environment variables. This prefix helps to differentiate environment variables when similarly named tools exist outside of the R ecosystem.

Setting Alternative Conventions

If you choose to use alternative naming conventions, you must set the callback function before defining options. This is best achieved by altering these settings in the file where you define your options.

If you choose to break up your options across multiple files, then it is best to define the collate order for your R scripts to ensure that the options are consistently configured across operating systems.

See Also

naming_formats

Examples

Run this code
set_envvar_name_fn(envvar_name_generic)

set_envvar_name_fn(function(package, name) {
  toupper(paste("ENV", package, name, sep = "_"))
})

Run the code above in your browser using DataLab