7

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

4
  • Are you using roxygen or roxygen2? Commented Jan 16, 2012 at 3:00
  • @hadley: roxygen2, just added roxygen tag also to attain more attention. Commented Jan 16, 2012 at 8:32
  • What version are you using? Roxygen2 should do that automatically since 2.2 Commented Jan 16, 2012 at 14:28
  • @hadley: I am using 2.2.2 from CRAN. Without @usage tag, I get the above result. Commented Jan 16, 2012 at 14:34

1 Answer 1

9

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 
Sign up to request clarification or add additional context in comments.

3 Comments

Works like a charm, thanks @Andrie for pointing my attention to @usage - I just do not how could I take no notice of this useful tag.
That's because you should never need to use @usage - any time you do it is a bug in roxygen2 and you should file a bug report.
Thanks @hadley, I have added a comment on the appropriate issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.