Skip to content

Instantly share code, notes, and snippets.

View doug-friedman's full-sized avatar

Doug Friedman doug-friedman

View GitHub Profile
#####################
### COLS FUNCTION ###
#####################
require(readr)
## Given the file, fields, and their classes, R will import only the relevant columns
## Instead of full class names, you should use the following naming conventions...
## c = character, d = double, i = integer, l = logical
## see read_csv documentation for more information
@doug-friedman
doug-friedman / getGrantsGovData
Last active July 1, 2019 04:19
An R function to scrape Grants.Gov Open Data.
## Scrape Grants.Gov Data using the API Query Parameters
## See http://docs.fbopen.apiary.io/ for details
## Specify keywords, whether you want to see noncompeted and/or closed grants,
## your API key, and whether or not you want to peek at the results first (see the first 10).
library(jsonlite, warn.conflicts=F)
library(RCurl, warn.conflicts=F)
getGrantsGovData = function(keywords=c(), showNonCompeted=TRUE, showClosed=TRUE, my.key="", peek=FALSE) {
@doug-friedman
doug-friedman / extractCols.R
Last active August 29, 2015 13:58
A quick R function to speed up reading in selected columns from a large csv file.
#####################
### COLS FUNCTION ###
#####################
## Given the file, fields, and their classes, R will import only the relevant columns
extractCols = function(file="", fields = c(), fields.class = c(), nrows=-1){
# Read the first line of the file
first.line = read.csv(file, nrows=1)