rpartPages function
- WidgetRef ref
Display the results of building an rpart tree.
Implementation
List<Widget> rpartPages(WidgetRef ref) {
String stdout = ref.watch(stdoutProvider);
// Begin the list of pages to display with model content.
List<Widget> pages = [];
// Temporary storage for page content or image.
String content = '';
String image = '';
////////////////////////////////////////////////////////////////////////
//
// Default model 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)
with configuration set using
[rpart::rpart.control()](https://www.rdocumentation.org/packages/rpart/topics/rpart.control).
''',
content: 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;
}