Skip to content

Instantly share code, notes, and snippets.

View statnmap's full-sized avatar

Sébastien Rochette statnmap

View GitHub Profile
@statnmap
statnmap / unstated_deps.R
Last active September 22, 2022 17:49
Check: for unstated dependencies in ‘tests’
# When in your package in development
db <- tools:::.read_description("DESCRIPTION")
testdir <- "tests/testthat"
Rinfiles <- list.files(testdir, pattern = "\\.Rin$", full.names = TRUE)
Rfiles <- list.files(testdir, pattern = "\\.[rR]$", full.names = TRUE)
res <- tools:::.check_packages_used_helper(db, c(Rinfiles, Rfiles))
res
repos <- tools:::.get_standard_repository_URLs()
@statnmap
statnmap / render_and_observeEvent.R
Created September 22, 2022 15:53
Why you do not want to use `render*()` inside `observeEvent()`: it does not do what you think it does
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
@statnmap
statnmap / render_toc.R
Last active October 9, 2021 17:40 — forked from gadenbuie/render_toc.R
Generate Manual Table of Contents in (R)Markdown Documents
#' 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 August 2, 2021 09:20
Thank GitHub contributors in your articles
# 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 December 12, 2021 19:53
VSCode R users extensions
@statnmap
statnmap / overlapping_buffers.R
Created May 20, 2020 15:40
Find overlapping polygons after buffer
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 October 31, 2019 07:38
Transform multiple layer dataframe raster into stack
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 April 2, 2019 07:02 — forked from VincentGuyader/install-mini.R
configuration poste 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 March 10, 2019 13:59
Transform hexbin object into sf polygon
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)