MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / parseEmbeddedR

Function parseEmbeddedR

src/attributes.cpp:995–1027  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 5

regexMatchesFunction · 0.85
submitLineMethod · 0.80
inCommentMethod · 0.80
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected