mllg / checkmate

Fast and versatile argument checks
https://mllg.github.io/checkmate/
Other
261 stars 30 forks source link

How to use `checkCharacter()`, arg `names =` ? #249

Open vertesy opened 10 months ago

vertesy commented 10 months ago

Hey,

first off, thanks for the great package!

In checkCharacter(), arg names = you write:

[character(1)] Check for names. See checkNamed for possible values. Default is “any” which performs no check at all. Note that you can use checkSubset to check for a specific set of names.

Thank you for your time taken!

tdeenes commented 10 months ago

You seem to misunderstand what the manual says: the possible values for the names argument of checkCharacter are listed in ?checkNamed (see the type argument). So you can have sthing like:

checkCharacter(c(a = "A", b = "B"), names = "unique") # this passes
#checkCharacter(c(a = "A", b = "B"), names = "unnamed") # this fails

If you want to check for a specific set of names, you have to use checkSubset:

x <- c(a = "A", b = "B")
assert(
  checkCharacter(x),
  checkSubset(names(x), choices = base::letters),
  combine = "and"
)
vertesy commented 10 months ago

Ah, thanks, especially for typing out the examples!! clear now!