Hi everbody,
I think I'm making slight progress in this. I still want to get and set the
usesleft attribute in the tokentable (ideally for multiple respondents at once depending on other attributes - but first things first). I use R with the handy limer package (s.
github.com/cloudyr/limer
)
Some methods to get (and set) participant properties.
Code:
### List participants with method list_participants via limer
tok <- call_limer(method = "list_participants",
params = list(iSurveyID = sid))
str(tok)
This returns a data frame with the basic information on the respondents (here: shortened and anonymized):
Code:
'data.frame': 10 obs. of 3 variables:
$ tid : chr "1" "2" "3" "4" ...
$ token : chr "token1" "token2" "token3"...
$ participant_info:'data.frame': 10 obs. of 3 variables:
..$ firstname: chr "" "" "" "" ...
..$ lastname : chr "" "" "" "" ...
..$ email : chr "email1@email.com" "email2@email.com" "email3@email.com ...
There is another function in limer, a wrapping the method get_participants() from the remote:
Code:
### Function get_participants() from limer
#https://github.com/cloudyr/limer/blob/7c10cc62f703d03bcac23fb444ebd39cf5d0e2b0/R/get_participants.R
attr <- c('email', 'usesleft') # select some attributes.
tok <- get_participants(sid, iStart=0, iLimit=10, bUnused=FALSE, aAttributes=attr)
str(tok)
This returns the information as above, but this time with the usesleft for each participant as a column.
Code:
'data.frame': 10 obs. of 4 variables:
$ tid : chr "1" "2" "3" "4" ...
$ token : chr "token1" "token2" "token3" ...
$ participant_info:'data.frame': 10 obs. of 3 variables:
..$ firstname: chr "" "" "" "" ...
..$ lastname : chr "" "" "" "" ...
..$ email : chr "mail1@mail.com" "mail2@mail.com" "mail3@mail.com" ...
$ usesleft : chr "1" "1" "1" "1" ...
You can easily extract the vector of usesleft by
Code:
tok$usesleft # vector of usesleft
and get
Code:
[1] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
I figured out how to get the participant information for single participants:
Code:
### Method get_participant_properties (via limer)
# https://api.limesurvey.org/classes/remotecontrol_handle.html#method_get_participant_properties
attr <- c("tid", "email", "token", 'usesleft', 'attribute_1')
tok <- call_limer(method = "get_participant_properties",
params = list(iSurveyID = sid,
tokenid = 1,
aTokenProperties = attr))
str(tok)
This returns:
Code:
List of 4
$ tid : chr "1"
$ email : chr "email1@email.com"
$ token : chr "token1"
$ usesleft: chr “1”
Now that this works my questions are:
(1) How to get attributes for multiple participants at once (i.e. vectorized, e.g. tokenid = 1:100)?
(2) How to SET attributes for one participant?
This should work with the set_participant_properties - but how?
Code:
# https://api.limesurvey.org/classes/remotecontrol_handle.html#method_set_participant_properties
call_limer(method = "set_participant_properties",
params = list(iSurveyID = sid,
tokenid = 1,
aTokenProperties = "usesleft",
aTokenData = ?????))
And if that is clear:
(3) How to SET attributes for multiple participants at once? (If possible also vectorized, not in a loop)
Thanks for your time and help!
Best, G