8

I am trying to add documentation via roxygen2 in a package. I am able to create the packag successfully and on load able to use the functions too. Here is my understanding of how to do it, I create an empty R-Package project on RStudio and then have a source file named "getSomething.R". The contents are the following,

#' Test function to ask on stackoverflow
#' 
#' \code{getSomething} Does something to get something.
#' 
#' @param a param 1
#' @param b param 2
#' 
#'

getSomething <- function(a,b){
  return(a*b)
}

Now, I build and load the package which should ideally, create the package with .Rd file in the /man folder and also come up on doing "?getSomething". But nothing comes up on using the command nor are the Rd files created. Am I missing something here? In my original project, I have some dependent packages which I have added.

Following is the decription file,

Package: testPackage
Type: Package
Title: Learn how to use roxygen2.
Version: 1.0.1
Date: 2014-11-27
Author: amj2403
Maintainer: amj2403 <emailid>
Description: Write something here
License: NA
Depends:
    R (>= 3.0.0),
    rjson,
    futile.logger,
    RCurl

Also the NAMESPACE file,

exportPattern("^[[:alpha:]]+"

I think I am missing some vital step.

Avinash
  • 2,521
  • 4
  • 21
  • 35
  • Have you configured the RStudio project to "Generate documentation with Roxygen"? – Roland Dec 01 '14 at 10:31
  • @Roland Yes I have. As of now, I run the oxygenize("package name") before building it and it works fine. But I was thinking it should work otherwise too. – Avinash Dec 01 '14 at 12:55
  • When you configured it to generate documentation with roxygen, did you click through to "Configure" and set the "Automatically roygxenise when running:" fields? – Oliver Keyes Dec 01 '14 at 13:01
  • @Avinash gotcha. Will add it as an answer. – Oliver Keyes Dec 08 '14 at 13:18

3 Answers3

10

The default in RStudio, when you enable roxygen2, is to roxygenise everything on package builds and R CMD CHECK but not on "build and reload". To enable that, go to Project Options -> Build Tools. Then click the "Configure" button next to "Generate documentation with Roxygen" and tick the "Build & Reload" box.

Community
  • 1
  • 1
Oliver Keyes
  • 3,294
  • 2
  • 14
  • 23
2

Sometimes RStudio would not display the checkbox "Generate documentation with Roxygen" at all. If this is the case, in R Console type library(roxygen2) and it will suddenly appear.

I wish default would be to mandate loading of it and enabling it.

userJT
  • 11,486
  • 20
  • 77
  • 88
1

I had the same problem while making a package with devtools. I just needed to run devtools::document() to create the help files.

rsoren
  • 4,036
  • 3
  • 26
  • 37