Re: [R-pkg-devel] S3 method, useMethod and <-, using Roxygen
Ok, this might be a Roxygene issue, so I would close this discussion here and file an issue at GitHub for further investigation. What I found out so far: #' @rdname set_label #' @export `set_label<-` <- function(x, attr.string = NULL, value) { UseMethod("set_label<-") } #' @rdname set_label #' @export `set_label<-.default` <- function(x, attr.string = NULL, value) { x <- set_label(x, value, attr.string) x } creates following rd-file: % Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/set_label.R \name{set_label} \alias{set_label} \alias{set_label<-} \alias{set_label<-.default} \alias{set_var_labels} \title{Add variable label(s) to variables} \usage{ set_label(x, lab, attr.string = NULL) set_var_labels(x, lab, attr.string = NULL) set_label(x, attr.string = NULL) <- value \method{set_label}{default}(x, attr.string = NULL) <- value } while #' @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, value, force.labels, force.values) x } results in % Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/set_labels.R \name{set_labels} \alias{set_labels} \alias{set_labels<-} \alias{set_labels<-.default} \alias{set_val_labels} \title{Add value labels to variables} \usage{ set_labels(x, labels, force.labels = FALSE, force.values = TRUE) set_val_labels(x, labels, force.labels = FALSE, force.values = TRUE) set_labels(x, force.labels = FALSE, force.values = TRUE) <- value \method{set_labels}{default}(x, force.labels = FALSE, force.values = TRUE) <- value } There's a carriage return (or similar) in the generated rd-file which throws the warning message in the check procedure. I cam up with removing "#' @rdname set_labels", because 1) it works fine then and 2) my index-page of the package help does not list redundant function names multiple times. Best Daniel Am 23.10.2015 um 13:10 schrieb Hadley Wickham: 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üdeckewrote: 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, ...) { ... } -- _ 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Re: [R-pkg-devel] S3 method, useMethod and <-, using Roxygen
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üdeckewrote: > 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@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-package-devel -- http://had.co.nz/ __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Re: [R-pkg-devel] S3 method, useMethod and <-, using Roxygen
> which I believe is correct, although I don't think I've ever seen such > a construct in the wild. What would be the proper way to define such methods? Eg, I want `set_label` to work like this: x <- set_label(x, "my label") and additionally, like this: set_label(x) <- "my label" How would I define the latter function? (this is how it is currently done by me) #' @export set_label <- function(x, lab, attr.string = NULL) { ... } #' @rdname set_label #' @export `set_label<-` <- function(x, attr.string = NULL, value) { UseMethod("set_label<-") } #' @rdname set_label #' @export `set_label<-.default` <- function(x, attr.string = NULL, value) { x <- set_label(x, value, attr.string) x } Am 23.10.2015 um 13:10 schrieb Hadley Wickham: 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 } -- _ 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Re: [R-pkg-devel] S3 method, useMethod and <-, using Roxygen
Ok, the "Note" is due a typo (x <- set_labels(x, values,... "values" should be "value"). But still after fixing this, the two warnings remain. Am 23.10.2015 um 10:30 schrieb Daniel Lüdecke: 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel