Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
68104fa
removed api_key references from the code
seanofahey Dec 24, 2016
18bd228
initial commit. Separated out from the surveylist function
seanofahey Dec 26, 2016
cba3d42
updated content to parsed_content, removed api_key references, update…
seanofahey Dec 26, 2016
2f5ca72
removed api_key references, updated api url to v3, changed post to ge…
seanofahey Dec 26, 2016
3f2afeb
initial commit
seanofahey Dec 26, 2016
f336433
returned print.sm_survey to surveylist
seanofahey Dec 26, 2016
4e44f41
modified lapply function
seanofahey Dec 26, 2016
fc8d0e9
updated to use SurveyMonkey API V3 urls, removed api_key references, …
seanofahey Dec 27, 2016
8507b7d
updated surveyquetions function to match new api data structure and t…
seanofahey Dec 27, 2016
000dc2c
modified surveyquestions and surveypreview functions to use the surve…
seanofahey Dec 27, 2016
fcbbb0a
updated print.sm_survey to match fields for SurveyMonkey V3 API
seanofahey Dec 27, 2016
2f1bd41
Merge branch 'master' of https://github.com/seanofahey/Rmonkey
seanofahey Dec 27, 2016
82624cf
getresponses updated to SM API v3. api_key code removed. function c…
seanofahey Dec 27, 2016
a4d85a3
Merge branch 'master' of https://github.com/seanofahey/Rmonkey
seanofahey Dec 27, 2016
dd1f4a3
changed POST to GET, updated class function, commented out content$st…
seanofahey Dec 27, 2016
3136434
added json to header and fixed code to add sm_userdetails class
seanofahey Dec 27, 2016
d33041f
initial commit
seanofahey Dec 27, 2016
8ecfba3
moved print.sm_survey to surveydetails from surveylist
seanofahey Dec 27, 2016
e93df55
switched order of parameters in the function call
seanofahey Dec 27, 2016
c6f390f
updated to demonstrate more functions
seanofahey Dec 27, 2016
cc26c75
removed question_details option from surveydetails call since it is n…
seanofahey Dec 28, 2016
804b915
added more functions
seanofahey Dec 28, 2016
6962584
removed content$status error checking block. Reformatted class assig…
seanofahey Dec 28, 2016
9781142
added survey questions, surveypreview, and getreponses examples
seanofahey Dec 28, 2016
e0ab986
created new documentation for smlogin
seanofahey Dec 28, 2016
6521f75
fixed missing quote
seanofahey Dec 28, 2016
ed2f6d0
fixed missing quote
seanofahey Dec 28, 2016
2ce2215
added selected API parameters
seanofahey Dec 28, 2016
332d160
updated api references for qtype and varnames variables
seanofahey Dec 28, 2016
97d9da3
changed format of content call
seanofahey Dec 29, 2016
70a6a12
changed format of content call
seanofahey Dec 29, 2016
2c590d5
changed format of content call
seanofahey Dec 29, 2016
cb8159b
added jsonlite
seanofahey Dec 29, 2016
f0ffcda
add description of SurveyMonkey API response JSON and commented out f…
seanofahey Dec 31, 2016
f1a265a
added comment detailing the list structure form the JSON response
seanofahey Dec 31, 2016
ef3fec0
updated comments about json
seanofahey Dec 31, 2016
03ca44f
changed question_id, and answer_id references to id (per API v3). ch…
seanofahey Dec 31, 2016
00523b0
initial commit - function to unpack json nested list for survey quest…
seanofahey Jan 1, 2017
1807154
added comments and fixed row id and text function
seanofahey Jan 1, 2017
e2591cc
modified structure to include a repeat loop to simplify code
seanofahey Jan 2, 2017
9bac83a
data frame variables renamed. Future work comments added
seanofahey Jan 2, 2017
a066046
fixed error in variable name (detail -> sd)
seanofahey Jan 2, 2017
b1a5843
fixed issue with HTML text clean up
seanofahey Jan 2, 2017
5d626d6
fixed GET to allow queries
seanofahey Jan 2, 2017
6e168ef
modified function arguments to match v3 api. changed GET to pass que…
seanofahey Jan 2, 2017
1428fac
changed default value for question_details to be TRUE
seanofahey Jan 2, 2017
c352fe5
updated the GET command to use query vs. body
seanofahey Jan 2, 2017
175f600
initial commit of code to create a data frame from survey response data
seanofahey Jan 2, 2017
fb59e98
added more functions for survey response data frame and decoding
seanofahey Jan 2, 2017
7823595
tested end to end -- working
seanofahey Jan 2, 2017
4b71aa8
updated version number
seanofahey Jan 2, 2017
2eade47
updated the make variable names more consistent
seanofahey Jan 2, 2017
98ba143
reformatted code and added edits to roxygen comments
seanofahey Jan 2, 2017
e976d0f
added roxygen comments and also reformatted code
seanofahey Jan 2, 2017
4f78e99
added roxygen comments
seanofahey Jan 2, 2017
58f6115
updated with new roxygen comments
seanofahey Jan 2, 2017
f6815a0
updated news
seanofahey Jan 3, 2017
eb3faff
added roxygen @export tag
seanofahey Jan 3, 2017
2672bcd
updated Roxygen documentation for functions and ran roxygenize to ref…
seanofahey Jan 5, 2017
d5d4258
added Roxygen documentation
seanofahey Jan 5, 2017
736b2d9
added Roxygen documentation
seanofahey Jan 5, 2017
dbe41ff
Merge branch 'master' of https://github.com/seanofahey/Rmonkey
seanofahey Jan 5, 2017
12fc34c
updated Roxygen code for as.data.frame.surveyresponses
seanofahey Jan 5, 2017
8494c73
updated to comment out libraries that should install automatically wi…
seanofahey Jan 5, 2017
dce0e0b
updated to comment out libraries that should install automatically wi…
seanofahey Jan 5, 2017
77ffced
added missing field name
seanofahey Jan 6, 2017
59781bb
added capability to recurisvely query to get all responses
seanofahey Jan 7, 2017
331bece
added tidyr
seanofahey Jan 8, 2017
a5d0e93
added code to capture and include text to essay questions. Still nee…
seanofahey Jan 8, 2017
94f2946
renamed function
seanofahey Jan 8, 2017
7179586
renamed function
seanofahey Jan 8, 2017
9a8b3a8
Merge branch 'master' of https://github.com/seanofahey/Rmonkey
seanofahey Jan 8, 2017
1e5d1e7
renamed surveyquestiondf to surveyquestions and updated docs
seanofahey Jan 9, 2017
d18491b
renamed surveyquestiondf to surveyquestions and updated docs
seanofahey Jan 9, 2017
129ed61
added all_pages option for downloads
seanofahey Jan 9, 2017
b526ad0
updated to account for "other" text responses
seanofahey Jan 9, 2017
aa27b82
updated to manage "other" text without warnings
seanofahey Jan 9, 2017
7e02272
added parameter to select response format
seanofahey Jan 9, 2017
19daf82
added parameter to select response format
seanofahey Jan 9, 2017
588c591
changed code to set default parameters. Increated per-page to 100 in …
seanofahey Jan 9, 2017
0ed90f6
moved table spread command into else statement
seanofahey Jan 16, 2017
85d1c88
made call to tidyr explicit
seanofahey Mar 6, 2017
b3a4422
updated README
seanofahey Mar 31, 2017
f64ad0e
small changes to README
seanofahey Mar 31, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,054 changes: 1,054 additions & 0 deletions .Rapp.history

Large diffs are not rendered by default.

21 changes: 17 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
Package: Rmonkey
Version: 0.3.3
Date: 2016-03-20
Version: 0.5
Date: 2016-12-28
Title: A Survey Monkey R Client
Authors@R: c(person("Thomas J.", "Leeper", role = c("aut", "cre"),
email = "thosjleeper@gmail.com"),
person("Sean", "Fahey", role = "ctb",
email = "seanmfahey@yahoo.com"),
person("Kevin", "Little", role = "ctb",
email = "klittle@iecodesign.com"),
person("David", "Robinson", role = "ctb",
email = "drobinson@stackoverflow.com"),
person("Stephan", "Renatus", role = "ctb"))
Maintainer: Thomas J. Leeper <thosjleeper@gmail.com>
Imports: stats, utils, httr, jsonlite, curl, plyr
Description: Programmatic access to the Survey Monkey API <https://developer.surveymonkey.com/>, which currently provides extensive functionality for monitoring surveys and retrieving survey results and some functionality for creating new surveys and data collectors.
Imports:
stats,
utils,
httr,
jsonlite,
curl,
plyr
Description: Programmatic access to the Survey Monkey API <https://
developer.surveymonkey.com/>, which currently provides extensive functionality
for monitoring surveys and retrieving survey results and some functionality for
creating new surveys and data collectors.
License: GPL-2
URL: https://github.com/cloudyr/Rmonkey
BugReports: https://github.com/cloudyr/Rmonkey/issues
RoxygenNote: 5.0.1

40 changes: 11 additions & 29 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
export('smlogin')
export('userdetails')
export('surveylist')
export('surveydetails')
export('surveyquestions')
export('surveypreview')
export('collectors')
export('createcollector')
export('responsecounts')
export('respondentlist')
export('getresponses')
export('getallresponses')
export('templates')
export('createsurvey')
# Generated by roxygen2: do not edit by hand

S3method(print, 'sm_survey')
S3method(print, 'sm_collector')
S3method(print, 'sm_respondent')
S3method(print, 'sm_response')
S3method(print, 'sm_template')

S3method(as.data.frame, 'sm_response')
S3method(as.data.frame, 'sm_response_list')

importFrom('stats', 'setNames')
importFrom('utils', 'head', 'browseURL')
importFrom('plyr', 'rbind.fill')
importFrom('curl', 'curl_escape')
import('httr')
import('jsonlite')
export(getresponses)
export(print.sm_response)
export(print.sm_survey)
export(smlogin)
export(surveydetails)
export(surveylist)
export(surveypreview)
export(surveyquestions)
export(surveyresponses)
export(userdetails)
11 changes: 11 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# CHANGES TO Rmonkey 0.5 #

## SIGNIFICANT USER-VISIBLE CHANGES ##
* Rebuilt several functions to work with SurkeyMonkey API V3 (smlogin, userdetails, surveylist, surveydetails)
*

## BUG FIXES ##

## DOCUMENTATION ##
* added Roxygen comments to new functions

# CHANGES TO Rmonkey 0.4 #

## SIGNIFICANT USER-VISIBLE CHANGES ##
Expand Down
88 changes: 53 additions & 35 deletions R/asdataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,65 +12,83 @@ as.data.frame.sm_response <- function(x, row.names, optional, details = NULL, st
} else {
stop("'details' is missing and cannot be determined automatically")
}

survey<-x
# These first functions unpack the surveydetails() with questions
details <- surveydetails(survey, question_details = TRUE)


# extract all questions from the `question` element in all pages
# note: this assumes that all data records are identical and so the first can be used as a model
questions <- do.call('c', lapply(details$pages, function(i) i[['questions']]))

# `type` contains info about each question type
qtypes <- sapply(questions, function(i) {
fam <- i$type$family
fam <- i$family
if (fam == "matrix") {
setNames(paste0(fam, "_", i$type$subtype), i$question_id)
setNames(paste0(fam, "_", i$subtype), i$id)
} else {
setNames(fam, i$question_id)
setNames(fam, i$id)
}
})

# set variable names
varnames <- sapply(questions, function(i) {
# `heading` is the display text
setNames(i$heading, i$question_id)
setNames(i$heading, i$id)
})

# alternate method which reuses an existing function and cleans HTML tags
varnames2 <- surveyquestions(survey)

# extract all answers from the `answers` elements of each subelement of `question`
# `answer_id` is what is recorded in `sm_response`
# `text` is the display seen by respondents
# `answers` is empty for "open_ended" type questions
answerchoices <- sapply(questions, function(i) {
out <- list()
for (k in seq_along(i$answers)) {
if (i$type$family == "matrix") {
if (i$type$subtype == "rating") {
if (i$answers[[k]]$type == "other") {
out[[k]] <- setNames(i$answers[[k]]$text, i$answers[[k]]$answer_id)
} else {
# exclude "col" values from matrix questions
if (i$answers[[k]]$type == "row") {
out[[k]] <- setNames(i$answers[[k]]$text, i$answers[[k]]$answer_id)
}
}
out[[k]] <- setNames(i$answers[[k]]$text, i$answers[[k]]$answer_id)
} else if (i$type$subtype == "menu") {
if (i$answers[[k]]$type == "col") {
tmp_txt <- unlist(lapply(i$answers[[k]]$items, `[`, "text"))
tmp_ans <- unlist(lapply(i$answers[[k]]$items, `[`, "answer_id"))
out[[k]] <- setNames(tmp_txt, tmp_ans)
rm(tmp_txt)
rm(tmp_ans)
}
}
} else {
out[[k]] <- setNames(i$answers[[k]]$text, i$answers[[k]]$answer_id)
}
for (k in seq_along(i$answers$choices)) {
# if (i$family == "matrix") {
# if (i$subtype == "rating") {
# if (i$answers[[k]]$type == "other") {
# out[[k]] <- setNames(i$answers[[k]]$text, i$answers[[k]]$id)
# } else {
# # exclude "col" values from matrix questions
# if (i$answers[[k]]$type == "row") {
# out[[k]] <- setNames(i$answers[[k]]$text, i$answers[[k]]$id)
# }
# }
# out[[k]] <- setNames(i$answers[[k]]$text, i$answers[[k]]$id)
# } else if (i$type$subtype == "menu") {
# if (i$answers[[k]]$type == "col") {
# tmp_txt <- unlist(lapply(i$answers[[k]]$items, `[`, "text"))
# tmp_ans <- unlist(lapply(i$answers[[k]]$items, `[`, "id"))
# out[[k]] <- setNames(tmp_txt, tmp_ans)
# rm(tmp_txt)
# rm(tmp_ans)
# }
# }
# } else {
out[[k]] <- setNames(i$answers$choices[[k]]$text, i$answers$choices[[k]]$id)
# }
}
return(unlist(out))
})
answerchoices <- unlist(do.call(c, answerchoices))

# extract question_ids
question_ids <- unlist(sapply(x$questions, `[`, 'question_id'))
# count number of answers per question
nanswers <- integer()
for (i in seq_along(x$questions)) {
nanswers[i] <- length(x$questions[[i]]$answers)
}
rm(i)
question_ids <- unlist(sapply(questions, `[`, 'id'))

# # count number of answers per question
# nanswers <- integer()
# for (i in seq_along(x$questions)) {
# nanswers[i] <- length(x$questions[[i]]$answers)
# }
# rm(i)

# count the number of answer choices per question
nanswers <- sapply(questions, function(x) {length(x$answers$choices)})

# create vector of answer names by repeating question names `nanswers` times each
answer_names <- rep(question_ids, nanswers)

Expand Down
Loading