Skip to content

Instantly share code, notes, and snippets.

@scrogster
Last active November 26, 2017 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scrogster/4d541af6ea68470819ecbdc385879bb8 to your computer and use it in GitHub Desktop.
Save scrogster/4d541af6ea68470819ecbdc385879bb8 to your computer and use it in GitHub Desktop.
#function to substitute vowels with Maori macrons into text strings in R
#there's probably a fancier way to do this, but it works OK.
#just precede vowels requiring a macron with '@' and the function will substitute the appropriate vowel with macron.
#Handy for graph labelling etc.
maorify<-function(x){
x<-gsub("@a","\u0101", x) #macron a
x<-gsub("@e","\u0113", x) #macron e
x<-gsub("@i","\u012B", x) #macron i
x<-gsub("@o","\u014D", x) #macron o
x<-gsub("@u","\u016B", x) #macron u
return(x)
}
#Example usage
hist(rpois(1000, 5), xlab=maorify("Number of T@u@i per hectare"),
main=maorify("Density of T@u@i at Whakat@ane"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment