Open wjones127 opened 8 years ago
Beautiful! Well done, @wjones127.
I'm looking at your code @wjones127 , and wondering whether you found that using the map function from purr was essential to your solution or whether it was more of an experiment? Wes was using the more traditional seq_along...
Yeah I had purrr
in there because I though I might need some of it's functionality, but I think in the final code all the map
calls could be replaced with lapply
.
I found a working solution to Wes's problem of converting a dataframe into the JSON format he wanted.
The approach differs from Wes's mainly in that I just do the nesting of subquestions for every question, and later prune out the subquestions that have
NA
as their id. His approach was pretty close, but there is a bit of a frustrating limitation to thenest()
function: it can't be applied twice in a row to the same data frame. You can see in thenest_subquestions
function that I had to create separate data frames with the nested subquestions and options, and then merge them together; this couldn't be done in the same data frame without getting an error.