Skip to content

Instantly share code, notes, and snippets.

@nico202
Last active February 20, 2019 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nico202/ec1fb3182dc1aec459e8b229880b5fde to your computer and use it in GitHub Desktop.
Save nico202/ec1fb3182dc1aec459e8b229880b5fde to your computer and use it in GitHub Desktop.
statcheck command line interface
# License is GPLv2+
#!/usr/bin/env Rscript
library(statcheck)
library(stringr)
args <- commandArgs(trailingOnly=TRUE)
if (length(args)==0) {
stop("Usage: statcheck-cli filename.txt", call.=FALSE)
} else if (length(args)==1) {
## default output file
filename <- args[1]
}
buffer <- readLines(filename)
res <- statcheck(buffer,stat = c("t", "F", "cor", "chisq", "Z", "Q"),
OneTailedTests = FALSE, alpha = 0.05, pEqualAlphaSig = TRUE,
pZeroError = TRUE, OneTailedTxt = FALSE, AllPValues = FALSE)
if (length(res) == 0) {
print("No report found")
q()
}
lines <- list()
for(i in 1:nrow(res)) {
stat <- as.character(res$Raw[i])
lines <- grep(stat, buffer, fixed = TRUE)
for (line in lines) {
found <- str_locate_all(buffer[line], fixed(stat))
for (point in 1:length(found)) {
lp <- found[[point]]
lineend <- lp[2]
exp <- format(round(res$Computed[i], 3))
if (res$Error[i]) {
message <- paste("The expected value is ",
exp, " (", res$Computed[i], ")", sep = "")
mtype <- "error: "
} else {
message <- stat
mtype <- "info: "
}
cat(filename, ":", line, ":", lp[1], ": ", mtype,
message, "\n",
sep = "")
}
}
}
;; add this to your emacs config. `statcheck-cli` must be in your PATH
(flycheck-define-checker statscheck
"A linter for statistics."
:command ("statscheck-cli" source)
:error-patterns
((error line-start (file-name) ":" line ":" column ": error: "
(message) line-end)
(info line-start (file-name) ":" line ":" column ": info: "
(message) line-end))
:modes (text-mode markdown-mode org-mode))
(add-to-list 'flycheck-checkers 'statscheck)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment