Coder Social home page Coder Social logo

Comments (4)

HenrikBengtsson avatar HenrikBengtsson commented on June 21, 2024 1

Might want to disable partial matching when a default is provided?

Good point.

Though, I can see how "magically" setting exact = TRUE when default is specified, can become a point of confusion and possibly result in a blocking discussion for implementing support for a new argument default. If exact = TRUE becomes the new default, which I hope it one day will, this would be moot.

An alternative to having the default value of exact depend on whether argument default i specified, is to require exact = TRUE whenever default is specified. This means you'd had to write:

w <- attr(x, "hello", exact = TRUE, default = "world")

for now, to avoid an error. This would also help to prepare for the day when exact = TRUE becomes the new default (I hope).

(Just my thoughts)

from wishlist-for-r.

HenrikBengtsson avatar HenrikBengtsson commented on June 21, 2024

I like this idea - this addition to attr() would be consistent to how getOption() and Sys.getenv() provide "default" fallbacks. Not sure if there are other functions too with this too.

FWIW, I wasn't sure whether NULL was a valid attribute value. It turns out it's not; it's not possible to have attributes will value NULL;

> 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.

PS: big fan of your work. Thanks for this repository and for all your packages! smiley

Thanks. Happy to hear :)

from wishlist-for-r.

nfultz avatar nfultz commented on June 21, 2024

Might want to disable partial matching when a default is provided?

from wishlist-for-r.

vh-d avatar vh-d commented on June 21, 2024

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.

from wishlist-for-r.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.