Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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...

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