Skip to content

Instantly share code, notes, and snippets.

Jason Bryer jbryer

Block or report user

Report or block jbryer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jbryer
jbryer / RPackageInstaller.R
Created Nov 23, 2011
Install basic set of R packages
View RPackageInstaller.R
.libPaths() #By default, R will install packages to the first element
#This script will install some very common R packages.
repos = 'http://cran.r-project.org' #Main CRAN
repos.win = 'http://www.stats.ox.ac.uk/pub/RWin' #Site provides some prebuilt binaries for Windows
repos.rforge = 'http://r-forge.r-project.org'
libraries = c('Deducer', 'devtools', 'doBy', 'foreign', 'gdata', 'ggplot2', 'gmaps',
'Hmisc', 'JGR', 'maps', 'mapdata', 'mapproj', 'maptools', 'proto', 'psych', 'R2wd',
'Rcmdr', 'RCurl', 'reshape', 'RODBC', 'roxygen2', 'seqinr', 'sm', 'sp',
@jbryer
jbryer / GoogleReader.R
Created Jan 13, 2012
Function to return an RSS feed using the (unofficial) Google Reader API
View GoogleReader.R
require(XML)
require(RCurl)
#' This function ruturns an XML tree of the RSS feed from the given URL.
#'
#' This function utilizes the (unofficial) Google Reader API to retrieve RSS
#' feeds. The advantage of access RSS feeds through the Google Reader API is that
#' you are not limited by the number of entries a website may included in their
#' feed. That is, Google maintains generally maintains a complete history of
#' entries from the RSS feed.
@jbryer
jbryer / RBloggers.R
Created Jan 13, 2012
Retrieving and Analyzing R-Bloggers using the Google Reader API
View RBloggers.R
source('https://raw.github.com/gist/1606595/269d61dfcc7930f5275a212e11f3c43771ab2591/GoogleReader.R')
rbloggers = getRSSFeed(feedURL="http://r-bloggers.com/feed",
email="GOOGLE READER EMAIL",
passwd="GOOGLE READER PASSWORD",
posts=5000)
entries = rbloggers[which(names(rbloggers) == "entry")]
length(entries)
saveXML(rbloggers, file='rbloggers.xml')
@jbryer
jbryer / EmailClass.R
Created Jan 20, 2012
Example of object oriented programming in R
View EmailClass.R
#' Constructor
EmailClass <- function(name, email) {
nc = list(
name = name,
email = email,
get = function(x) nc[[x]],
set = function(x, value) nc[[x]] <<- value,
props = list(),
history = list(),
getHistory = function() return(nc$history),
@jbryer
jbryer / BirthdayProblem.R
Created Jan 31, 2012
Given a room with n people in it, what is the probability any two will have the same birthday?
View BirthdayProblem.R
## See http://en.wikipedia.org/wiki/Birthday_problem for an explanation of the problem
require(ggplot2)
require(reshape)
theme_update(panel.background=theme_blank(),
panel.grid.major=theme_blank(),
panel.border=theme_blank())
birthday <- function(n) {
1 - exp( - n^2 / (2 * 365) )
@jbryer
jbryer / setup.r
Created Mar 7, 2012
R Setup Script
View setup.r
#List of most used R packages that we wish to install.
libraries = c('cacheSweave', 'Deducer', 'devtools', 'doBy', 'foreign', 'gdata',
'ggplot2', 'Hmisc', 'JGR', 'lubridate', 'maps', 'mapdata', 'mapproj',
'maptools', 'proto', 'psych', 'R2wd', 'RCurl', 'reshape',
'RODBC', 'roxygen2', 'seqinr', 'sm', 'sp', 'sqldf', 'survey',
'WriteXLS', 'XML', 'xtable')
#We will install packages from the main CRAN site
repos = 'http://cran.r-project.org'
#Site provides some prebuilt binaries for Windows
@jbryer
jbryer / Rprofile.R
Created Mar 7, 2012
My .Rprofile that works both on Windows and Linux
View Rprofile.R
# .Rprofile -- commands in this file will be executed at the beginning of
# each R session. On Windows, the R_PROFILE environment variable must have value
# with the full path to this file. On Linux (or other Unix like systems) this file
# must be in the user's home directory.
# Set the default repository to the main CRAN site
options(repos=c(CRAN='http://cran.r-project.org'))
# Set the oDrive varaible and library path
if(Sys.info()['sysname'] == 'Windows') {
@jbryer
jbryer / ggplot2Cheat.r
Created Apr 26, 2012
Graphic Parameters (symbols, line types, and colors) for ggplot2
View ggplot2Cheat.r
require(ggplot2)
require(grid)
theme_update(panel.background=theme_blank(),
panel.grid.major=theme_blank(),
panel.border=theme_blank())
#Borrowed (i.e. stollen) from http://research.stowers-institute.org/efg/R/Color/Chart/ColorChart.R
getColorHexAndDecimal <- function(color) {
if(is.na(color)) {
@jbryer
jbryer / varEntryDialog.r
Created Aug 13, 2012
Function to create a tcl/tk dialog box for a user to enter variable values.
View varEntryDialog.r
#' Creates a dialog box using tcl/tk to get input from the user.
#'
#' This function will create a tcl/tk dialog box to get user input. It has been
#' written to be extensible so the R programmer can easily create a dialog with
#' any number of varaibles with custom labels and data conversion of the user
#' entered data. The function will return a list where the element names are
#' \code{vars} and the value is the user input. By default, all entry will be
#' converted using the \code{as.character} function. However, this can easily be
#' altered using the \code{fun} parameter. For example, if integers are required,
#' use \code{fun=c(as.integer, ...)}. It is also possible to write custom
@jbryer
jbryer / xtable.decimal.r
Last active Jun 29, 2017
Prints a LaTeX table with numeric columns aligned on their decimal points. This function wraps the xtable and print.xtable functions in the xtable package so that numeric columns are aligned on their decimal place.
View xtable.decimal.r
require(xtable)
#' Prints a LaTeX table with numeric columns aligned on their decimal points.
#'
#' This function wraps the \code{\link{xtable}} and \code{\link{print.xtable}}
#' functions in the \code{xtable} package so that numeric columns are aligned
#' on their decimal place.
#'
#' See \url{http://jason.bryer.org/posts/2013-01-04/xtable_with_aligned_decimals.html}
#' for more information.
You can’t perform that action at this time.