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

in standalone-types-check,check_number_whole() min and max don't accept integer. #1702

Open
olivroy opened this issue Apr 19, 2024 · 1 comment

Comments

@olivroy
Copy link
Contributor

olivroy commented Apr 19, 2024

rlang:::check_number_whole(2, max = 3L)
#> Error 
#> ! `max` must be a single double value.

But my use case was that max = length(something) which is integer, and triggered this unfriendly error.

Is there something rlang can do that will not affect performance.

For what it's worth, I think it would still be valid to accept integer for check_number_decimal() too.

@olivroy
Copy link
Contributor Author

olivroy commented Jul 11, 2024

I investigated a bit further and saw that it is part of a TODO item in the C core.

double r_arg_as_double(r_obj* x, const char* arg) {
  // TODO: Coercion of int and lgl values
  if (!_r_is_double(x, 1, -1)) {
    r_abort("`%s` must be a single double value.", arg);
  }
  return r_dbl_get(x, 0);
}

Where should the conversion happen?

In R, it would just be

if (is.integer(x)) {
 x <- as.numeric(x)
}

But I don't know how to make that happen in C...

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

1 participant