phillc73 / abettor

An R package for connecting to the online betting exchange Betfair, via their API-NG product, using JSON-RPC.
Other
51 stars 36 forks source link

getAccountStatement uses legacyData fields and code is messy #51

Closed Soccerama closed 3 years ago

Soccerama commented 3 years ago

I rewrote this function a few months ago to allow the retrieval of more than 100 records. It works but the code uses the legacyData fields rather than the itemClassData json field. This was my first contribution to abettor and it shows - the code is messy, difficult to read and this may make it more error prone. I've been trying to work out how to unpack the json in a more efficient manner but it is proving difficult. Seeking the help of some experts on this. If anybody reading this can help with unpacking a dataframe of elements, each of which is in a json (key/value pair) format that would be greatly appreciated. My attempts have been along these lines and have all ended in a similar place, none of them with the clean dataframe structure that is required as an output from the function. I put the json field into a dataframe using accItem <- accOrder$result$accountStatement$itemClassData Then have tried using accDF <- map(accItem[,1], jsonlite::fromJSON(simplifyDataFrame = simplifyDataFrame)) which appears to give a dataframe with 100 eelements, each of which is a list with 21 elements - the 21 fields from within itemClassData.

Soccerama commented 3 years ago

Think I've finally found it: do.call(rbind, accDF) seems to work. Lots of time trawling stackoverflow to find this answer. Will now work on a more robust version of this function.