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
# PPOTM: Practical-Programming Of The Month (2016 January) | |
# iMAINloop: Continue asking users "what file to load" until they type a zero. | |
iMAINloop <- 0; | |
while (iMAINloop < 1 ) { | |
# Below creates a list of all files (in the current working directory) of pattern *.csv | |
# Note that you can set path="xxxx" to look in a different folder area | |
filenames <- list.files(pattern = ".csv") |
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
# packages to use | |
library(SWMPr) | |
library(httr) | |
library(XML) | |
library(foreach) | |
library(doParallel) | |
# names of files on server | |
files_s3 <- httr::GET('https://s3.amazonaws.com/swmpalldata/')$content | |
files_s3 <- rawToChar(files_s3) |
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
# 'root' character string of directory to search | |
# 'file_typs' character vector of file types to search | |
# 'omit_blank' logical indicating of blank lines are counted | |
# 'recursive' logical indicating if all directories within 'root' are searched | |
# 'lns' logical indicating if lines are counted, use F for counting characters | |
# 'trace' logical for monitoring progress | |
file.lens <- function(root, file_typs, omit_blank = F, recursive = T, | |
lns = T, trace = T){ | |
require(reshape2) |
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
plot.nnet<-function(mod.in,nid=T,all.out=T,all.in=T,bias=T,wts.only=F,rel.rsc=5, | |
circle.cex=5,node.labs=T,var.labs=T,x.lab=NULL,y.lab=NULL, | |
line.stag=NULL,struct=NULL,cex.val=1,alpha.val=1, | |
circle.col='lightblue',pos.col='black',neg.col='grey', | |
bord.col='lightblue', max.sp = F,...){ | |
require(scales) | |
#sanity checks | |
if('mlp' %in% class(mod.in)) warning('Bias layer not applicable for rsnns object') |
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
lek.fun<-function(mod.in,var.sens=NULL,resp.name=NULL,exp.in=NULL,steps=100,split.vals=seq(0,1,by=0.2),val.out=F){ | |
require(ggplot2) | |
require(reshape) | |
## | |
#sort out exp and resp names based on object type of call to mod.in | |
#get matrix for exp vars | |
#for nnet |
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
#credit http://stackoverflow.com/questions/13649473/add-a-common-legend-for-combined-ggplots | |
require(ggplot2) | |
require(reshape) | |
require(gridExtra) | |
p.dat<-data.frame(step=row.names(grp.dat),grp.dat,stringsAsFactors=F) | |
p.dat<-melt(p.dat,id='step') | |
p.dat$step<-as.numeric(p.dat$step) |
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
plot.area<-function(x,col=NULL,horiz=F,prop=T,stp.ln=T,grp.ln=T,axs.cex=1,axs.lab=T,lab.cex=1, | |
names=c('Group','Step','Value'),...){ | |
#sort out color fector | |
if(!is.null(col)){ | |
if(sum(col %in% colors()) != length(col)) stop('col vector must be in "colors()"') | |
col<-colorRampPalette(col)(ncol(x)) | |
} | |
else col<-colorRampPalette(c('lightblue','green'))(ncol(x)) | |
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
gar.fun<-function(out.var,mod.in,bar.plot=T,struct=NULL,x.lab=NULL, | |
y.lab=NULL, wts.only = F){ | |
require(ggplot2) | |
require(plyr) | |
# function works with neural networks from neuralnet, nnet, and RSNNS package | |
# manual input vector of weights also okay | |
#sanity checks |
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
shinyServer(function(input, output) { | |
myData <- reactive({ | |
read.table( | |
input$file$datapath, | |
sep='\t', | |
header=T, | |
stringsAsFactors=F | |
) | |
}) |
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
\documentclass[a4paper,12pt]{article} %document class declaration (article, report, book, etc) has to go first | |
\usepackage{times} %package imports times new roman font | |
\usepackage[margin=1in]{geometry} %change margins to 1in | |
\begin{document} | |
\renewcommand{\rmdefault}{ptm} | |
\setlength{\parindent}{0mm} %set indentation at start of new paragraphs | |
\setlength{\parskip}{0mm} %set white space between paragraphs |