GenerateHITsFromTemplate | R Documentation |
Generate individual HIT .html files from a local .html HIT template file, in the same fashion as the MTurk Requester User Interface (RUI).
GenerateHITsFromTemplate(
template,
input,
filenames = NULL,
write.files = FALSE
)
template |
A character string or filename for an .html HIT template |
input |
A data.frame containing one row for each HIT to be created and columns named identically to the placeholders in the HIT template file. Operation will fail if variable names do not correspond. |
filenames |
An optional list of filenames for the HITs to be created.
Must be equal to the number of rows in |
write.files |
A logical specifying whether HIT .html files should be created and stored in the working directory. Or, alternatively, whether HITs should be returned as character vectors in a list. |
GenerateHITsFromTemplate
generates individual HIT question content
from a HIT template (containing placeholders for input data of the form
\${variablename}
). The tool provides functionality analogous to the
MTurk RUI HIT template and can be performed on .html files generated
therein. The HITs are returned as a list of character strings. If
write.files = TRUE
, a side effect occurs in the form of one or more
.html files being written to the working directory, with filenames specified
by the filenames
option or, if filenames=NULL
of the form
“NewHIT1.html”, “NewHIT2.html”, etc.
A list containing a character string for each HIT generated from the template.
Thomas J. Leeper
API Reference: ExternalQuestion Data Structure
## Not run:
# create/edit template HTML file
# should have placeholders of the form `${varName}` for variable values
temp <- system.file("templates/htmlquestion2.xml", package = "pyMTurkR")
readLines(temp)
# create/load data.frame of template variable values
a <- data.frame(hittitle = c("HIT title 1","HIT title 2","HIT title 3"),
hitvariable = c("HIT text 1","HIT text 2","HIT text 3"),
stringsAsFactors=FALSE)
# create HITs from template and data.frame values
temps <- GenerateHITsFromTemplate(template = temp, input = a)
# create HITs from template
hittype1 <- RegisterHITType(title = "2 Question Survey",
description = "Complete a 2-question survey",
reward = ".20",
duration = seconds(hours=1),
keywords = "survey, questionnaire, politics")
hits <- lapply(temps, function(x) {
CreateHIT(hit.type = hittype1$HITTypeId,
expiration = seconds(days = 1),
assignments = 2,
question = GenerateHTMLQuestion(x)$string)
})
# cleanup
ExpireHIT(hit.type = hittype1$HITTypeId)
DisposeHIT(hit.type = hittype1$HITTypeId)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.