-
Notifications
You must be signed in to change notification settings - Fork 4
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
WISH: attr() allows to provide a default fallback value #139
Comments
I like this idea - this addition to FWIW, I wasn't sure whether > x <- 42L; attributes(x) <- alist(abc = 1, def = NULL, ghi = 3)
> str(attributes(x))
List of 2
$ abc: num 1
$ ghi: num 3 In other words, one does not have to account for that as a special case and your "current" snippet is sufficient.
Thanks. Happy to hear :) |
Might want to disable partial matching when a default is provided? |
I prefer more generic approach like this in my code w <- ifnull(attr(x, "hello"), "world") Would be nice to have something like this in base but the addition would potentially break someone's code of course. |
Good point. Though, I can see how "magically" setting An alternative to having the default value of w <- attr(x, "hello", exact = TRUE, default = "world") for now, to avoid an error. This would also help to prepare for the day when (Just my thoughts) |
Wish
attr()
allows to specifydefault=value
to return a default value if the requested attribute is not found.PS: big fan of your work. Thanks for this repository and for all your packages! 😃
The text was updated successfully, but these errors were encountered: