R help needed, please. To be clear: I'm almost positive I'm having R problems, not API problems.
I'm trying to make a data frame from the results of API calls to the RStudio Connect server to get usage information using R calls. The return is a list of usage records, with each record being a list of key-value pairs.
with seven entries per inner list.
The problem is that some of the values are NULL, so when I convert to a data frame with
data.frame(matrix(unlist(payload$results), nrow=length(payload$results), byrow=T), stringsAsFactors=FALSE)
or anything similar, the key-value entries with NULLs are dropped so that the record has, say, five pairs rather than seven. Records from that point down go into the data frame misaligned and therefore garbage.
I've tried to convert the NULLs to NA or to empty strings by applying functions to the lists:
a[sapply(a, is.null)] <- NA a[sapply(a, function(x) is.null(x))] <- NA a[sapply(a, function(x) length(x)==0L)] <- NA
and many other variations. None make any difference.
If anyone has working code to make a properly-aligned data frame from the API's return list I'd appreciate it. Or a link to a StackOverflow page, or even a list of search terms which will give me a solution rather than something kinda but not quite like what I'm looking for.