Despite the fact that I accepted Hong Oyi's answer, I cannot help but think parse , and eval is a heavy decision. Also, as stated, this is unsafe, although for my application I can be sure that I will not receive dangerous quotes.
So, I developed an alternative, somewhat cruel approach:
udecode <- function(string){ uconv <- function(chars) intToUtf8(strtoi(chars, 16L)) ufilter <- function(string) { if (substr(string, 1, 1)=="|") uconv(substr(string, 2, 5)) else string } string <- gsub("\\\\u([[:xdigit:]]{4})", ",|\\1,", string, perl=TRUE) strings <- unlist(strsplit(string, ",")) string <- paste(sapply(strings, ufilter), collapse='') return(string) }
Any simplifications are welcome!
seancarmody
source share