Examples

Here we provide some illustrative examples. You can reproduce all of these examples in your own install of Larch, as all of the example data is included with the standard distribution. To work with any objects you find in the examples, a handy function is provided to extract that object directly into your workspace:

larch.example(n, extract='m', echo=False, output_file=None)

Run an example code section (from the documentation) and give the result.

Parameters:
  • n (int) – The number of the example to reproduce.
  • extract (str or Sequence[str]) – The name of the object of the example to extract. By default m but it any named object that exists in the example namespace can be returned. Give a sequence of str to get multiple objects.
  • echo (bool, optional) – If True, will echo the commands used.
  • output_file (str, optional) – If given, check whether this named file exists. If so, return the filename, otherwise run the example code section (which should as a side effect create this file). Then check that the file now exists, raising a FileNotFoundError if it still does not exist.