# NOT RUN {
## BulkCreate ##
# load a vector of HTML files from the working directory
qvec <- sapply(list.files(pattern = ".html"), function(x) {
paste0(readLines(x, warn = FALSE), collapse = "\n")
})
# create a HIT from each question file
hits1 <- BulkCreate(questions = qvec,
annotation = paste("Bulk Create", Sys.Date()),
title = "Categorize an image",
description = "Categorize this image",
reward = ".05",
expiration = seconds(days = 4),
duration = seconds(minutes = 5),
keywords = "categorization, image, moderation, category")
# cleanup
ExpireHIT(annotation = paste("Bulk Create", Sys.Date()))
DisposeHIT(annotation = paste("Bulk Create", Sys.Date()))
# }
# NOT RUN {
# }
# NOT RUN {
## BulkCreateFromURLs ##
# create three HITs from the template
hits2 <-
BulkCreateFromURLs(url = paste0("https://www.example.com/",1:3,".html"),
frame.height = 400,
annotation = paste("Bulk From URLs", Sys.Date()),
title = "Categorize an image",
description = "Categorize this image",
reward = ".05",
expiration = seconds(days = 4),
duration = seconds(minutes = 5),
keywords = "categorization, image, moderation, category")
# cleanup
ExpireHIT(annotation = paste("Bulk From URLs", Sys.Date()))
DisposeHIT(annotation = paste("Bulk From URLs", Sys.Date()))
# }
# NOT RUN {
# }
# NOT RUN {
## BulkCreateFromTemplate ##
# load template HTML file
# should have placeholders of the form `${varName}` for variable values
temp <- system.file("templates/htmlquestion2.xml", package = "MTurkR")
# 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 three HITs from the template
hits3 <-
BulkCreateFromTemplate(template = temp,
input = a,
annotation = paste("Bulk From Template", Sys.Date()),
title = "Categorize an image",
description = "Categorize this image",
reward = ".05",
expiration = seconds(days = 4),
duration = seconds(minutes = 5),
keywords = "categorization, image, moderation, category")
# cleanup
ExpireHIT(annotation = paste("Bulk From Template", Sys.Date()))
DisposeHIT(annotation = paste("Bulk From Template", Sys.Date()))
# }
# NOT RUN {
# }
# NOT RUN {
## BulkCreateFromHITLayout ##
# retrieve HITLayoutID from Requester User Interface
layoutid <- "23ZGOOGQSCM61T1H5H9U0U00OQWFFU"
# create/load data.frame of HITLayout variable values
b <- 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 three HITs from the template
hits4 <-
BulkCreateFromHITLayout(hitlayoutid = layoutid,
input = b,
annotation = paste("Bulk From Layout", Sys.Date()),
title = "Categorize an image",
description = "Categorize this image",
reward = ".05",
expiration = seconds(days = 4),
duration = seconds(minutes = 5),
keywords = "categorization, image, moderation, category")
# cleanup
ExpireHIT(annotation = paste("Bulk From Layout", Sys.Date()))
DisposeHIT(annotation = paste("Bulk From Layout", Sys.Date()))
# }
Run the code above in your browser using DataLab