rpartPages function

List<Widget> rpartPages(
  1. WidgetRef ref
)

Rpart tree displays.

Implementation

List<Widget> rpartPages(
  WidgetRef ref,
) {
  String stdout = ref.watch(stdoutProvider);

  // Begin the list of pages to display with the introduction markdown text.

  List<Widget> pages = [];

  // Temporary storage for page content or image.

  String content = '';
  String image = '';

  ////////////////////////////////////////////////////////////////////////

  // Default tree text.

  content = rExtractTree(stdout);

  if (content.isNotEmpty) {
    pages.add(
      TextPage(
        title: '''

          # Decision Tree Model

          Built using [rpart::rpart()](https://www.rdocumentation.org/packages/rpart/topics/rpart).

          ''',
        content: '\n$content',
      ),
    );
  }

  ////////////////////////////////////////////////////////////////////////

  // Tree visualisation.

  image = '$tempDir/model_tree_rpart.svg';

  if (imageExists(image)) {
    pages.add(
      ImagePage(
        title: '''

          # Decision Tree Visualisation

          Built using
          [rattle::fancyRpartPlot()](https://www.rdocumentation.org/packages/rattle/topics/fancyRpartPlot).

          ''',
        path: image,
      ),
    );
  }

  ////////////////////////////////////////////////////////////////////////

  // Convert to rules.

  content = rExtract(stdout, 'asRules(model_rpart)');

  if (content.isNotEmpty) {
    pages.add(
      TextPage(
        title: '''

          # Decision Tree as Rules

          Built using [rattle::asRules()](https://www.rdocumentation.org/packages/rattle/topics/asRules).

          ''',
        content: '\n$content',
      ),
    );
  }

  ////////////////////////////////////////////////////////////////////////

  return pages;
}