Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's not possible (?) to overload a generic with a named argument after the ellipsis #65

Closed
cosi1 opened this issue May 4, 2021 · 2 comments

Comments

@cosi1
Copy link

cosi1 commented May 4, 2021

Reproducible example:

## This works fine:
`metadata7<-` <- R7::new_generic("metadata7", signature = "x")

R7::method(`metadata7<-`, "Annotated7") <- function(x, ..., value) {
  if (!is.list(value)) {
    stop("replacement 'metadata' value must be a list")
  }
  if (!length(value)) {
    names(value) <- NULL # instead of character()
  }
  x@metadata <- value
  x
}
## This doesn't
`metadata7<-` <- R7::new_generic("metadata7", signature = c("x", "...", "value"))

R7::method(`metadata7<-`, "Annotated7") <- function(x, ..., value) {
  if (!is.list(value)) {
    stop("replacement 'metadata' value must be a list")
  }
  if (!length(value)) {
    names(value) <- NULL # instead of character()
  }
  x@metadata <- value
  x
}
@hadley
Copy link
Member

hadley commented Oct 22, 2021

What's the problem? This looks ok:

`metadata7<-` <- R7::new_generic("metadata7", signature = c("x", "...", "value"))

R7::method(`metadata7<-`, "Annotated7") <- function(x, ..., value) {
  if (!is.list(value)) {
    stop("replacement 'metadata' value must be a list")
  }
  if (!length(value)) {
    names(value) <- NULL # instead of character()
  }
  x@metadata <- value
  x
}

Created on 2021-10-22 by the reprex package (v2.0.1)

@hadley
Copy link
Member

hadley commented Oct 27, 2021

Closing in favour of #85 where we'll make sure to fully support and test this pattern.

@hadley hadley closed this as completed Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants