Reputation: 317
From an API I get a Base64 encoded dataset. I use RCurl::base64
to decode it, but it's serialized. How do I convert it to a dataframe?
After decoding my return, I get a long textstring with semi colon separated data and column names. Looks like this:
[1] "\"lfdn\";\"pseudonym\";\"external_lfdn\";\"tester\"\r\n\"50\";\"434444345\";\"0\";\"0\"\r\n\"91\";\"454444748\";\"0\";\"0\"\r\n\
You can see the structure with a simple cat(x)
:
"lfdn";"pseudonym";"external_lfdn";"tester"
"50";"434444345";"0";"0"
"91";"454444748";"0";"0"
"111";"444444141";"0";"0"
I've tried the obvious unserialize(x)
, but I get:
R> Error in unserialize(enc) :
R> character vectors are no longer accepted by unserialize()
Whatever I throw at it... I can write the object to disk, and read it back in, but I prefer to avoid that.
Getting the data from the serialized textstring into a dataframe with column names would be great!
Upvotes: 1
Views: 303
Reputation: 20379
This should do the trick:
read.table(text=j, header = TRUE, sep = ";")
# lfdn pseudonym external_lfdn tester
# 1 50 434444345 0 0
# 2 91 454444748 0 0
Note. I copied your string from above, it does not contain the last row with 111 in it.
Upvotes: 1