I made a function that removes en and em dashes. Great! But when I try to upload it to github and then re-install as a package something happens to the function. It replaces the dashes with some gobly gook characters. That usually means unicode stuff. I want to be able to export the function.
I tried replacing \\– with \u2013 and 0x2013. Also played with fixed and perl arguments. No luck.
Here’s:
- the function that works
- a test case
- how it looks after I import it back in
Code:
#What I exported
incomp <- function (text.var){
x <- gsub("\\–", "|", x)
x <- gsub("\\—", "|", x)
return(x)
}
#here it is in action working well
x <- c("I like...", "well?.", "–", "—")
incomp(x)
#[1] "I like..." "well?." "|" "|" #what I look like (ain't I pretty?)
#what the exported function looks like when the package compiles
incomp <- function (text.var){
x <- gsub("[–]", "|", x)
x <- gsub("[—]", "|", x)
return(x)
}
#I don't work anymore
x <- c("I like...", "well?.", "(–", "—") #I'm broken
incomp(x)
A search for r and unicode brings up lots of information but I can’t seem to apply it to my situation correctly.
- u2013 for the en dash
- u2014 for the em dash
This post is cross posted at talkstats.com. I generally do not cross post but am under the gun to get this out. I will link the two threads. LINK TO THE TALKSTATS THREAD
Thank you in advance.
The default when exporting locale of R are set to “C” I guess. Your locale maybe different.
Perhaps you can use Sys.setlocale in your package?