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

New tib_custom() as a variant of tib_scalar() with different defaults? #183

Open
krlmlr opened this issue May 26, 2023 · 2 comments
Open

Comments

@krlmlr
Copy link
Collaborator

krlmlr commented May 26, 2023

For ingesting a datetime field, I use:

    tib_scalar("start", vctrs::new_datetime(), ptype_inner = character(), transform = ~ as.POSIXct(.x, tz = "UTC")),

Should we support

    tib_custom("start", ~ as.POSIXct(.x, tz = "UTC")),

with tib_custom() forwarding to tib_scalar() but with different defaults (in particular, ptype_inner = character() and transform required, perhaps ptype optional)?

as.POSIXct(character())
#> POSIXct of length 0

Created on 2023-05-26 by the reprex package (v2.0.1)

@mgirlich
Copy link
Owner

mgirlich commented Jul 7, 2023

I don't think we need tib_custom() for this. We could simply change tib_scalar() a little, e.g. adding

if (is_missing(ptype)) {
    if (is_missing(ptype_inner) || is_null(ptype_inner) || is_null(transform)) {
      cli_abort("Must provide {.arg ptype} or both of {.arg ptype_inner} and {.arg transform}.")
    }

    ptype <- transform(ptype_inner)
  }

But I also like the clarity of

tib_scalar(
  "start",
  vctrs::new_datetime(),
  ptype_inner = character(),
  transform = ~ as.POSIXct(.x, tz = "UTC")
)

It is a bit redundant but also a bit easier to understand what the outcome of this tib_scalar() is.

@krlmlr
Copy link
Collaborator Author

krlmlr commented Jul 7, 2023

We don't need tib_custom(), it would be a handy helper with different defaults than tib_scalar() .

Do you really need is_missing() when you can always do is.null() ?

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