Skip to content

Instantly share code, notes, and snippets.

Avatar

Sébastien Rochette statnmap

View GitHub Profile
@statnmap
statnmap / render_toc.R
Last active Oct 9, 2021 — forked from gadenbuie/render_toc.R
Generate Manual Table of Contents in (R)Markdown Documents
View render_toc.R
#' Render Table of Contents
#'
#' A simple function to extract headers from an RMarkdown or Markdown document
#' and build a table of contents. Returns a markdown list with links to the
#' headers using
#' [pandoc header identifiers](http://pandoc.org/MANUAL.html#header-identifiers).
#'
#' WARNING: This function only works with hash-tag headers.
#'
#' Because this function returns only the markdown list, the header for the
@statnmap
statnmap / thank_GitHub_contributors.R
Last active Aug 2, 2021
Thank GitHub contributors in your articles
View thank_GitHub_contributors.R
# Thanks for article
library(purrr)
library(gh)
repos <- gh("/repos/statnmap/gitlabr/stats/contributors")
map(repos, "author") %>% map("login")
map_chr(repos, ~paste0(
# "[&#x0040;", # With @ before
"[",
@statnmap
statnmap / vscode_r_users_extensions.md
Last active Sep 7, 2021
VSCode R users extensions
View vscode_r_users_extensions.md
@statnmap
statnmap / overlapping_buffers.R
Created May 20, 2020
Find overlapping polygons after buffer
View overlapping_buffers.R
library(sf)
library(ggplot2)
library(dplyr)
# Get data
extraWD <- "."
if (!file.exists(file.path(extraWD, "departement.zip"))) {
githubURL <- "https://github.com/statnmap/blog_tips/raw/master/2018-07-14-introduction-to-mapping-with-sf-and-co/data/departement.zip"
download.file(githubURL, file.path(extraWD, "departement.zip"))
unzip(file.path(extraWD, "departement.zip"), exdir = extraWD)
@statnmap
statnmap / df_to_stack.R
Created Oct 31, 2019
Transform multiple layer dataframe raster into stack
View df_to_stack.R
library(raster)
# remotes::install_github("statnmap/cartomisc")
library(cartomisc)
library(dplyr)
library(purrr)
# Create original raster
fn <- system.file("external/test.grd", package="raster")
s <- stack(fn, fn)
@statnmap
statnmap / install-mini.R
Last active Apr 2, 2019 — forked from VincentGuyader/install-mini.R
configuration poste R
View install-mini.R
percent <- function(x, digits = 2, format = "f", ...) {
paste0(formatC(100 * x, format = format, digits = digits, ...), "%")
}
mon_print <- function(synth){
N<-nrow(synth)
if( is.null(N)){
N<-1
synth <-
matrix(synth,nrow=1)
@statnmap
statnmap / hexbin_to_sf
Created Mar 10, 2019
Transform hexbin object into sf polygon
View hexbin_to_sf
library(hexbin)
library(sf)
# Create an hexbin
set.seed(101)
x <- rnorm(10000)
y <- rnorm(10000)
bin <- hexbin(x, y)
str(bin)
# st_as_sf(bin)