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

Return an error when length > 1 of vector is passed to a scaler argument #66

Conversation

yutannihilation
Copy link
Contributor

@yutannihilation yutannihilation commented Dec 8, 2020

Fix some part of #64

library(rextendr)

rust_function(
  code = "fn one_float(input: f64) -> f64 {
    5.*input
  }",
  patch.crates_io = c(
    'extendr-api = { path = "/home/yutani/repo/extendr/extendr-api" }',
    'extendr-macros = { git = "https://github.com/extendr/extendr" }'
  )
)
#> build directory: /tmp/RtmpVtIB3g/file7a70ee5a29f
#> Prebuild libR bindings are not available. Run `install_libR_bindings()` to improve future build times.

one_float(numeric(0))
#> Error in one_float(numeric(0)): zero length vector
one_float(numeric(1))
#> [1] 0
one_float(numeric(2))
#> Error in one_float(numeric(2)): >1 length vector

Created on 2020-12-08 by the reprex package (v0.3.0)

(I'm yet to figure out how to write tests for this...)

@yutannihilation yutannihilation changed the title Return an error when length > 1 Return an error when length > 1 of vector is passed to a scaler argument Dec 8, 2020
@clauswilke
Copy link
Member

Errors that are sent back to R probably have to be tested from R. This could eventually be part of a test suite that we put into the rextendr package.

@yutannihilation
Copy link
Contributor Author

have to be tested from R

Makes sense, thanks. I included only minimum tests here, but let's test thoroughly from R in future.

@clauswilke
Copy link
Member

Maybe we can improve the error messages a bit? How about:
"Vector of length zero given. Expected length 1."
"Vector of length >1 given. Expected length 1."

@yutannihilation
Copy link
Contributor Author

I agree it's nice to improve the error messages. To follow the tidyverse style (c.f. https://style.tidyverse.org/error-messages.html#problem-statement), how about placing the problem state first:

"Input must be length 1. Vector of length ... given."

@clauswilke
Copy link
Member

Sounds good to me. I suggest one minor edit: "Input must be of length 1."

@yutannihilation
Copy link
Contributor Author

Thanks, I'll use it.

@yutannihilation yutannihilation merged commit c1a0bdf into extendr:master Dec 9, 2020
@yutannihilation yutannihilation deleted the fix/issue-64-stricter-check-on-vector-length branch December 9, 2020 04:55
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

Successfully merging this pull request may close these issues.

None yet

2 participants