I think I came across a similar issue and maybe found a solution using stringi::stri_trans_general
that might help you.
My case is a bit simpler as I want to change one of the rules in "Latin-ASCII" (converting å to aa instead of a), whereas you want to ignore one of the rules.
stri_trans_general
has the option to use custom transliteration rules. Drawing on inspiration from koolmees' answer, you need to change the ñ to a random character that will not be transliterated by "Latin-ASCII" and then afterwards change it back in the custom rule list.
I am not an expert on this, but more information about custom rules can be found here or here.
# Your case
custom_rules <- "ñ > \\~;
Ñ > \\^;
::Latin-ASCII;
\\~ > ñ;
\\^ > Ñ"
stringi::stri_trans_general(c("DIVISIÓN DE MONTAÑA", "montaña"), id = custom_rules, rules = TRUE)
# My simpler case
my_rules <- "å > aa;
Å > Aa;
::Latin-ASCII;"
stringi::stri_trans_general(c("Århus", "Tårnby"), id = my_rules, rules = TRUE)
This solution also gives me the possibility to maintain a list of rules in another script, source the rules in when needed and use them in one line of stri_trans_general
. You also have the possibility to add more rules, e.g. one that replaces hyphens with a space as below.
# Add rule to also replace hyphens with a space
hyphen <- "å > aa;
'-' > ' ';
::Latin-ASCII;"
stringi::stri_trans_general("å-å", id = hyphen, rules = TRUE)