Created
August 7, 2013 17:56
-
-
Save cameronbracken/6176642 to your computer and use it in GitHub Desktop.
Demonstrates R lint error. Run like this (need to make executable first, `chmod +x Rlint.R`): ./Rlint.R lint_test.R
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
a = 1 |
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
#!/usr/bin/env Rscript | |
try_require <- function(pkg){ | |
e <- try( | |
suppressPackageStartupMessages(library(pkg,character.only=TRUE)) | |
,silent=TRUE) | |
if(class(e) == 'try-error') | |
invisible(FALSE) | |
else | |
invisible(TRUE) | |
} | |
try_require_install <- function(pkg){ | |
if(!(result <- try_require(pkg))){ | |
install.packages(pkg,repos='http://cran.rstudio.com/',quiet=TRUE) | |
result <- try_require(pkg) | |
} | |
invisible(result) | |
} | |
installed <- c( | |
try_require_install('optparse'), | |
try_require_install('lint') | |
) | |
if(any(!installed)){ | |
cat('Could not install optparse or lint packages.\n') | |
q(status=1) | |
} | |
op.obj <- OptionParser() | |
opt <- parse_args(op.obj, positional_arguments = TRUE) | |
file <- opt$args | |
opt <- opt$options | |
if(length(file) == 0) { | |
cat('No input file.\n') | |
q(status=1) | |
}else if(length(file) > 1){ | |
cat('Too many input files.\n') | |
q(status=1) | |
} | |
l <- lint(file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment