Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documenting setter functions with roxygen

I have a function that does nothing more than ads a unique attr to any R object. Base demo:

#' Setter function
#' @param x an R object
#' @param value a character value to set
#' @export
`foo<-` <- function(x, value){
    attr(x, 'foo') <- value
    return(x)
}

This works like a charm except for generating a good Rd file, relevant part:

\usage{
  foo(var, value) <- value
}

And of course it triggers a warning while running R CMD check as it should be foo(var) <- value.

Any hints would be really apprecieted!


Update: thanks to richierocks it seems there is a fix

like image 693
daroczig Avatar asked Jan 15 '12 21:01

daroczig


People also ask

What is .RD file in R?

R objects are documented in files written in “R documentation” (Rd) format, a simple markup language much of which closely resembles (La)TeX, which can be processed into a variety of formats, including LaTeX, HTML and plain text.

How do I add documents in R?

To add documentation to an R package, you need to create a subdirectory “ man ” containing a set of files, one per function, in a special R Documentation format ( . Rd ). These will be the source for the documentation for each function; R processes them to create plain text, PDF, and HTML versions.


1 Answers

You can use the roxygen tag @usage

Here is an example from one of my packages:

#' @rdname pattern
#' @usage pattern(x) <- value
#' @param value New value
#' @export pattern<-
"pattern<-" <- function(x, value=c("^", "($|(_\\d+(_\\d+)*)$)")){
  attr(x, "pattern") <- value
  x
}

This results in my desired documentation:

Usage

  pattern(x) <- value

Arguments
x surveydata object

value New value
like image 67
Andrie Avatar answered Sep 22 '22 22:09

Andrie