Parse embedded R code chunks from a file (receives the lines of the file as a CharcterVector for using with regexec and as a standard stl vector for traversal/insepection)
| 993 | // file as a CharcterVector for using with regexec and as a standard |
| 994 | // stl vector for traversal/insepection) |
| 995 | std::vector<std::string> parseEmbeddedR( |
| 996 | Rcpp::CharacterVector linesVector, |
| 997 | const std::deque<std::string>& lines) { |
| 998 | Rcpp::List matches = regexMatches(linesVector, |
| 999 | "^\\s*/\\*{3,}\\s*[Rr]\\s*$"); |
| 1000 | bool withinRBlock = false; |
| 1001 | CommentState commentState; |
| 1002 | std::vector<std::string> embeddedR; |
| 1003 | |
| 1004 | for (int i = 0; i<matches.size(); i++) { |
| 1005 | |
| 1006 | // track comment state |
| 1007 | std::string line = lines[i]; |
| 1008 | commentState.submitLine(line); |
| 1009 | |
| 1010 | // is this a line that begins an R code block? |
| 1011 | const Rcpp::CharacterVector match = matches[i]; |
| 1012 | bool beginRBlock = match.size() > 0; |
| 1013 | |
| 1014 | // check state and do the right thing |
| 1015 | if (beginRBlock) { |
| 1016 | withinRBlock = true; // #nocov |
| 1017 | } |
| 1018 | else if (withinRBlock) { |
| 1019 | if (commentState.inComment()) // #nocov start |
| 1020 | embeddedR.push_back(line); |
| 1021 | else |
| 1022 | withinRBlock = false; // #nocov end |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | return embeddedR; |
| 1027 | } |
| 1028 | |
| 1029 | } // anonymous namespace |
| 1030 |
no test coverage detected