Skip to content

Instantly share code, notes, and snippets.

View andrie's full-sized avatar

Andrie de Vries andrie

View GitHub Profile
@andrie
andrie / pagerank.R
Last active April 16, 2021 01:50
Analyze R packages for popularity, using pagerank algorithm
## Analyze R packages for popularity, using pagerank algorithm
# Inspired by Antonio Piccolboni, http://piccolboni.info/2012/05/essential-r-packages.html
library(miniCRAN)
library(igraph)
library(magrittr)
# Download matrix of available packages at specific date ------------------
@andrie
andrie / permutations of samples.R
Last active August 29, 2015 14:11
Computing the probability of drawing two identical numbers out of a hat
# Computing the probability of drawing two identical
# numbers out of a hat
# Incorrect - binomial distribution ---------------------------------------
# Use pbinom() to compute a probability curve for binomial
# distribution
@andrie
andrie / cran-package-communities.R
Last active August 29, 2015 14:11
Determine CRAN package clusters (communities)
## Determine CRAN package clusters (communities)
library(miniCRAN)
library(igraph)
library(magrittr)
# Download matrix of available packages at specific date ------------------
# Wrapper around available.packages ---------------------------------------
index <- function(url, type="source", filters=NULL){
contribUrl <- contrib.url(url, type=type)
available.packages(contribUrl, type=type, filters=filters)
}
# CRAN --------------------------------------------------------------------
@andrie
andrie / foreach-progressbar.R
Last active August 29, 2015 14:15
Create a tclktk progressbar to provide feedback when running a parallel job
library(foreach)
library(iterators)
library(doParallel)
library(tcltk)
# Choose number of iterations
n <- 250
# In sequence, without progress bar ---------------------------------------
@andrie
andrie / foreach-parallel-progressbar.R
Created February 21, 2015 13:53
Creating progress bars from each parallel worker using foreach and doParallel
library(foreach)
library(iterators)
library(doParallel)
library(tcltk)
# Choose number of iterations
n <- 1000
cl <- makeCluster(8)
@andrie
andrie / archimedes-spiral.R
Last active August 29, 2015 14:22
archimedes-spiral
# Based on archimedes spiral
# Inspired by https://www.youtube.com/watch?v=SEiSloE1r-A
# The surprising beauty of mathematics | Jonathan Matte | TEDxGreensFarmsAcademy
# See http://en.wikipedia.org/wiki/Archimedean_spiral
rotate <- function(theta){
matrix(
c(cos(theta), -sin(theta),
sin(theta), cos(theta)
),
@andrie
andrie / networkD3.R
Last active July 21, 2023 19:35
Visualise graph using the networkD3 package
library("networkD3")
library("igraph")
# Download prepared igraph file from github
url <- "https://github.com/andrie/cran-network-structure/blob/master/pdb/depGraph-CRAN.rds?raw=true"
datafile <- tempfile(fileext = ".rds")
download.file(url, destfile = datafile, mode = "wb")
gs <- readRDS(datafile)
# Remove all nodes with fewer than 50 edges
@andrie
andrie / SO-100K.R
Last active August 29, 2015 14:25
Analysing questions tagged R on StackOverflow
# StackOverflow query at
# https://data.stackexchange.com/stackoverflow/query/338993/r-trends-questions-per-tag-per-month#resultSets
# Import data -------------------------------------------------------------
url <- "https://data.stackexchange.com/stackoverflow/csv/437426"
dat <- read.csv(url)
dat$Month <- as.Date(dat$Month)
head(dat)
@andrie
andrie / popular-stackoverflow-tags.R
Created July 29, 2015 13:35
Analyse stackoverflow tags of top 10 languages