Skip to content

Instantly share code, notes, and snippets.

@geophtwombly
Last active December 11, 2015 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geophtwombly/4666066 to your computer and use it in GitHub Desktop.
Save geophtwombly/4666066 to your computer and use it in GitHub Desktop.
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)
}
}
@kevinushey
Copy link

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment