poissonconsulting / chk

An R package for developers to check user-supplied function arguments
https://poissonconsulting.github.io/chk/
Other
48 stars 4 forks source link

Write chkor_vld() #96

Closed joethorley closed 3 years ago

joethorley commented 3 years ago

chkor_vld(...) could take series of vld_ functions and if all false then generates chk_ produce informative error message.

Much like chk_null_or()

joethorley commented 3 years ago

Added and much faster than chkr() but still relative slow

  library(chk)

  ptm <- proc.time()

  for(i in seq_len(1000)) {
    chkor(chk_flag(1), chk_flag(TRUE))
  }

  proc.time() - ptm
#>    user  system elapsed 
#>   7.893   0.237   8.163

  ptm <- proc.time()

  for(i in seq_len(1000)) {
    chk_null_or(TRUE, chk_flag)
  }
  proc.time() - ptm
#>    user  system elapsed 
#>   0.033   0.000   0.034

  ptm <- proc.time()

  for(i in seq_len(1000)) {
    chk_null_or(TRUE, vld = vld_flag)
  }
  proc.time() - ptm
#>    user  system elapsed 
#>   0.004   0.000   0.004

  ptm <- proc.time()

  for(i in seq_len(1000)) {
    chkor_vld(vld_flag(1), vld_flag(TRUE))
  }

  proc.time() - ptm
#>    user  system elapsed 
#>   0.044   0.001   0.045

  ptm <- proc.time()

  for(i in seq_len(1000)) {
    chk_number(1)
    chk_flag(TRUE)
  }
  proc.time() - ptm
#>    user  system elapsed 
#>   0.005   0.000   0.006

Created on 2021-09-02 by the reprex package (v2.0.1)

joethorley commented 3 years ago

Documented as follows

#' `chkor_vld()` is relatively slow.
#' If at all possible use [chk_null_or()] or first test using the individual
#' `vld_` functions and then call `chkor_vld()` to generate an informative
#' error message.
github-actions[bot] commented 2 months ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.