Create documentation for an R project

I would like to create documentation for my R code. The code is part of the R project, but not a package. Is there a way to show documentation for code not in a package using the built-in help viewer without creating a complete package?

+3


source to share


1 answer


You can use roxygen-style comments above your functions if you're okay, keeping your documentation directly in your code files. However, you are unlikely to be able to view the documentation using typical syntax ?your_function

. There might be a way to get around this with some hacks to generate documentation and place them somewhere in the help search path, but that seems like more work than necessary.

If you want to include roxygen2 style documentation inside a function, you can get a nice syntax ?your_function

to browse the documentation if you want to download the package docstring

. This is a package that I wrote pretty much exactly for your use case - where you have the code you want to document but took no time to put in the package. I suggest either reading the README on the github page for docstring or looking at the vignette provided on cran for docstring .



Here's a sample session using docstring:

library(docstring)

square <- function(x){

    #' Square a number
    #'
    #' Calculates the square of the input
    #'
    #' @param x the input to be squared

    return(x^2)
}

# This will display the documentation for square
# just like any other help file would be displayed
?square

      

+11


source







All Articles