cloudyr/Rmonkey

Attempt to set an attribute on null

Closed this issue · 2 comments

I'm getting an "Error in setNames(k$text, k$answer_id) : attempt to set an attribute on NULL" error when I try to cast the Rmonkey response object as a data frame. It looks like one of my survey questions (It has a type of "label - maybe it's the button to go to the next page?) has a null $text value. Could that be an issue?

Here's my traceback:

g<-Rmonkey::getresponses(r,s[[1]])
as.data.frame(g)
Error in setNames(k$text, k$answer_id) :
attempt to set an attribute on NULL
traceback()
12: setNames(k$text, k$answer_id)
11: FUN(X[[i]], ...)
10: lapply(X = X, FUN = FUN, ...)
9: sapply(i$answers, function(k) {
setNames(k$text, k$answer_id)
})
8: FUN(X[[i]], ...)
7: lapply(X = X, FUN = FUN, ...)
6: sapply(questions, function(i) {
sapply(i$answers, function(k) {
setNames(k$text, k$answer_id)
})
})
5: as.data.frame.sm_response(X[[i]], ...)
4: FUN(X[[i]], ...)
3: lapply(x, as.data.frame, details = details, ...)
2: as.data.frame.sm_response_list(g)
1: as.data.frame(g)

the response object looks something like this:

str(g[[1]])
List of 2
$ respondent_id: chr "4305718703"
$ questions :List of 16
..$ :List of 2
.. ..$ answers :List of 3
.. .. ..$ :List of 1
.. .. .. ..$ row: chr "9571169461"
.. .. ..$ :List of 1
.. .. .. ..$ row: chr "9561318489"
.. .. ..$ :List of 1
.. .. .. ..$ row: chr "9561318492"
.. ..$ question_id: chr "871278703"
..$ :List of 2
.. ..$ answers :List of 3
.. .. ..$ :List of 2
.. .. .. ..$ col: chr "9561352935"
.. .. .. ..$ row: chr "9561352929"
.. .. ..$ :List of 2
.. .. .. ..$ col: chr "9561352935"
.. .. .. ..$ row: chr "9561352930"
.. .. ..$ :List of 2
.. .. .. ..$ col: chr "9561352935"
.. .. .. ..$ row: chr "9561352931"
.. ..$ question_id: chr "871282932"

...and so on, for 16 questions

@bloyal I have sent a patch that I think should fix this. Can you see if it works for you?