public
Last active

  • Download Gist
add @export
1 2 3 4 5 6 7 8 9 10
for( file in list.files("./R", full.names = TRUE)) {
doc <- scan( what=character(), sep="\n", file, blank.lines.skip = FALSE))
returns <- which(!grepl("returnItem", doc) & grepl("@return", doc))
if(length(returns) > 0){
doc[returns] <- gsub("##' @return", paste("##' @export\n##' @return"), doc[returns])
doc <- paste(doc, collapse="\n")
cat(doc, file = file)
}
}

Slightly cleaner, keeps contents of @return:

for( file in list.files("./R", full.names = TRUE) ) {
  doc <- scan( what=character(), sep="\n", file )
  doc <- gsub("##' @return (.*)", "##' @export\n##' @return \\1", doc)
  doc <- paste(doc, collapse="\n" )
  cat( doc, file=file )
}

Although ideally, we would want to ensure we don't already have an @export statement somewhere in the block, and that's a more difficult problem...

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.