# NOT RUN {
##
## 1. Test good cases
##
votetst <- data.frame(
surName=c('Smith', 'Jones', 'Graves', 'Jsn', 'Jsn', 'Gay'),
givenName=c("Sam", "", "", "John", "John", ''),
votex=factor(c('Y', 'N', 'abstain', 'Y', 'Y', 'Y')),
State=factor(rep(c("CA", "", "SC", "NY"), c(1, 2, 1, 2))),
district=rep(c("13", "1", "2", "1"), c(1, 2, 2, 1)),
stringsAsFactors=FALSE )
x1 <- data.frame(
Office=factor(rep(c("House", "Senate"), e=8)),
state=rep(c("NY", "SC", "SD", "CA", "AK", "AR", "NY", "NJ"), 2),
District=rep(c("2", "2", "At Large", "13", "1", "9", "1", "3"), 2),
surname=rep(c('Jsn', 'Jsn', 'Smith', 'Smith', 'Jones',
'Graves', 'Rx', 'Agnew'), 2),
givenName=rep(c("John D.", "John J.",
"Samual", "Samual", "Mary", "Mary", "Susan", 'Spiro'), 2),
don=1:16, stringsAsFactors=FALSE)
x1. <- mergeVote(x1, votetst)
x2 <- cbind(x1, votex=factor( rep(
c('Y', 'notEligible', 'Y', 'N', 'abstain', 'Y', 'notEligible'),
c(2,1,1,1,1,1,9) ) ) )
# }
# NOT RUN {
all.equal(x1., x2)
# }
# NOT RUN {
##
## 2. Test a case with a vote error in x
##
x1a <- cbind(x1, voterr=rep(
c('notEligible', 'Y', 'notEligible'), c(7, 1, 8)))
x1a. <- try(mergeVote(x1a, votetst))
# }
# NOT RUN {
class(x1a.)=='try-error'
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab