How to use .mlrrc¶
Suppose you always use CSV files. Then instead of always having to type
--csv as in
mlr --csv cut -x -f extra mydata.csv
mlr --csv sort -n id mydata.csv
and so on, you can instead put the following into your
Then you can just type things like
mlr cut -x -f extra mydata.csv
mlr sort -n id mydata.csv
--csv part will automatically be understood. If you do want to process, say, a JSON file then
mlr --json ... at the command line will still override the defaults you've placed in your
What you can put in your .mlrrc¶
You can include any command-line flags, except the "terminal" ones such as
--mloadflags aren't allowed in
.mlrrcas they control code execution, and could result in your scripts running things you don't expect if you receive data from someone with a
./.mlrrcin it. You can use
The formatting rule is you need to put one flag beginning with
--per line: for example,
--csvon one line and
--nr-progress-mod 1000on a separate line.
Since every line starts with a
--option, you can leave off the initial
--if you want. For example,
ojsonis the same as
nr-progress-mod 1000is the same as
Comments are from a
#to the end of the line.
Empty lines are ignored -- including lines which are empty after comments are removed.
Here is an example
# Input and output formats are CSV by default (unless otherwise specified # on the mlr command line): csv # If a data line has fewer fields than the header line, instead of erroring # (which is the default), just insert empty values for the missing ones: allow-ragged-csv-input # These are no-ops for CSV, but when I do use JSON output, I want these # pretty-printing options to be used: jvstack jlistwrap # Use "@", rather than "#", for comments within data files: skip-comments-with @
Where to put your .mlrrc¶
If the environment variable
MLRRC is set:
If its value is
.mlrrcfiles are processed. (This is nice for things like regression testing.)
Otherwise, its value (as a filename) is loaded and processed. If there are syntax errors, they abort
mlrwith a usage message (as if you had mistyped something on the command line). If the file can't be loaded at all, though, it is silently skipped.
.mlrrcin your home directory or current directory is ignored whenever
MLRRCis set in the environment.
Example line in your shell's rc file:
$HOME/.mlrrcexists, it's processed as above.
./.mlrrcexists, it's then also processed as above.
The idea is you can have all your settings in your
$HOME/.mlrrc, then maybe more project-specific settings for your current directory if you like.