Question: I have 2 tables:

* candidates (candidat\_id, first\_name, name)
* files (file\_id, candidat\_id, category, operation)

I want to display the list, sorted in alphabetical order of the names, of candidates who have more than one examination file with the same category and the same operation.

Answer: 
```
library(dplyr)
library(stringr)

add_spaces <- function(colnames, words) {
  for(i in 1:length(colnames)) {
    for(j in words) {
      if(str_detect(string = colnames[i], pattern = j)) {
        colnames[i] <- str_replace(string = colnames[i], j, glue::glue("{str_to_lower(j)}_"))
      }
    }
  }

  colnames <- colnames %>% 
    str_remove("\\_+$") # Remove hyphens at the end

  message("Characters not identified: ")
  print(str_remove_all(colnames, "[a-z_]"))

  invisible(colnames)
}

colnames <- names(<file>) # Capture colnames  # Using c("BOOKINGPROCESSNOTEADDED", "BOOKEDDATETIME", "BOOKINGSTATUS")

words <- c("BOOKING", "BOOKED", "PROCESS") # Create first list of words

colnames <- add_spaces(colnames, words) # Run the first iteration        

> Characters not identified:
[1] "NOTEADDED" "DATETIME"  "STATUS"

words <- c(words, "NOTE", "ADDED", "DATE", "TIME", "STATUS") # Augment list with missing words

colnames <- add_spaces(colnames, words) # Rerun, ... repeat as needed

colnames 

[1] "booking_process_note_added" "booked_date_time"           "booking_status" 

```
I would build the dictionary manually:

* Start with an empty dictionary
* Get all names
* Find one containing uppercase
* Manually add words to the dictionary to split that one
* Split all of them using the current dictionary

Repeat the last 3 steps until all words are split. For example, with the 3 names you posted, the dictionary would first get `c("booking", "status")`, and that name would have no uppercase. The name `BOOKINGPROCESSNOTEADDED` would become `booking_PROCESSNOTEADDED`; if you chose that, you'd add `c("process", "note", "added")` to the dictionary, and find `BOOKEDDATETIME` next. Now you need to decide on the words: is it `c("booked", "date", "time")` or `c("booked", "datetime")`?

And so on.