nathaneastwood
nathaneastwood

Reputation: 3764

Bad \usage lines found in documentation object

I am having trouble getting my package to pass the R CMD Check. I am using devtools version 1.9.1 and Roxygen2 version 4.1.1. The issue I have is as follows:

Bad \usage lines found in documentation object 'my_fn':


Functions with \usage entries need to have the appropriate \alias
entries, and all their arguments documented.
The \usage entries must correspond to syntactically valid R code.
See chapter 'Writing R documentation files' in the 'Writing R
Extensions' manual.

So as you can see it isn't actually giving me any pointers to where the issue is occuring. It is just 2 blank spaces.

My function is as follows:

#' My function
#'
#' Extracts data from the database in order to produce plots and
#' descriptive statistics.
#'
#' @param operate A vector of ID codes.
#' @param crl A vector of crl data.
#' @param nt A vector of nt data.
#' @param ref.coef Reference coefficient for gestational age.
#' @param ... Further arguments passed to or from other methods.
#'
#' @export
my_fn <- function (operate,
                   crl,
                   nt,
                   ref.coef = list(fit = function(crl) {
                     -1 + 0.05 * crl - 0.0002 * crl ^ 2
                   },
                   sd.reg = 0.5),
                   ...) {
# Some cool stuff
}

The corresponding .Rd file is as follows:

% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/my_fn.R
\name{my_fn}
\alias{my_fn}
\title{My function}
\usage{
my_fn(operate, crl, nt, 
      ref.coef = list(fit = function(crl) {     -1 + 0.05 * crl - 0.0002
  * crl^2 }, sd.reg = 0.5), ...)
}
\arguments{
\item{operate}{A vector of ID codes.}

\item{crl}{A vector of crl data.}

\item{nt}{A vector of nt data.}

\item{ref.coef}{Reference coefficient for gestational age.}

\item{...}{Further arguments passed to or from other methods.}
}
\description{
Extracts data from the database in order to produce plots and
descriptive statistics.
}

Any ideas where it is failing?

Upvotes: 5

Views: 1767

Answers (1)

hrbrmstr
hrbrmstr

Reputation: 78792

When I remove the entire ref.coef from the documentation and from the function, no error.

When I keep it in the roxygen docs and function, roxygenize it and then try to add sd.reg (to see if it was just a parse error) it still whines.

It does not look like a roxygen problem, but more the way the R CMD check is dealing with the Rd file.

An interim solution may be to do something like:

ref.coef = REF.COEF(),

and then

REF.COEF <- function() {
  list(fit = function(crl) {
    -1 + 0.05 * crl - 0.0002 * crl ^ 2
  },
  sd.reg = 0.5)
}

(so you get a good/passing R CMD check and still get the functionality you need)

and posting a msg on the R devel list about your error. This is probably a simple Rd parsing issue (but you may also want to think about simplifying the function params a bit and doing that list assignment in function vs in param).

Upvotes: 4

Related Questions