Skip to content

Instantly share code, notes, and snippets.

View Pakillo's full-sized avatar
🌳
Living the dream

Francisco Rodriguez-Sanchez Pakillo

🌳
Living the dream
View GitHub Profile
@leeper
leeper / update_github.R
Last active February 2, 2021 22:56
Update packages if a newer version is available from GitHub
library('devtools')
library('utils')
library('httr')
update_github <-
function(ask = TRUE, ...){
installed <- installed.packages()
oldVersion <- installed[,'Version']
urls <- sapply(names(oldVersion), function(x){
d <- packageDescription(x)
#Create an explicit binomially distributed set of numbers
n = 1000
frac = 0.9
x = rep(c(1,0),times = c(n*frac, n*(1-frac)))
#Fit a Gaussian model and a binomial model to the same data
gauss_mod = glm(x~1,family = gaussian)
binom_mod = glm(x~1, family= binomial)
#Compare AIC
@hadley
hadley / curriculum.md
Created September 27, 2013 20:24
My first stab at a basic R programming curriculum. I think teaching just these topics without overall motivating examples would be extremely boring, but if you're a self-taught R user, this might be useful to help spot your gaps.

Notes:

  • I've tried to break up in to separate pieces, but it's not always possible: e.g. knowledge of data structures and subsetting are tidy intertwined.

  • Level of Bloom's taxonomy listed in square brackets, e.g. http://bit.ly/15gqPEx. Few categories currently assess components higher in the taxonomy.

Programming R curriculum

Data structures

@AlbertRapp
AlbertRapp / street_map_game_mechanics.qmd
Created June 19, 2022 14:59
Testing out the mechanics for a shiny web app/game with maps and street names
---
output: html_document
editor_options:
chunk_output_type: console
---
## Load Packages
```{r}
setwd(here::here('streep_map_game/'))
@danlwarren
danlwarren / thin.max.R
Last active October 5, 2022 14:19
thin.max.R, a function for rarefying point data in any number of dimensions
# Function to rarefy point data in any number of dimensions. The goal here is to
# take a large data set and reduce it in size in such a way as to approximately maximize the
# difference between points. For instance, if you have 2000 points but suspect a lot of
# spatial autocorrelation between them, you can pass in your data frame, the names (or indices)
# of the lat/lon columns, and the number 200, and you get back 200 points from your original data
# set that are chosen to be as different from each other as possible given a randomly chosen
# starting point
# Input is:
#
@jesperronn
jesperronn / docx2md.md
Last active November 21, 2023 12:49 — forked from aembleton/docx2md.md
Convert a Word Document into MD

Converting a Word Document to Markdown in One Move

The Problem

A lot of important government documents are created and saved in Microsoft Word (*.docx). But Microsoft Word is a proprietary format, and it's not really useful for presenting documents on the web. So, I wanted to find a way to convert a .docx file into markdown.

Installing Pandoc

On a mac you can use homebrew by running the command brew install pandoc.

The Solution

@benmarwick
benmarwick / inspect-rmd-diff-from-last-commit.R
Last active February 8, 2024 21:17
GitHub doesn't show rich diffs for Rmd files. That can make collaborative writing tough. Here's how to see rich diffs of two commits of a single R Markdown document on a GitHub repo or local Git repo
# another method
# remotes::install_github("ropenscilabs/reviewer")
browseURL(reviewer::diff_rmd("analysis/paper/paper.qmd",
# this gets the sha of the previous commit
git2r::commits(n=2)[[2]]$sha)$raw)
@johnbaums
johnbaums / diverge0.R
Last active February 15, 2024 09:42
Plot a rasterVis::levelplot with a colour ramp diverging around zero
diverge0 <- function(p, ramp) {
# p: a trellis object resulting from rasterVis::levelplot
# ramp: the name of an RColorBrewer palette (as character), a character
# vector of colour names to interpolate, or a colorRampPalette.
require(RColorBrewer)
require(rasterVis)
if(length(ramp)==1 && is.character(ramp) && ramp %in%
row.names(brewer.pal.info)) {
ramp <- suppressWarnings(colorRampPalette(brewer.pal(11, ramp)))
} else if(length(ramp) > 1 && is.character(ramp) && all(ramp %in% colors())) {