rExtractRowsColumns function

String rExtractRowsColumns(
  1. String txt
)

Implementation

String rExtractRowsColumns(String txt) {
  // If it appears that R has not yet finished loading the dataset then return
  // an appropriate message.

  // if (txt.contains("Error: object 'ds' not found")) {
  //   return ('The dataset appears to still be loading. Please wait.');
  // }

  if (txt.isEmpty) return '';

  // Split the string into lines.

  List<String> lines = txt.split('\n');
  txt = '${lines.first} ${lines[1]}';

  RegExp regExp = RegExp(r'[\d,]+');
  Iterable<Match> matches = regExp.allMatches(txt);

  // Extract the numbers and format them.

  List<String?> numbers = matches.map((match) => match.group(0)).toList();

  String result = '';

  if (numbers.length >= 2) {
    result = '${numbers.first} x ${numbers[1]}';
  }

  return result;
}