From 090aad58e3924c30f74e8c16143bd14ac0d08ccb Mon Sep 17 00:00:00 2001 From: "Thomas J. Leeper" Date: Sun, 22 Jan 2017 16:32:17 +0000 Subject: [PATCH] fix tests for 0.8.0 release --- DESCRIPTION | 4 +- NEWS => NEWS.md | 96 +++++++++++++++++++++--------------------- R/GetStatistic.R | 11 +++-- R/ListStatistics.R | 5 --- R/RequesterReport.R | 26 +++++++----- README.md | 8 ++-- man/GetStatistic.Rd | 2 +- tests/testthat/tests.R | 6 +-- 8 files changed, 79 insertions(+), 79 deletions(-) rename NEWS => NEWS.md (92%) diff --git a/DESCRIPTION b/DESCRIPTION index 56a5699..f4d8f4a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: MTurkR -Version: 0.7.11 -Date: 2016-07-26 +Version: 0.8.0 +Date: 2017-01-22 Title: R Client for the MTurk Requester API Authors@R: c(person("Thomas J.", "Leeper", role = c("aut", "cre"), email = "thosjleeper@gmail.com"), diff --git a/NEWS b/NEWS.md similarity index 92% rename from NEWS rename to NEWS.md index 422fbf1..de98e52 100644 --- a/NEWS +++ b/NEWS.md @@ -1,25 +1,27 @@ -# CHANGES TO MTurkR 0.8 # +# CHANGES TO MTurkR 0.8 -## SIGNIFICANT USER-VISIBLE CHANGES ## +## SIGNIFICANT USER-VISIBLE CHANGES * `GetAssignments()` now attempts to convert non-character variables to an appropriate R vector type via `type.convert(, as.is = TRUE)`. +* Some statistics have been deprecated for the `GetStatistic()` and `RequesterReport()`, including "NumberAssignmentsAvailable", "NumberAssignmentsAccepted", "NumberAssignmentsReturned", "TotalFeePayout", and "TotalRewardAndFeePayout". This is reflected in the return value of `ListStatistics()`. -## DOCUMENTATION ## +## DOCUMENTATION * Added two papers (one from *The Political Methodologist* and one from *The R Journal*) as supplemental PDF documentation, accessible via `? MTurkR`. (#93) * Documentation now indicates that `GrantBonus()` allows the `reason` argument to contain newlines and tabs. (#109) -## BUG FIXES ## +## BUG FIXES +* Question identifiers used in a Qualification AnswerKey are only checked if `CreateQualificationType()` is called with `validate.answerkey = TRUE`. (#117, h/t Darrell Penta) * Fixed a bug in `BulkCreateFromHITLayout()` that caused the function to fail. (#114, h/t Tyler Scott) * Fixed a bug in trying to parse already parsed response for `GetBonuses()`. (#113, h/t Andrew Brown) * The simple wizard now correctly respects AWS credentials specified as environment variables instead of the deprecated `credentials()` function. (h/t Kim Gross) -* Functions should now all return data.frames with character class columns (unless otherwise noted) with sequentially numbered rownames. This corrects potentially some confusing behavior introduced during XML parsing. (#112) +* Functions should now all return data frames with character class columns (unless otherwise noted) with sequentially numbered rownames. This corrects potentially some confusing behavior introduced during XML parsing. (#112) -# CHANGES TO MTurkR 0.7 # +# CHANGES TO MTurkR 0.7 -## SIGNIFICANT USER-VISIBLE CHANGES ## +## SIGNIFICANT USER-VISIBLE CHANGES * `GenerateExternalQuestion` now sets a default value of `frame.height = 400`. * The AWS Access Key ID used for requests is now redacted from the error message printing when an API request fails to reduce the risk of accidentally disclosing the credential. (#105) @@ -37,7 +39,7 @@ * `SufficientFunds()` reflects the new commission structure effective July 21, 2015. (#87) * `BulkCreateFromTemplate` and `BulkCreateFromURLs` now have a `frame.height` argument with a default of 450. -## DOCUMENTATION ## +## DOCUMENTATION * A small test suite has been added to help ensure correct package functionality. It is only executed in the sandbox in the presence of valid AWS credentials. (#100) * The package now includes pages describing common use cases for MTurk (surveys, categorization, sentiment analysis, and webscraping). (#98) @@ -45,7 +47,7 @@ * The package now includes additional HTMLQuestion templates including examples for image categorization and sentiment rating. (#94) * Documentation for `GenerateHITReviewPolicy` and `GenerateAssignmentReviewPolicy` was expanded and tested, and a related HTMLQuestion HIT template is now installed. -## BUG FIXES ## +## BUG FIXES * Fixed a bug in checking for a valid AWS keypair in `request()`. (h/t Sean Murphy, #106) * When ttk widgets were added to the graphical wizard in v0.6, scrollbar calls retained tk-only options. Those have been removed. (h/t Justin Koch) @@ -53,9 +55,9 @@ * Closing the graphical wizard crashed RStudio due to `bringToTop(-1)`. This is fixed. (h/t Carolina Kuepper-Tetzel) -# CHANGES TO MTurkR 0.6.5 # +# CHANGES TO MTurkR 0.6.5 -## SIGNIFICANT USER-VISIBILE CHANGES ## +## SIGNIFICANT USER-VISIBILE CHANGES * Added `BulkCreate`, `BulkCreateFromTemplate`, `BulkCreateFromURLs`, and `BulkCreateFromHITLayout` functions that can be used to create multiple HITs of the same HITType with identical properties but different question content. The `hitsfromtemplate` function has been removed. (#76) * The graphical wizard now supports creating HIT- and Assignment-level ReviewPolicies during HIT creation. (#55) @@ -64,7 +66,7 @@ * `GrantBonus` now accepts a `unique.request.token` argument. (#75) * The unused `format` argument to `GenerateNotification` has been removed. (#71) -## DOCUMENTATION ## +## DOCUMENTATION * Examples have been added to demonstrate functionality of `AnswerKeyTemplate`. * Documentation for `GrantQualification` and `RejectQualification` has been merged to clarify the use of these functions. Documentation has been expanded with complete examples of both functions. (#72) @@ -72,18 +74,18 @@ * `GenerateHITsFromTemplate` now has a more complete example that includes an installed template HTML file. (#72) * Several small changes have been made to correct documentation and fix bad formatting in the PDF version of the manual. (#72) -## BUG FIXES ## +## BUG FIXES * Fixed a bug in the CreateQualification dialog of the graphical wizard related to destroying the dialog. (h/t Sean Murphy) * Fixed a bug in the AssignQualification dialog of the graphical wizard. (h/t Carolina Kuepper-Tetzel) * Loading MTurkR no longer overwrites existing MRurkR `options`. (#83) -* `GetStatistic` now consistently returns a three-column data frame containing the name of the requested statistic, its value, and the date of the statistic. If the request fails, this data.frame has zero rows. Printing of request information (if `verbose = TRUE`) has further been fixed to prevent incorrect printing when `count` was specified. (#78) +* `GetStatistic` now consistently returns a three-column data frame containing the name of the requested statistic, its value, and the date of the statistic. If the request fails, this data frame has zero rows. Printing of request information (if `verbose = TRUE`) has further been fixed to prevent incorrect printing when `count` was specified. (#78) * Fixed a bug in `ExtendHIT` wherein specifying both `add.assignments` and `add.seconds` caused only assignments to be incremented. (#79) -# CHANGES TO MTurkR 0.6 # +# CHANGES TO MTurkR 0.6 -## SIGNIFICANT USER-VISIBLE CHANGES ## +## SIGNIFICANT USER-VISIBLE CHANGES * `GetReviewResults` should now be able to return all results. This is untested due to the large page size of ReviewResults (65,535). (#54) * The graphical wizard now uses "themed" tk (ttk) widgets where possible, in order to improve the appearance. This creates a dependency on tcl >= 8.5. @@ -94,13 +96,13 @@ * `mturkr.wizard` now allows users to enter multiple WorkerIds for several functions by simply pasting one WorkerId per line into a multi-line textbox. (#52, h/t Justin Weigand) * `GetReviewResultsForHIT` now has `pagenumber` and `pagesize` arguments to control pagination of results. (#54) -## DOCUMENTATION ## +## DOCUMENTATION * Documentation for `CreateHIT` and `CreateQualificationType` now include examples using template files installed with the package. (#40) * Documentation of generating a Masters QualificationRequirement has been slightly clarified. * Examples of Amazon Simple Queue Service (SQS) notifications have been added, along with a detailed tutorial on the MTurk wiki. (#60) -## BUG FIXES ## +## BUG FIXES * Fixed a bug in the wizard that prevented the user from clearing and viewing QualificationRequirements that had been added to a HITType. * Numerous related bug fixes in the wizard related to populating HITId, HITTypeId, and QualificationTypeId fields were fixed. (#69) @@ -108,36 +110,36 @@ * Wizard dialogs for adding question data structures to a HIT did not close on accepting "OK". (#65) * `GetAssignments` only returned the first answer option when multiple selection answers were chosen by a worker. (#63, h/t Kyle Harms) * Fixed a possible bug in `ContactWorkers` batch mode that sent multiple emails to the same worker(s). (#58, h/t Andy Guess) -* Fixed a few XML-related bugs in `as.data.frame.QuestionForm` and `as.data.frame.AnswerKey`. +* Fixed a few XML-related bugs in `as.data frame.QuestionForm` and `as.data frame.AnswerKey`. -# CHANGES TO MTurkR 0.5.5 # +# CHANGES TO MTurkR 0.5.5 -## SIGNIFICANT USER-VISIBLE CHANGES ## +## SIGNIFICANT USER-VISIBLE CHANGES * `GenerateReviewPolicy` is removed in lieu of two new functions: `GenerateHITReviewPolicy` and `GenerateAssignmentReviewPolicy`, both of which have a simplified function API and include extensive examples in the documentation. The previous code never worked correctly, so this change should be unimportant. The use of `CreateHIT` remains unchanged. (#47) * `HITStatus`, `ApproveAllAssignments`, `ChangeHITType`, `DisposeHIT`, `DisableHIT`, `ExpireHIT`, `ExtendHIT`, `GetAssignment`, `GetBonuses`, `SetHITAsReviewing` now include an optional `annotation` argument that can be used to apply the function to all HITs of a given "batch" created in the online Requester User Interface. (#51) * `GetFileUpload` no longer has a `file.ext` argument. Instead the file extension is taken from the uploaded file itself. The format of the filename for the downloaded file has also been clarified. (#45) -## DOCUMENTATION ## +## DOCUMENTATION * Examples for all functions have been substantially expanded and checked for accuracy. * The MTurkR wiki (https://github.com/leeper/MTurkR/wiki) includes numerous updated code examples, including full documentation for both `wizard.simple` and `mturkr.wizard`, the MTurkR interactive interfaces. -## BUG FIXES ## +## BUG FIXES * Fixed a bug in `SearchHITs` that was not passing `...` arguments ot `GetQualificationType` * Fixed a small bug in the batch (pagination) of `SearchQualificationTypes`. -* Functions for QualificationTypes now return a data.frame containing character variables rather than factor variables, as this could cause unintended coercion when using `GenerateQualifiationType`. (h/t Haotian Zhou) +* Functions for QualificationTypes now return a data frame containing character variables rather than factor variables, as this could cause unintended coercion when using `GenerateQualifiationType`. (h/t Haotian Zhou) * Corrected several related bugs (API version number, LocaleValue specification) that prevented the "In" comparator in a QualificationRequirement from working with multiple LocaleValues in API version 2013-11-15. (#50, h/t Haotian Zhou) -# CHANGES TO MTurkR 0.5 # +# CHANGES TO MTurkR 0.5 -## SIGNIFICANT USER-VISIBLE CHANGES ## +## SIGNIFICANT USER-VISIBLE CHANGES * `GenerateQualificationRequirement` now supports new comparators (given MTurk API update on 2014-07-17): "DoesNotExist", "In", and "NotIn". The "DoesNotExist" comparator allows requesters to effectively block workers who do not have, e.g., a requester-defined qualification. The "In" and "NotIn" comparators allow a boolean OR logical in QualificationRequirements (e.g., allowing a worker to be from the US or the UK) rather than having to create two separate HITs with different Locale restrictions. * The `qual.number` argument to `GenerateQualificationRequirement` has been removed. * The `return.hit.dataframe` argument to `GetHITsForQualificationType` has been removed. -* Functions of the form `*ToDataFrame` have been replaced with `as.data.frame` S3 methods, which are handled by a global `as.data.frame.MTurkResponse` function. (#36) +* Functions of the form `*ToDataFrame` have been replaced with `as.data frame` S3 methods, which are handled by a global `as.data frame.MTurkResponse` function. (#36) * `ParseErrorCodes` is removed (now used internally in `request`). * `options('MTurkR.print')` is deleted and replaced by `options('MTurkR.verbose')`. All functions will, temporarily, accept `print` arguments. All code should be updated to reflect the new terminology moving forward. * When `validation.test=TRUE` or `browser=TRUE`, functions now return an object of class "MTurkResponse" for the purpose of debugging. @@ -149,24 +151,24 @@ * In many functions that return a data frame with a `Valid` column (e.g., `ContactWorkers`, etc.), `Valid` is now a factor. (#28) * Using `ContactWorkers` in batch mode now returns a data frame identical in structure to using it in regular mode, with one row per worker. (#32) * The `signature` argument to `request` now defaults to `NULL` and is generated automatically. -* `HITsToDataFrame` (now `as.data.frame.HITs`) now returns, for the QualificationRequirements list element, an empty data frame rather a single `NA` missing value if a given HIT does not have any QualificationRequirements attached to it. +* `HITsToDataFrame` (now `as.data frame.HITs`) now returns, for the QualificationRequirements list element, an empty data frame rather a single `NA` missing value if a given HIT does not have any QualificationRequirements attached to it. * `request` now generates the API authentication signature automatically, eliminating the need for `authenticate`, which is deprecated. `request` no longer accepts `signature` or `timestamp` arguments and has a new argument order. Arguments can be passed to `request` via a new `...` argument in all functions. * `request` now uses `curlPerform` instead of `getURL` to gain finer control over API requests. * `request` now attempts to `tryCatch` any errors on writing the MTurkR log file. (#9) * `request` now returns an object of S3 class "MTurkResponse" and an associated print method has been added. -## BUG FIXES ## +## BUG FIXES * `GenerateQualificationRequirement` now correctly handles the "Exists" comparator by requiring an empty character string for the corresponding `value` argument. * `HITStatus` now prints correctly when only one HIT is retrieved. * `ApproveAllAssignments` now only attempts to approved assignments with AssignmentStatus "Submitted". -* `as.data.frame.QuestionForm` now returns "Overview" elements and "Question" elements as one data.frame, distinguished by a new column: `Element`. (#8) +* `as.data frame.QuestionForm` now returns "Overview" elements and "Question" elements as one data frame, distinguished by a new column: `Element`. (#8) * `GetQualifications` and `GetQualificationRequests` now respect the `return.all` argument. * The `return.qual.dataframe` argument in `GetQualificationType` and `GetQualifications` is removed. * Fixed a bug in `GetBonuses` whereby the default `return.all=TRUE` argument overwrote manually specified `pagenumber` and `pagesize` arguments. When `GetBonuses` is called with a `hit.type`, `return.all` is used recursively, such that `return.all=FALSE` returns the requested page for each HIT of the requested HITType. (h/t Dane Wendell, #37) * Corrected the API operation name in `SendTestEventNotification`. * Fixed a bug in `GetBonuses` using a HITTypeId that caused the function to fail catastrophically. -## DOCUMENTATION ## +## DOCUMENTATION * The `return.qual.dataframe` argument in `GetQualificationType` and `GetQualifications` is removed. * All functions now reflect the new `...` argument, the contents of which are passed to `request`. (#38) * All references to the `browser` options are removed given removal of the feature from all functions. @@ -177,9 +179,9 @@ * The `add.seconds` parameter was incorrectly called `add.time` in the `ExtendHIT` documentation. -# CHANGES TO MTurkR 0.4 # +# CHANGES TO MTurkR 0.4 -## SIGNIFICANT USER-VISIBLE CHANGES ## +## SIGNIFICANT USER-VISIBLE CHANGES * Functions that accept a `hit.type` argument can now generally accept a vector of HITTypeIds rather than just a single character string. See documentation. * `GetBonuses` now allows requests to be opened in the default browser, like most other API functions. * From version 0.3.7, global options (`MTurkR.log`,`MTurkR.test`,`MTurkR.browser`,and `MTurkR.print`) have been added to all functions. Defaults for these remain the same in all places. @@ -190,8 +192,8 @@ * Most API query functions now include a `validation.test` parameter that, when TRUE, runs pre-query checks on the MTurkR call and returns the full API query URL. The call is not executed. This can be used for pre- or post-request debugging. * The 'MTurkRlog.tsv' file is now located according to a global option, specified by `options(MTurkR.logdir = getwd())`. The previous default behavior (to store the file in the working directory) is preserved but can now be globally modified for all requests. This might be useful for storing all requests (from all MTurk projects) in a single directory. -## BUG FIXES ## -* `ContactWorkers` now supplies additional information when attempting to contact ineligible workers (i.e., those who have not worked for the requester previously). These workers are indicated by a value of `HardFailure` in the `Valid` column of the response data.frame. (#29) +## BUG FIXES +* `ContactWorkers` now supplies additional information when attempting to contact ineligible workers (i.e., those who have not worked for the requester previously). These workers are indicated by a value of `HardFailure` in the `Valid` column of the response data frame. (#29) * All functions now explicitly convert factor arguments (e.g., for `worker`, `qual`, `hit`, etc.) to character in order to prevent some unintended side effects. (#26) * New versions of libcurl (>7.28) deprecate boolean values for SSL_VERIFYPEER and SSL_VERIFYHOST options. `request` was returning errors due to this and has been updated. Everything is backwards compatible to earlier versions of libcurl. (#31, h/t James Ben Taylor) * `GenerateHITLayoutParameter` now replaces any non-XML ampersands with `&`, which had previously caused failures when creating HITs. (#30, h/t Eric Lin) @@ -208,25 +210,25 @@ * Added filters to `request` to handle a variety of problematic characters (that might emerge from FreeText responses in assignments). (h/t and contributions from Solomon Messing) * removed references to `shell.exec` and replaced with `browseURL`. -## DOCUMENTATION ## +## DOCUMENTATION * Where appropriate, functions using `hit.type` parameters are now described (correctly) as allowing vectors of HITTypeIds rather than just a single HITTypeId. See documentation. * Documentation for `ContactWorkers` now describes in greater detail what happens when attempting to contact ineligible workers. (#29) -# CHANGES TO MTurkR 0.3.5 # +# CHANGES TO MTurkR 0.3.5 -## SIGNIFICANT USER-VISIBLE CHANGES ## +## SIGNIFICANT USER-VISIBLE CHANGES * `CreateHIT` now provides an option to validate the 'question' parameter for HTMLQuestion, ExternalQuestion, and QuestionForm HIT structures. * `CreateQualificationType` now provides options to validate the 'test' and/or 'answerkey' parameters for QuestionForm and AnswerKey structures, respectively. * `GenerateAnswerKey` was modified to accept slightly different inputs for the 'questions' parameter. A new function, `AnswerKeyTemplate`, produces a user-modifiable template (as a list) for that parameter based on a QuestionForm data structure for which an AnswerKey is desired. * When internal functions (described in the documentation of `XMLToDataFrame`) that normally return named lists have nothing to translate to a data frame, they now return named lists with NULL values rather than simply a single NULL. -## BUG FIXES ## +## BUG FIXES * Fixed bug in `GetAssignments` that prevented the return of assignments for an entire HITType or for multiple HITs. Specifically, previous version was retrieving assignments via the API but not returning them to the user. (h/t Robert Vesco) -# CHANGES TO MTurkR 0.3 # +# CHANGES TO MTurkR 0.3 -## SIGNIFICANT USER-VISIBLE CHANGES ## +## SIGNIFICANT USER-VISIBLE CHANGES * To improve speed and reduce the number of API calls, `HITsToDataFrame`, which is called by `SearchHITs`, `GetHIT`, etc., now uses the convenience function `ListQualificationTypes` to return the name of QualificationRequirements when applicable. * Expanded the functionality of `ContactWorkers` to allow a 'batch' mode, wherein workers are contacted with generic (i.e., not customized) email messages and subject lines in batches of 100. * Text sent to console when `print=TRUE` modified slightly, so that iteration numbers are printed for each iteration (to monitor progress of mutli-item requests). @@ -235,7 +237,7 @@ * Updates were made to `GenerateAnswerKey` (see documentation) and a new function `AnswerKeyToDataFrame` was released. * `QuestionFormToDataFrame` created. See documentation for details. -## BUG FIXES ## +## BUG FIXES * MTurk API operation 'ChangeHITTypeofHIT' typo was fixed to 'ChangeHITTypeOfHIT'. * A small change was made to `BlockWorkers` to allow a single reason to be used for multiple workers, as originally intended. * Fixed bug in `GetAssignments` to allow retrieval of assignments by status, as originally intended. @@ -243,27 +245,27 @@ * Bug fixes to `CreateQualificationType` related to parsing of XML in 'test' and 'answerkey' parameters. * Modified `credentials` to pass CRAN checks. -## DOCUMENTATION ## +## DOCUMENTATION * Documentation for `CreateQualificationType` notes web browser-dependent constraints on URL length that may produce unintended behavior when 'browser=TRUE' and a 'test' parameter is specified. * Added documentation for `AnswerKeyToDataFrame`. * Various copyedits. -# CHANGES TO MTurkR 0.2 # +# CHANGES TO MTurkR 0.2 -## SIGNIFICANT USER-VISIBLE CHANGES ## +## SIGNIFICANT USER-VISIBLE CHANGES * A completely new GUI interface for managing MTurkR, which now suggests library(tcltk), has been added. The previous, text-based wizard remains available by calling `mturkr.wizard("simple")`. * Support for ReviewPolicies has been added, both creating them using `GenerateReviewPolicy` and retrieving their results using `GetReviewResultsForHIT`. * Support for AnswerKey data structures has been added, for use in `CreateQualificationType`. * Added simple checks for 'sortproperty', 'sortdirection', 'pagesize', and 'pagenumber' parameters in relevant functions. * Expanded support for QuestionForm data structures is currently under development and should be available in the next release. -## BUG FIXES ## +## BUG FIXES * A number of bug fixes have been corrected throughout the package. Most were minor and related to output, but some like the 'return.all' parameter in `GetAssignments`, were producing unintended behavior. * Various mislabeled function parameters (used within functions) have been corrected (some were creating notes on R CMD check). * `request` was modified to remove problematic whitespace characters when writing log entries (which made reading the log file into R problematic). -## DOCUMENTATION ## +## DOCUMENTATION * Fixed a number of minor errors in documentation. * Expanded documentation for functions associated with AnswerKey and ReviewPolicy data structures. * Expanded documentation for 'sortproperty' and 'sortdirection' parameters in relevant functions. diff --git a/R/GetStatistic.R b/R/GetStatistic.R index 13e8405..88e3dff 100644 --- a/R/GetStatistic.R +++ b/R/GetStatistic.R @@ -3,15 +3,14 @@ statistic <- function (statistic, period = "LifeToDate", count = NULL, response.group = NULL, verbose = getOption('MTurkR.verbose', TRUE), ...) { operation <- "GetRequesterStatistic" - value.long <- c("NumberAssignmentsAvailable", "NumberAssignmentsAccepted", - "NumberAssignmentsPending", "NumberAssignmentsApproved", - "NumberAssignmentsRejected", "NumberAssignmentsReturned", - "NumberAssignmentsAbandoned", "NumberHITsCreated", "NumberHITsCompleted", + value.long <- c("NumberAssignmentsPending", "NumberAssignmentsApproved", + "NumberAssignmentsRejected", "NumberAssignmentsAbandoned", + "NumberHITsCreated", "NumberHITsCompleted", "NumberHITsAssignable", "NumberHITsReviewable") value.double <- c("PercentAssignmentsApproved", "PercentAssignmentsRejected", "TotalRewardPayout", "AverageRewardAmount", "TotalRewardFeePayout", - "TotalFeePayout", "TotalRewardAndFeePayout", "TotalBonusPayout", - "TotalBonusFeePayout", "EstimatedRewardLiability", "EstimatedFeeLiability", + "TotalBonusPayout", "TotalBonusFeePayout", + "EstimatedRewardLiability", "EstimatedFeeLiability", "EstimatedTotalLiability") if (!statistic %in% value.long & !statistic %in% value.double) { stop("Statistic not valid") diff --git a/R/ListStatistics.R b/R/ListStatistics.R index ac6ecc4..ac875ab 100644 --- a/R/ListStatistics.R +++ b/R/ListStatistics.R @@ -1,12 +1,9 @@ ListStatistics <- function (stat = NULL, value.type = NULL, type = NULL) { stats <- setNames(as.data.frame(rbind( - c("NumberAssignmentsAvailable", "Long", "GetRequesterStatistic"), - c("NumberAssignmentsAccepted", "Long", "GetRequesterStatistic"), c("NumberAssignmentsPending", "Long", "GetRequesterStatistic"), c("NumberAssignmentsApproved", "Long", "GetRequesterStatistic"), c("NumberAssignmentsRejected", "Long", "GetRequesterStatistic"), - c("NumberAssignmentsReturned", "Long", "GetRequesterStatistic"), c("NumberAssignmentsAbandoned", "Long", "GetRequesterStatistic"), c("NumberHITsCreated", "Long", "GetRequesterStatistic"), c("NumberHITsCompleted", "Long", "GetRequesterStatistic"), @@ -17,8 +14,6 @@ function (stat = NULL, value.type = NULL, type = NULL) { c("TotalRewardPayout", "Double", "GetRequesterStatistic"), c("AverageRewardAmount", "Double", "GetRequesterStatistic"), c("TotalRewardFeePayout", "Double", "GetRequesterStatistic"), - c("TotalFeePayout", "Double", "GetRequesterStatistic"), - c("TotalRewardAndFeePayout", "Double", "GetRequesterStatistic"), c("TotalBonusPayout", "Double", "GetRequesterStatistic"), c("TotalBonusFeePayout", "Double", "GetRequesterStatistic"), c("EstimatedRewardLiability", "Double", "GetRequesterStatistic"), diff --git a/R/RequesterReport.R b/R/RequesterReport.R index 4ad4f61..b04ce94 100644 --- a/R/RequesterReport.R +++ b/R/RequesterReport.R @@ -3,22 +3,26 @@ function (period = "LifeToDate", verbose = getOption('MTurkR.verbose', TRUE), .. if (!period %in% c("OneDay", "SevenDays", "ThirtyDays", "LifeToDate")) { stop("Period not valid") } - statistics <- c("NumberAssignmentsAvailable", "NumberAssignmentsAccepted", - "NumberAssignmentsPending", "NumberAssignmentsApproved", - "NumberAssignmentsRejected", "NumberAssignmentsReturned", + statistics <- c( + "NumberAssignmentsPending", "NumberAssignmentsApproved", "NumberAssignmentsRejected", "NumberAssignmentsAbandoned", "NumberHITsCreated", "NumberHITsCompleted", "NumberHITsAssignable", "NumberHITsReviewable", "PercentAssignmentsApproved", "PercentAssignmentsRejected", "TotalRewardPayout", "AverageRewardAmount", - "TotalRewardFeePayout", "TotalFeePayout", "TotalRewardAndFeePayout", - "TotalBonusPayout", "TotalBonusFeePayout", "EstimatedRewardLiability", + "TotalRewardFeePayout", "TotalBonusPayout", + "TotalBonusFeePayout", "EstimatedRewardLiability", "EstimatedFeeLiability", "EstimatedTotalLiability") z <- emptydf(length(statistics), 2, c("Statistic", "Value")) - z[, 1] <- statistics - for (i in 1:20) { - z[i, 2] <- GetStatistic(statistics[i], period = period, ...) + z[["Statistic"]] <- statistics + only_ltd <- c("NumberHITsAssignable", "EstimatedRewardLiability", "EstimatedFeeLiability", "EstimatedTotalLiability") + for (i in seq_along(statistics)) { + if (statistics[i] %in% only_ltd) { + if (statistics[i] == "NumberHITsAssignable" && period != "LifeToDate") { + message("'NumberHITsAssignable' is being retrieved for period 'LifeToDate'") + } + z[i, 2] <- GetStatistic(statistics[i], period = "LifeToDate", verbose = verbose, ...)[["Value"]] + } else { + z[i, 2] <- GetStatistic(statistics[i], period = period, verbose = verbose, ...)[["Value"]] + } } - for (i in 21:23) { - z[i, 2] <- GetStatistic(statistics[i], period = "LifeToDate", ...) - } return(z) } diff --git a/README.md b/README.md index d70ba60..7f4b1e4 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,10 @@ If you experience problems using MTurkR, you can: ## Installation ## -[![CRAN Version](http://www.r-pkg.org/badges/version/MTurkR)](http://cran.r-project.org/package=MTurkR) -![Downloads](http://cranlogs.r-pkg.org/badges/MTurkR) +[![CRAN Version](https://www.r-pkg.org/badges/version/MTurkR)](https://cran.r-project.org/package=MTurkR) +![Downloads](https://cranlogs.r-pkg.org/badges/MTurkR) [![Travis-CI Build Status](https://travis-ci.org/cloudyr/MTurkR.png?branch=master)](https://travis-ci.org/cloudyr/MTurkR) -[![codecov.io](http://codecov.io/github/cloudyr/MTurkR/coverage.svg?branch=master)](http://codecov.io/github/cloudyr/MTurkR?branch=master) +[![codecov.io](https://codecov.io/github/cloudyr/MTurkR/coverage.svg?branch=master)](https://codecov.io/github/cloudyr/MTurkR?branch=master) To install the latest version from CRAN, simply use: @@ -43,7 +43,7 @@ To install the latest development version of **MTurkR** from GitHub: install.packages("MTurkR", repos = c(getOption("repos"), "http://cloudyr.github.io/drat")) # latest (unstable) version from GitHub -if(!require("ghit")){ +if (!require("ghit")) { install.packages("ghit") } ghit::install_github("cloudyr/MTurkR") diff --git a/man/GetStatistic.Rd b/man/GetStatistic.Rd index cafa56f..0ce2a3f 100644 --- a/man/GetStatistic.Rd +++ b/man/GetStatistic.Rd @@ -47,7 +47,7 @@ Retrieve a specific requester or worker statistic. The list of available statist } \examples{ \dontrun{ -GetStatistic("NumberHITsSubmitted","OneDay") +GetStatistic("NumberHITsCompleted","OneDay") RequesterReport("ThirtyDays") GetWorkerStatistic("A1RO9UJNWXMU65","PercentHITsApproved","LifeToDate") WorkerReport("A1RO9UJNWXMU65","SevenDays") diff --git a/tests/testthat/tests.R b/tests/testthat/tests.R index a856068..aed0677 100644 --- a/tests/testthat/tests.R +++ b/tests/testthat/tests.R @@ -9,13 +9,13 @@ test_that("Account Balance Check", { Sys.sleep(1) test_that("RequesterReport", { - expect_true(is.data.frame(RequesterReport())) - expect_true(is.data.frame(WorkerReport("A1RO9UJNWXMU65", period = "OneDay", sandbox = TRUE))) + expect_true(is.data.frame(RequesterReport(sandbox = TRUE))) + expect_true(is.data.frame(RequesterReport(period = "OneDay", sandbox = TRUE))) }) Sys.sleep(1) -test_that("RequesterReport", { +test_that("WorkerReport", { expect_true(is.data.frame(WorkerReport("A1RO9UJNWXMU65", sandbox = TRUE))) expect_true(is.data.frame(WorkerReport("A1RO9UJNWXMU65", period = "OneDay", sandbox = TRUE))) })