Skip to content

Instantly share code, notes, and snippets.

Last active Dec 15, 2015
What would you like to do?
A script to help me do QA for data entry. Works from the command line. Yay!
# QA helper
# Generate rows to check and keep track of rows already checked
args <- commandArgs(TRUE) # should be (in order): # of rows to check, # of sheets in workbook, and filename
#choose number of entries to check
check <- args[1]
#enter number of sheets in workbook
no_sheets <- args[2]
filename <- args[3]
#pick random sheet from excel workbook
rand_sheet <- sample(1:no_sheets, 1)
sheet <- c(rep(rand_sheet, check))
#get number of rows in data entry sheet so far
xlsdat <- read.xls(filename, sheet = rand_sheet, blank.lines.skip=TRUE)
noc <- dim(xlsdat)[1]
#generate new random cells to check
test <- sort(sample(1:noc, check, replace=TRUE))
correct <- test * NA
qa <- data.frame(sheet, test, correct)
# write out
if (file.exists('QA.txt')) {
qa_temp <- read.table("QA.txt", header=TRUE, sep=' ', stringsAsFactors=FALSE)
qa_temp <- rbind(qa_temp, qa) #combine new & old
qa <- subset(qa_temp, duplicated(qa_temp$test)==FALSE) #remove duplicates
write.table(qa, "QA.txt", quote=FALSE, row.names=FALSE, na = "NA")[order(test,correct),]
qa <- qa[order(test,correct),]
write.table(qa, "QA.txt", quote=FALSE, row.names=FALSE, na = "NA")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment