The featureflag
package was created in order to allow R
users to easily make use of feature flags. Feature flags allow
developers to turn application features on and off in form of
configuration. They allow to you to avoid issues related to long live
branching by decoupling feature roll-out from the deployment
process.
If you are interested in learning more about feature flags, check out those great resources:
The featureflag
package currently supports the following
types of feature flags: * bool feature flags - simple on and off flags *
percentage feature flags - flags that are randomly enabled/disabled
based on the configured percentage * time period feature flags - flags
that are enabled during a speficied time period e.g. from 2020-01-01
10:00:00 until 2020-02-01 10:00:00
A bool feature flag can be created like this:
Now you can use it in combination with the is_enabled
method to branch out logic in your application:
if (is_enabled(my_bool_feature_flag)) {
print("Running my feature...")
}
#> [1] "Running my feature..."
In case we wanted to run some default functionality when our feature flag is off, we can simply add an else statement:
if (is_enabled(my_bool_feature_flag)) {
print("Running my feature...")
} else {
print("Running my default functionality...")
}
#> [1] "Running my feature..."
featureflag
offers helper methods to avoid boilerplate
if
and if/else
code. They can be replaced by
using the feature_if
and feature_ifelse
helpers. The above examples can be rewritten as: