r-lib / rlang

Low-level API for programming with R
https://rlang.r-lib.org
Other
491 stars 131 forks source link

Request: Export type-checking function(s) (e.g. `standalone-check-types`) #1672

Closed orgadish closed 7 months ago

orgadish commented 7 months ago

rlang has an excellent set of check_XXX functions with tailored error messages. It would be great if this were available (and maintained) for public use -- in my mind, this would supersede assertthat, which has not been updated in over 4 years (or vec_assert which is lifecycle: questioning).

Alternatively, these could be exported using a single function (e.g. rlang::check) which takes one of the already exported rlang::is_ functions and generates a good error message. e.g. rlang::check(x, rlang::is_string, allow_null = FALSE, allow_na = TRUE)

Related to discussion in r-lib/rlang#1111

olivroy commented 7 months ago

I think there may be plans to create a new package for that: https://github.com/tidyverse/design/issues/160#issuecomment-1664166965

But meanwhile, in your packages, you can use usethis::use_standalone("r-lib/rlang", "type-check")

See ggplot2 https://github.com/tidyverse/ggplot2/blob/main/R/import-standalone-types-check.R

https://usethis.r-lib.org/reference/use_standalone.html?q=use_sta#null

orgadish commented 7 months ago

Thanks for the use_standalone tip!

I hope tidyverse/design#160 goes through!