Question: I want to change this:

```
input <- c("Théodore Agrippa d'AUBIGNÉ", "Vital d'AUDIGUIER DE LA MENOR")

```

into this :

```
output <- c("Théodore Agrippa d'Aubigné", "Vital d'Audiguier De La Menor")

```

The only words that should be modified are those that are all upper case.

**Edit:** 

An edge case, where first letter of sequence isn't in `[A-Z]`:

```
input <- "Philippe Fabre d'ÉGLANTINE"

```

Answer: 
Here is an alternative solution:

```
gsub("(?<=\\p{L})(\\p{L}+)", "\\L\\1", input, perl = TRUE)

```

I'm not trying to compete with the other existing answers, I just solved (or tried) for the challenge and share it here because it might be useful for someone and/or I get constructive feedback on how it could be improved.

**Edit**

I had for some reason skipped over:

> 
> only words [...] that are all upper case
> 
> 
> 

I think the following deals a bit better with that:

```
gsub("(?<=\\b\\p{Lu})(\\p{Lu}+\\b)", "\\L\\1", input, perl = TRUE)

```
You could also use the [snakecase pkg](https://github.com/Tazinho/snakecase) and specifically set `sep_in = " "` to not delete non-alphanumerics like `'` (default is `sep_in = "[^[:alnum:]]"`):

```r
library(snakecase)

input <- c("Théodore Agrippa d'AUBIGNÉ", "Vital d'AUDIGUIER DE LA MENOR")
output <- c("Théodore Agrippa d'Aubigné", "Vital d'Audiguier De La Menor")

to_title_case(input, sep_in = " ")
#> [1] "Théodore Agrippa d'Aubigné"    "Vital d'Audiguier De La Menor"

identical(to_title_case(input, sep_in = " "), output)
#> [1] TRUE

```

Created on 2019-08-01 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)

This works because

1. **snakecase** treats special characters as words, when they are not specified as input separators via `sep_in`.
2. `snakecase::to_title_case()` first applies `snakecase::to_sentence_case()` which separates words by " " and afterwards wraps the (lower case) result inside `tools::toTitleCase()` which doesn't capitalize lone standing "d"'s, i.e. " d ' aubigné" becomes " d ' Aubigné".
3. **snakecase** always "protects" its output, i.e. it cleanes up the messy and probably not intended output separators (here " ") around non-alphanumeric characters (here `'`). (For numeric characters the behaviour can be adjusted via the `numerals` argument).