BIOL548O / Discussion

A repository for course discussion in BIOL548O
0 stars 0 forks source link

Logicals on characters? #22

Open scienceisfiction opened 8 years ago

scienceisfiction commented 8 years ago

This is probably a dumb question, but does someone know of a simple way to use logicals on characters? The way my data is currently tidied, most of my assertions are about characters, not numbers, for example:

DougsData %>%
  verify(year, (1998|1999)) %>%
  verify(day <= 31) %>%
  verify(length(levels(Location)) == 2) %>%
  verify(genus, ('selasphorus' | 'unknown'))

Is there a simple way to solve the problem of the last line? It would be more informative then just asking R to verify the number of genus (2) if I could make sure all values are exactly 'selasphorus' OR 'unknown'...

JoeyBernhardt commented 8 years ago

Hey @scienceisfiction,

What if you did something like this?

genera <- c("genus1", "genus2", "genus3")
DougsData %>%
assert(in_set(genera), genus)

Would that work for you?

scienceisfiction commented 8 years ago

Thanks @JoeyBernhardt ! Worked perfectly--of course it was something we went over in class that I just missed, lol.