Skip to content

Instantly share code, notes, and snippets.

@steadyfish
steadyfish / Instructions_for_creating_R_packages
Last active August 29, 2015 14:20
Creating R packages using RStudio, Git and GitHub
This method helps creating the proper R package directory structure using RStudio and then syncs it with the corresponding GitHub Project.
Sources:
http://www.molecularecologist.com/2013/11/using-github-with-r-and-rstudio/
https://support.rstudio.com/hc/en-us/articles/200532077-Version-Control-with-Git-and-SVN
http://r-pkgs.had.co.nz/git.html
Setup a GitHub account.
Download and install Rstudio.
@steadyfish
steadyfish / dplyr_functions_programmatic_use.R
Last active October 12, 2020 09:27
using dplyr functions programmatically
# using dplyr finctions in non-interactive mode
# examples
library(plyr)
library(dplyr)
d1 = data_frame(x = seq(1,20),y = rep(1:10,2),z = rep(1:5,4))
head(d1)
#### single table verbs ####
@steadyfish
steadyfish / GOIDataInput.R
Last active May 22, 2019 06:47
Accessing Open Data Portal (India) using APIs
####Download the data from Government of India open data portal#####
w_dir = getwd()
source(file=file.path(w_dir,"Code/Core.R"))
checkAndDownload(c("XML","RCurl","RJSONIO","plyr"))
### Alternative - 1: Using APIs ###
#JSON#
getJSONDoc <- function(link, res_id, api_key, offset, no_elements){
jsonURL = paste(link,
"resource_id=",res_id,
######## Packages ########
checkAndDownload<-function(packageNames) {
for(packageName in packageNames) {
if(!isInstalled(packageName)) {
install.packages(packageName,repos="http://lib.stat.cmu.edu/R/CRAN")
}
library(packageName,character.only=TRUE,quietly=TRUE,verbose=FALSE)
}
}