Skip to content

Commit

Permalink
docs(develop): add note about argument checking on the R side
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Jul 10, 2024
1 parent 1e7e0c0 commit 571b5e3
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,35 @@ impl From<ListSexp> for Wrap<Vec<Expr>> {
}
}
```

### Argument check on the R side

Want to check arguments on the R side, use functions from the imported `rlang` package.
One common function is `check_dots_empty0()`, which checks that `...` is empty.

When using such functions, wrap the entire process with `wrap({})` and catch errors that occur on the R side with the `wrap()` function.
This will display more informative error messages.

For example, if you pass a value to `...` in the `any()` method of Expr defined as follows:

```r
expr__any <- function(..., ignore_nulls = TRUE) {
wrap({
check_dots_empty0(...)
self$`_rexpr`$any(ignore_nulls)
})
}
```

Display an error message like this:

```r
pl$lit(1)$any(foo = 1)
#> Error:
#> ! Evaluation failed in `$any()`.
#> Caused by error:
#> ! `...` must be empty.
#> ✖ Problematic argument:
#> • foo = 1
#> Run `rlang::last_trace()` to see where the error occurred.
```

0 comments on commit 571b5e3

Please sign in to comment.