Last active
December 15, 2015 00:38
-
-
Save scisus/5174165 to your computer and use it in GitHub Desktop.
A script to help me do QA for data entry. Works from the command line. Yay!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
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 | |
library(gdata) | |
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),] | |
}else{ | |
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