ropensci / gendercoder

Creating R package to code free text gender responses
https://docs.ropensci.org/gendercoder/
Other
46 stars 12 forks source link

Custom dictionary should accept entries not in lower case #26

Closed ekothe closed 3 years ago

ekothe commented 5 years ago

Issue reported by Nils Reimer via email

"I noticed that the dictionary only works when you add dictionary entries in all lower case. I think it would be more user-friendly if gendercoder accepted dictionaries with capitalization and converted all entries to lower case within the recode_gender function."

Lingtax commented 3 years ago

I think you've already fixed this one @ekothe!

ekothe commented 3 years ago

At present if a participant provides a response that has capitalization and you want to add it to a custom dictionary - the dictionary entry you add will only work if it is entered in lower case. This is counter intuitive since the intuitive workflow is simply to copy the participant response verbatim when creating the new dictionary entry.

library(gendercoder)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

custom_dictionary <- list(
  `I am male` = "male")

tibble(gender = c("I am male")) %>% 
  mutate(broad_gender  = recode_gender(gender, dictionary = c(broad, custom_dictionary), fill = FALSE)
  )
#> # A tibble: 1 x 2
#>   gender    broad_gender
#>   <chr>     <chr>       
#> 1 I am male <NA>

custom_dictionary_2 <- list(
  `i am male` = "male")

tibble(gender = c("I am male")) %>% 
  mutate(broad_gender  = recode_gender(gender, dictionary = c(broad, custom_dictionary_2), fill = TRUE)
  )
#> # A tibble: 1 x 2
#>   gender    broad_gender
#>   <chr>     <chr>       
#> 1 I am male male

Created on 2021-03-16 by the reprex package (v1.0.0)