[R-pkg-devel] S3 method, useMethod and <-, using Roxygen

Hadley Wickham h.wickham at gmail.com
Fri Oct 23 13:10:19 CEST 2015


Here's a minimal reprex:

out <- roc_proc_text(rd_roclet(), "
  #' Foo
  `foo<-` <- function(x, y, value) {
    UseMethod('set_labels<-')
  }

  #' Foo
  `foo<-.default` <- function(x, y, value) {
    x
  }
  ")[[2]]

cat(format(out))

That generates

\usage{
\method{foo}{default}(x, y) <- value
}

which I believe is correct, although I don't think I've ever seen such
a construct in the wild.

Duncan: does that look right to you? (i.e. is that what the usage of
method of a replacement function should look like?)

Hadley

On Fri, Oct 23, 2015 at 3:30 AM, Daniel Lüdecke <d.luedecke at uke.de> wrote:
> Hello,
> I don't exactly know how to name my problem, so I try to describe it.
>
> In my package (sjmisc), I have a function to set label attributes to
> vectors:
>
> set_labels <- function(x, labels, ...) {
> ...
> }
>
> Usage would be:
> x <- set_labels(x, c("lo", "high"))
>
>
> No I wanted to also add functionality to directly change a value:
> set_labels(x) <- c("lo", "high")
>
>
> So I added this to my package source:
>
> #' @rdname set_labels
> #' @export
> `set_labels<-` <- function(x, force.labels = FALSE, force.values = TRUE,
> value) {
>   UseMethod("set_labels<-")
> }
>
> #' @rdname set_labels
> #' @export
> `set_labels<-.default` <- function(x, force.labels = FALSE, force.values =
> TRUE, value) {
>   x <- set_labels(x, values, force.labels, force.values)
>   x
> }
>
>
> However, running the check gives following note and warnings:
>
> * checking R code for possible problems ... NOTE
> set_labels<-.default: no visible binding for global variable 'values'
> * checking Rd files ... OK
> * checking Rd metadata ... OK
> * checking Rd line widths ... OK
> * checking Rd cross-references ... OK
> * checking for missing documentation entries ... OK
> * checking for code/documentation mismatches ... WARNING
> Functions or methods with usage in documentation object 'set_labels' but not
> in code:
>   set_labels.default
>
> * checking Rd \usage sections ... WARNING
> Objects in \usage without \alias in documentation object 'set_labels':
>   'set_labels.default'
>
> Bad \usage lines found in documentation object 'set_labels':
>     <- value
>
> 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.
>
>
> I don't know what to do here. Any help is appreciated!
>
> Thanks in advance
> Daniel
> --
>
> _____________________________________________________________________
>
> Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen
> Rechts; Gerichtsstand: Hamburg | www.uke.de
> Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr.
> Uwe Koch-Gromus, Joachim Prölß, Rainer Schoppik
> _____________________________________________________________________
>
> SAVE PAPER - THINK BEFORE PRINTING
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel



-- 
http://had.co.nz/



More information about the R-package-devel mailing list