I'm trying to convert some text from ebcdic. This does the job just fine:
> iconv( "\xf0\xc1\xf0\xe5", from="IBM01047", to="ASCII", sub="?" )
[1] "0A0V"
But I'm struggling to prepare the correct input variable using paste0:
s <- "f0c1f0e5"
> s2 <- sapply(seq(1, nchar(s), by=2), function(x) paste0( "\\x", substr(s, x, x+1)) )
> iconv( s2, from="IBM01047", to="ASCII", sub="?" )
[1] "*???" "*???" "*???" "*???"
> s2
[1] "\\xf0" "\\xc1" "\\xf0" "\\xe5"
> cat(s2)
\xf0 \xc1 \xf0 \xe5
What do I need to do to the output of paste0 to get iconv() to accept it? cat() seems to be able to do it.
There are a number of paste0/backslash questions here, but none seem to address this particular issue.
Update:
Tried with raw strings, with exactly the same result:
s2 <- sapply(seq(1, nchar(s), by=2), function(x) paste0( r"(\x)", substr(s, x, x+1)) )