Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience function to generate roxygen comment blocks #51

Closed
eheinzen opened this issue Aug 25, 2017 · 4 comments
Closed

Convenience function to generate roxygen comment blocks #51

eheinzen opened this issue Aug 25, 2017 · 4 comments

Comments

@eheinzen
Copy link

It'd be nice to have a convenience function to create roxygen comment blocks automatically. This would be similar to utils::prompt, but instead of creating Rd files, it would print out roxygen comment blocks Perhaps make it S3, with methods for functions and data.frames? I'm thinking something like this:

> myfun <- function(a, b, ..., d) NULL
> use_roxygen_comments(myfun)
#' <Title>
#' 
#' <Description>
#' 
#' @param a <parameter description>
#' @param b <parameter description>
#' @param ... <parameter description>
#' @param d <parameter description>
#' @return <describe returned object
#' @seealso <links to other help pages>
#' @export
@eheinzen
Copy link
Author

Maybe something as easy as this:

use_roxygen_comments <- function(x, ...)
{
  UseMethod("use_roxygen_comments")
}

use_roxygen_comments.function <- function(x, ...)
{
  x <- match.fun(x)
  nms <- names(formals(x))
  if(length(nms) > 0) {
    params <- paste0("@param ", nms, " <parameter description>")
  } else {
    params <- character(0)
  }

  txt <- c("<Title>", "", "<Description>", "", params, "@return <describe returned object",
           "@seealso <links to other help pages>", "@export")
  out <- paste0("#' ", txt)
  cat(out, sep = '\n')
  invisible(out)
}


@jimhester
Copy link
Member

The RStudio IDE already supports this code->Insert Roxygen Skeleton, but presumably you are using a different editor?

@eheinzen
Copy link
Author

Thanks, Jim. I'm on RStudio and saw that, but this was suggested by a coworker. Many people are still using emacs, etc., for their editing...

@hadley
Copy link
Member

hadley commented Aug 28, 2017

This is out of scope for usethis - and is duplicate of r-lib/roxygen2#253

@hadley hadley closed this as completed Aug 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants