Verified Commit 9ffe4bab authored by Cody L Marquart's avatar Cody L Marquart
Browse files

Test and verify coded columns

closes #5
parent e8635fa8
Pipeline #49040 passed with stages
in 2 minutes and 45 seconds
......@@ -29,11 +29,12 @@ as.data.frame.CodeSet <- function(x, row.names = NULL, optional = FALSE, ...) {
if(is.null(len) && !is.null(args$len)) len = args$len;
if(is.null(args$codes)) codes = x$codes;
if(!is.null(len) && len > 0) {
data.frame(ID = 1:len, excerpt = excerpts[1:len], sapply(codes, function(x){
coded_cols <- sapply(codes, function(x){
df = data.frame( x$computerSet[1:len] )
colnames(df) = c( x[['name']] )
df
}))
})
names(coded_cols) <- as.character(lapply(codes, `[[`, "name"))
data.frame(ID = 1:len, excerpt = excerpts[1:len], coded_cols)
} else {
data.frame()
}
......
library(testthat)
context("Testing the autocode function")
data(RS.data)
rs_text = RS.data$text
test_that("test autocoding code set", {
code.data = create.code(name = "Data", expressions = c("number","data"), excerpts = rs_text)
code.people = create.code(name = "People", expressions = c("people","he", "she", "they"), excerpts = rs_text)
code.set = code.set("Demo RS CodeSet", "CodeSet made for the demo", codes = c(code.data, code.people))
allcoded = autocode(x = code.set, excerpts = rs_text, simplify = TRUE)
expect_equivalent(colnames(allcoded), c("ID", "excerpt", "Data", "People"))
expect_equal(nrow(allcoded), length(rs_text))
expect_true(all(allcoded$Data %in% c(0, 1)))
expect_true(all(allcoded$People %in% c(0, 1)))
})
test_that("test autocoding single code", {
code.data = create.code(name = "Data", expressions = c("number","data"), excerpts = rs_text)
allcoded = autocode(x = code.data, excerpts = rs_text, simplify = TRUE)
expect_equivalent(colnames(allcoded), c("ID", "excerpt", "Data"))
expect_equal(nrow(allcoded), length(rs_text))
expect_true(all(allcoded$Data %in% c(0, 1)))
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment