To convert strings to ascii code in R, I typically use:
> strtoi(charToRaw("abcd"),16L)
[1] 97 98 99 100
Is there a function to do the inverse, i.e.
>myDesiredFunc(c(97 98 99 100))
[1] "abcd"
Thanks.
To convert strings to ascii code in R, I typically use:
> strtoi(charToRaw("abcd"),16L)
[1] 97 98 99 100
Is there a function to do the inverse, i.e.
>myDesiredFunc(c(97 98 99 100))
[1] "abcd"
Thanks.
I just noticed that R
has a intToUtf8
and utf8ToInt
functions that does the same thing.
> test<-utf8ToInt("Apples")
> test
[1] 65 112 112 108 101 115
> intToUtf8(test)
[1] "Apples"
Also:
rawToChar(as.raw(c(97,98,99,100)))
Type ?charToRaw
at the command prompt for more info.
Best I found is:
readLines(rawConnection(as.raw(c(97,98,99,100,13))))
Although I guess it is better to close the connection
con = rawConnection(as.raw(c(97,98,99,100,13)))
res = readLines(con);
close(con);
show(res);
[1] "abcd"
© 2022 - 2024 — McMap. All rights reserved.