The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
Strict separation of settings from code.
configulaR is a port of the excellent python-decouple library for R.
As stated by its original author, configulaR makes it easy to:
configulaR’s behavior mimics python-decouple as closely as possible and is tested against python-decouple’s unit tests.
# Install from CRAN
install.packages("configulaR")
# Or install the development version from GitHub
# install.packages("devtools")
::install_github("dataupsurge/configulaR") devtools
configulaR always searches for configuration values in this order:
.ini
or .env
filesconfig
Environment variables have precedence over config files to maintain Unix consistency.
By default, config files are searched for in: 1. The current working
directory 2. Any other directory provided via the path
argument 3. Parent directories (if no config files are found in the
current directory)
configulaR looks for either settings.ini
or
.env
files.
Parameter values can be retrieved anytime by invoking the
configulaR::get_var
function:
library(configulaR)
# Retrieve a value from environment or config file
<- get_var('API_KEY', default='my-default-key')
api_key
# With type casting
<- get_var('DEBUG', default=FALSE, cast='logical')
debug_mode <- get_var('PORT', default=3000, cast='integer') port_number
If the config
parameter is not provided, a config file
search will be performed at each function call.
To avoid repeated config file searches, preload the configuration once:
# Load config once
<- get_config()
config
# Then use it for all subsequent calls
<- get_var('API_KEY', config=config, default='my-default-key')
api_key <- get_var('DEBUG', config=config, default=FALSE, cast='logical') debug_mode
If a parameter has no default value and doesn’t exist in the environment or config files, configulaR will raise an error:
# This will fail if SECRET_KEY is not defined anywhere
<- get_var('SECRET_KEY')
secret_key
# This will use the default if SECRET_KEY is not defined
<- get_var('SECRET_KEY', default='fallback-secret-key') secret_key
This fail-fast policy helps you avoid subtle bugs when parameters are missing.
By default, all values returned by configulaR
are
strings
.
To specify a different return type, use the cast
argument:
# Return as integer
<- get_var('MAX_CONNECTIONS', default='10', cast='integer')
max_connections
# Return as logical
<- get_var('DEBUG', default='True', cast='logical')
debug_enabled
# Return as float
<- get_var('TIMEOUT', default='5.5', cast='float')
timeout_seconds
# Custom casting function
get_var('NUMBERS', default='1,2,3', cast=function(x) as.numeric(strsplit(x, ',')[[1]]))
Predefined casting types include:
'int'
, 'integer'
'bool'
, 'boolean'
,
'logical'
'float'
configulaR supports both .ini
and
.env
files.
configulaR can read ini files and provide simple interpolation.
Simply create a settings.ini
in your working directory
or in its parent directories:
[settings]
DEBUG=True
TEMPLATE_DEBUG=%(DEBUG)s
SECRET_KEY=ARANDOMSECRETKEY
DATABASE_URL=mysql://myuser:mypassword@myhost/mydatabase
PERCENTILE=90%%
#COMMENTED=42
Create a .env
text file in your repository’s root
directory:
DEBUG=True
TEMPLATE_DEBUG=True
SECRET_KEY=ARANDOMSECRETKEY
DATABASE_URL=mysql://myuser:mypassword@myhost/mydatabase
PERCENTILE=90%
#COMMENTED=42
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.