Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can RStudio automatically generate an roxygen template for a function?

Does RStudio support any automated roxygen template creation?

In Emacs-ESS, C-x C-o will produce an roxygen template for a function. For example, it will automagically convert this:

foo <- function(x,y) x+y 

into this:

##' .. content for \description{} (no empty lines) .. ##' ##' .. content for \details{} .. ##' @title  ##' @param x  ##' @param y  ##' @return  ##' @author David foo <- function(x,y) x+y 

Does similar functionality exist within RStudio?

updates

  • as of ESS 12.09-2, the command has been changed to C-c C-o C-o
  • this feature has been implemented in Rstudio: CTRL+ALT+SHIFT+R
like image 965
David LeBauer Avatar asked May 30 '12 22:05

David LeBauer


People also ask

How do you add Roxygen?

Inserting a skeleton - Do this by placing your cursor anywhere in the function you want to document and click Code Tools -> Insert Roxygen Skeleton (default keyboard shortcut Ctrl+Shift+Alt+R ).

How do I create an RD file?

Creating Rd FilesUse the File -> New -> R Documentation command in RStudio. This command will allow you to specify the name of an existing function or dataset to use as the basis for the Rd file or alternatively will create a new empty Rd file.

What is roxygen2?

roxygen2 dynamically inspects the objects that it's documenting, so it can automatically add data that you'd otherwise have to write by hand. It abstracts over the differences in documenting S3 and S4 methods, generics and classes, so you need to learn fewer details.


2 Answers

(Converting @Crops comment into a full answer)

In RStudio v0.99 there is a new option under the "Code" menu for .R files: "Insert Roxygen Skeleton". There is an image of it in RStudio's blog post about v0.99 preview.

Roxygen skeleton menu image from RStudio

like image 50
Brian Diggs Avatar answered Oct 05 '22 10:10

Brian Diggs


The silence that followed your question should tell you something... The answer, currently, is NO is doesn't. I know of several people who use EMACS for precisely this reason, and would not consider switching to RStudio until that has full roxygen support. That said, there has been some discussion about this between users and the makers of RStudio. Considering all the cool things that have been added to RStudio recently, I would not be surprised to see it happen. In fact, I think it is quite likely it will happen. But don't hold your breath for it, it may be a long wait...

like image 20
Peter Verbeet Avatar answered Oct 05 '22 11:10

Peter Verbeet