Skip to content

Instantly share code, notes, and snippets.

View andrie's full-sized avatar

Andrie de Vries andrie

View GitHub Profile
@andrie
andrie / CRAN_pkg_history.R
Last active February 26, 2020 19:38
Scrapes CRAN for historical number of packages per release
# Scrapes CRAN archives to determine the number of packages per release
# Create a list of pages to scrape, including both archive and current
extract_url <- function(){
url <- list(
archive = "https://cran-archive.r-project.org/bin/windows/contrib/",
active = "https://cran.r-project.org/bin/windows/contrib/"
)
get_urls <- function(url){

Keybase proof

I hereby claim:

  • I am andrie on github.
  • I am apdevries (https://keybase.io/apdevries) on keybase.
  • I have a public key ASDOCA6xxvGsbQQS_v860hBzhtmtZ2Jf-sscY3X2a2kl5wo

To claim this, I am signing this object:

@andrie
andrie / 1-RODBC.R
Created October 12, 2015 11:00
Preview of using Revolution R Enterprise inside SQL Server 2016
### Connect to SQL Server using RODBC
library(RODBC)
library(magrittr)
# Connect to SQL Server using RODBC ------------------
sqlHost <- "DAA136209339.sys-sqlsvr.local"
sqlDatabase <- "RevoTestDB"
dsnString <- "driver={SQL Server};server=%s;database=%s;trusted_connection=true"
@andrie
andrie / interpolate.R
Last active December 9, 2019 06:56
Interpolation and smoothing functions in R
# Generate data in the form of a sine wave
set.seed(1)
n <- 1e3
dat <- data.frame(
x = 1:n,
y = sin(seq(0, 5*pi, length.out = n)) + rnorm(n=n, mean = 0, sd=0.1)
)
approxData <- data.frame(
@andrie
andrie / doSNOW.R
Created October 21, 2015 10:08
Progress bars with foreach and doSNOW
library(doSNOW)
library(tcltk)
cl <- makeSOCKcluster(2)
registerDoSNOW(cl)
pb <- txtProgressBar(max=100, style=3)
progress <- function(n) setTxtProgressBar(pb, n)
opts <- list(progress=progress)
r <- foreach(i=1:100, .options.snow=opts) %dopar% {
@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 / analysis.R
Created December 27, 2015 18:34
World record runing events
library(ggplot2)
dat <- read.csv("world records.csv", stringsAsFactors = FALSE)
# Clean and transform the data --------------------------------------------
track <- within(dat, {
Time <- as.numeric(Time.in.hours)
Date <- as.Date(Date, format = "%d-%b-%y")
Speed <- Distance / Time
logDistance <- log10(Distance)
@andrie
andrie / strange_attractor.R
Created April 17, 2019 14:27
Plotting strange attractors using `datashader` with `reticulate`
# Original blog post
# https://fronkonstin.com/2019/01/10/rcpp-camaron-de-la-isla-and-the-beauty-of-maths/
# For this example to work, you must have a conda environment with the datashader library
# See http://datashader.org/getting_started/index.html#installation for installation instructions
library(Rcpp)
library(reticulate)
library(dplyr)
use_condaenv("datashader", required = TRUE)
@andrie
andrie / 1-miniCRAN.R
Last active April 2, 2018 11:44
Introduction to miniCRAN
# Install package from CRAN
getOption("repos")
options(repos=c(CRAN="http://cran.at.r-project.org/"))
install.packages("miniCRAN", type="source")
library("miniCRAN")
sessionInfo()
@andrie
andrie / 0-miniCRAN-SQL-server.R
Last active September 20, 2017 11:42
Use miniCRAN to install packages on SQL Server
# Instructions for using miniCRAN to create a package repository for installing packages on SQL Server 2016
#
# 1. Create a local repository on a machine connected to the Internet
# 2. Copy the miniCRAN repository to the target machine
# 3. Install the packages on the target machine