Is there a global flag that can be set to provide code along with the ROxygen documentation?

I taught a class in which I had students who used the package I wrote. Now that the class is finished, I would like to provide them with the code for each of these functions built into the documentation for the functions. Is there a global flag that I can set for this? Any hacking code?

0
source share
2 answers

You can pre-process your R files with the brew package, for example.

File 'foo-tmp.r'

##' a function that doesn't do much 
##'
##' @title foo
##' @param x 
##' @param y 
##' @param z 
##' @return error message
##' @author Baptiste 
##' @examples
##' dontrun{
#<%= cat(paste0("##'", getSrcref(foo), "\n")) %> ##' }
foo <- function(x,  y,  z){
    rnorm(10) == 1
    # inline comment
    .NotYetImplemented()
    " other stuff"
    return(FALSE)
  }

Then process the file to generate foo.r

source("foo-tmp.r") # to know what the function is
brew("foo-tmp.r", "foo.r")

with the resulting output:

##' a function that doesn't do much 
##'
##' @title foo
##' @param x 
##' @param y 
##' @param z 
##' @return error message
##' @author Baptiste 
##' @examples
##' dontrun{
###'function(x,  y,  z){
 ##'    rnorm(10) == 1
 ##'    # inline comment
 ##'    .NotYetImplemented()
 ##'    " other stuff"
 ##'    return(FALSE)
 ##'  }
 ##' }
foo <- function(x,  y,  z){
    rnorm(10) == 1
    .NotYetImplemented()
    " other stuff"
    return(FALSE)
  }
+1
source

. . @baptiste , . .

0

All Articles