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

set_props() fails when setting property named object #423

Open
lawremi opened this issue Aug 24, 2024 · 3 comments
Open

set_props() fails when setting property named object #423

lawremi opened this issue Aug 24, 2024 · 3 comments

Comments

@lawremi
Copy link
Collaborator

lawremi commented Aug 24, 2024

Fairly obvious. The rough equivalent methods::initialize() avoids this by naming its first parameter .Object, which is a lot less likely to collide.

@hadley
Copy link
Member

hadley commented Aug 26, 2024

I like the idea of using `_object`, as inspired by transform().

@t-kalinowski
Copy link
Member

t-kalinowski commented Oct 10, 2024

What do we think of:

set_props <- function(...) {
  dots <- list(...)
  object <- dots[[1]]
  vals <- dots[-1]
  props(object) <- vals
  object
}

The issue of guarding against unintended argument matches is quite frustrating. I recall various proposals, such as those on the R-dev mailing list, for how to improve this.

I really wish I could use ; as a separator when defining and calling functions, where arguments before ; would match positionally, and arguments after ; would match by name. For example:

set_props <- function(object; ...) {
  # object always matched positionally
  props(object) <- list(...)
  object
}
set_props(foo, object = bar) # foo matched to `object`

Similarly, for functions without a ; in their definition, callers could do something like:

dplyr::mutate(df; .data = 1:3)
# or 
df |> dplyr::mutate(; .data = 1:3)

@lawremi
Copy link
Collaborator Author

lawremi commented Oct 15, 2024

I would prefer to just mangle the argument name, because it is important to have an actual argument for the object, at least for the sake of clarity.

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

3 participants