Skip to content

Feature request: Export any individual tree to rpart-style ASCII text for GEE compatibility #784

Description

@samuel-rosa

Summary:
Add a function to export any individual tree from a ranger forest in the same ASCII indented style as produced by print.rpart (rpart), for interoperability (e.g. with Google Earth Engine).

Motivation:
Platforms like Google Earth Engine can ingest decision trees in the classic rpart ASCII text format (as printed by print(rpart_model)) for use in prediction workflows. Currently, ranger can fit forests or single trees efficiently, but does not offer a built-in way to export a single tree in this GEE-compatible format. Supporting this would enable users to train using ranger and easily deploy trees in GEE and other systems.

Proposed functionality:

  • A new function (e.g. export_ascii_tree() or treeAscii()) that takes a ranger forest/fit and a tree index.
  • Outputs a character string/vector containing the text representation in rpart-style indentation, matching print.rpart().
  • Handles regression/classification, numeric and factor splits correctly.

Example use case:

rfit <- ranger(Species ~ ., data = iris, num.trees = 100)
cat(treeAscii(rfit, tree = 23))

This would print a textual indented tree, directly uploadable to GEE.

Implementation notes:

  • Use treeInfo(ranger_fit, tree=...) to extract structure, then recursively walk from root using leftChild/rightChild to print branches and leaves matching print.rpart logic.
  • Factor/categorical splits need correct text formatting.
  • Optional: support arguments like max.depth, node stats, etc.

Impact/benefits:

  • Makes ranger interoperable with remote sensing and environmental science workflows that rely on GEE or rpart ASCII trees.
  • Opens up more deployment/use cases for ranger’s core audience.

References:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions