code: def gen_module(schema, algo, module):
      # print(str(schema))
      rest_api_version = get_customizations_for(
          algo, "rest_api_version", 3
      )
  
      doc_preamble = get_customizations_for(algo, "doc.preamble")
      doc_returns = get_customizations_for(algo, "doc.returns")
      doc_seealso = get_customizations_for(algo, "doc.seealso")
      doc_references = get_customizations_for(algo, "doc.references")
      doc_examples = get_customizations_for(algo, "doc.examples")
  
      required_params = get_customizations_or_defaults_for(
          algo, "extensions.required_params", []
      )
      extra_params = get_customizations_or_defaults_for(
          algo, "extensions.extra_params", []
      )
      ellipsis_param = get_customizations_for(
          algo, "extensions.ellipsis_param"
      )
      model_name = algo_to_modelname(algo)
  
      update_param_defaults = get_customizations_for(
          "defaults", "update_param"
      )
      update_param = get_customizations_for(algo, "update_param")
  
      yield "# This file is auto-generated by h2o-3/h2o-bindings/bin/gen_R.py"
      yield "# Copyright 2016 H2O.ai;  Apache License Version 2.0 (see LICENSE for details) \n#'"
      yield "# -------------------------- %s -------------------------- #" % model_name
      # start documentation
      if doc_preamble:
          yield "#'"
          yield reformat_block(doc_preamble, prefix="#' ")
      yield "#'"
  
      # start doc for signature
      required_params = odict(
          [
              (
                  p[0] if isinstance(p, tuple) else p,
                  p[1] if isinstance(p, tuple) else None,
              )
              for p in required_params
          ]
      )
      schema_params = odict(
          [(p["name"], p) for p in schema["parameters"]]
      )
      extra_params = odict(
          [
              (
                  p[0] if isinstance(p, tuple) else p,
                  p[1] if isinstance(p, tuple) else None,
              )
              for p in extra_params
          ]
      )
      all_params = (
          list(required_params.keys())
          + list(schema_params.keys())
          + list(extra_params.keys())
      )
  
      def get_schema_params(pname):
          param = deepcopy(schema_params[pname])
          updates = None
          for update_fn in [update_param, update_param_defaults]:
              if callable(update_fn):
                  updates = update_fn(pname, param)
              if updates is not None:
                  param = updates
                  break
          return (
              param if isinstance(param, (list, tuple)) else [param]
          )  # always return array to support deprecated aliases
  
      tag = "@param"
      pdocs = odict()
      for pname in all_params:
          if (
              pname in pdocs
          ):  # avoid duplicates (esp. if already included in required_params)
              continue
          if pname in schema_params:
              for param in get_schema_params(
                  pname
              ):  # retrieve potential aliases
                  pname = param.get("name")
                  if pname:
                      pdocs[pname] = get_customizations_or_defaults_for(
                          algo,
                          "doc.params." + pname,
                          get_help(param, indent=len(tag) + 4),
                      )
          else:
              pdocs[pname] = get_customizations_or_defaults_for(
                  algo, "doc.params." + pname
              )
      if ellipsis_param is not None:
          pdocs["..."] = get_customizations_or_defaults_for(
              algo, "doc.params._ellipsis_"
          )
  
      for pname, pdoc in pdocs.items():
          if pdoc:
              yield reformat_block(
                  "%s %s %s" % (tag, pname, pdoc.lstrip("\n")),
                  indent=len(tag) + 1,
                  indent_first=False,
                  prefix="#' ",
              )
  
      if doc_returns:
          tag = "@return"
          yield reformat_block(
              "%s %s" % (tag, doc_returns.lstrip("\n")),
              indent=len(tag) + 1,
              indent_first=False,
              prefix="#' ",
          )
      if doc_seealso:
          tag = "@seealso"
          yield reformat_block(
              "%s %s" % (tag, doc_seealso.lstrip("\n")),
              indent=len(tag) + 1,
              indent_first=False,
              prefix="#' ",
          )
      if doc_references:
          tag = "@references"
          yield reformat_block(
              "%s %s" % (tag, doc_references.lstrip("\n")),
              indent=len(tag) + 1,
              indent_first=False,
              prefix="#' ",
          )
      if doc_examples:
          yield "#' @examples"
          yield "#' \dontrun{"
          yield reformat_block(doc_examples, prefix="#' ")
          yield "#' }"
      yield "#' @export"
  
      # start function signature
      sig_pnames = []
      sig_params = []
      for k, v in required_params.items():
          sig_pnames.append(k)
          sig_params.append(k if v is None else "%s = %s" % (k, v))
  
      for pname in schema_params:
          params = get_schema_params(pname)
          for param in params:
              pname = param.get(
                  "name"
              )  # override local var as param can be an alias of pname
              if (
                  pname in required_params or not pname
              ):  # skip schema params already added by required_params, and those explicitly removed
                  continue
              sig_pnames.append(pname)
              sig_params.append(
                  "%s = %s"
                  % (
                      pname,
                      get_customizations_or_defaults_for(
                          algo,
                          "doc.signatures." + pname,
                          get_sig_default_value(param),
                      ),
                  )
              )
  
      for k, v in extra_params.items():
          sig_pnames.append(k)
          sig_params.append("%s = %s" % (k, v))
      if ellipsis_param is not None:
          sig_params.append("...")
  
      param_indent = len("h2o.%s <- function(" % module)
      yield reformat_block(
          "h2o.%s <- function(%s)" % (module, ",\n".join(sig_params)),
          indent=param_indent,
          indent_first=False,
      )
  
      # start function body
      yield "{"
      yield "\n".join(
          gen_set_params(
              algo,
              sig_pnames,
              schema_params,
              required_params,
              ellipsis_param=ellipsis_param,
          )
      )
  
      yield ""
      yield "  # Error check and build model"
      verbose = "verbose" if "verbose" in extra_params else "FALSE"
      yield "  model <- .h2o.modelJob('%s', parms, h2oRestApiVersion=%d, verbose=%s)" % (
          algo,
          rest_api_version,
          verbose,
      )
      with_model = get_customizations_for(algo, "extensions.with_model")
      if with_model:
          yield ""
          yield reformat_block(with_model, indent=2)
      yield "  return(model)"
      yield "}"
  
      bulk_pnames_skip = [
          "model_id",
          "verbose",
          "destination_key",
      ]  # destination_key is only for SVD
      bulk_params = list(
          zip(
              *filter(
                  lambda t: not t[0] in bulk_pnames_skip,
                  zip(sig_pnames, sig_params),
              )
          )
      )
      bulk_pnames = list(bulk_params[0])
      sig_bulk_params = list(bulk_params[1])
      sig_bulk_params.append("segment_columns = NULL")
      sig_bulk_params.append("segment_models_id = NULL")
      sig_bulk_params.append("parallelism = 1")
      if ellipsis_param is not None:
          sig_bulk_params.append("...")
  
      if algo != "generic":
          #
          # Segment model building
          #
          bulk_param_indent = len(
              ".h2o.train_segments_%s <- function(" % module.lower()
          )
          yield reformat_block(
              ".h2o.train_segments_%s <- function(%s)"
              % (module.lower(), ",\n".join(sig_bulk_params)),
              indent=bulk_param_indent,
              indent_first=False,
          )
  
          # start train_segments-function body
          yield "{"
          yield "\n".join(
              gen_set_params(
                  algo,
                  bulk_pnames,
                  schema_params,
                  required_params,
                  skip_params=bulk_pnames_skip,
                  ellipsis_param=ellipsis_param,
              )
          )
          yield ""
          yield "  # Build segment-models specific parameters"
          yield "  segment_parms <- list()"
          yield "  if (!missing(segment_columns))"
          yield "    segment_parms$segment_columns <- segment_columns"
          yield "  if (!missing(segment_models_id))"
          yield "    segment_parms$segment_models_id <- segment_models_id"
          yield "  segment_parms$parallelism <- parallelism"
          yield ""
          yield "  # Error check and build segment models"
          yield "  segment_models <- .h2o.segmentModelsJob('%s', segment_parms, parms, h2oRestApiVersion=%d)" % (
              algo,
              rest_api_version,
          )
          yield "  return(segment_models)"
          yield "}"
  
      #
      # Additional functions
      #
      module_extensions = get_customizations_for(
          algo, "extensions.module"
      )
      if module_extensions:
          yield ""
          yield module_extensions
  
file_path: h2o-3/h2o-bindings/bin/gen_R.py
imports: from collections import OrderedDict
  from copy import deepcopy
  from functools import partial
  import bindings
  from custom import get_customizations_for, reformat_block
label_desc: Use image node_id 2 for calling a global function with example usage: gen_module(schema, algo, module) and returns: unknown