Skip to content

Instantly share code, notes, and snippets.

View RLesur's full-sized avatar

Romain Lesur RLesur

View GitHub Profile
@hrbrmstr
hrbrmstr / gg_tweet.R
Last active October 16, 2020 04:49
use the magick device to make ggplots conform to twitter card or in-stream image optimal sizes, with or without "retina" resolution
library(httr)
library(magick)
library(hrbrthemes)
library(ggplot2)
theme_tweet_rc <- function(grid = "XY", style = c("stream", "card"), retina=TRUE) {
style <- match.arg(tolower(style), c("stream", "card"))
switch(
@RLesur
RLesur / case_when_factory.R
Last active October 31, 2023 23:48
How to create reusable dplyr::case_when() functions?
# case_when factory: ----------------------------------------------
create_case_when <- function(..., vars = "x") {
fun_fmls <- purrr::map(rlang::set_names(vars), ~ rlang::missing_arg())
fun_body <- substitute({
for (name in var) {
symb <- rlang::eval_bare(rlang::sym(name))
var <- rlang::eval_tidy(rlang::enquo(symb))
assign(name, var)
}
forms <- purrr::map(formulas, rlang::`f_env<-`, value = environment())
sapply(list.files(pattern = "\\.html$"), function(file) {
html <- readLines(file)
new_html <- gsub(
"https:.*?MathJax\\.js\\?",
"https://mathjax.rstudio.com/latest/MathJax.js?",
html
)
writeLines(new_html, file)
})
@cderv
cderv / update_git_remote.R
Created April 5, 2019 16:21
update git remote to new url
# Copyright (C) 2018 C. Dervieux
# Licence MIT - https://spdx.org/licenses/MIT.html
#' Update git remote url from R
#'
#' If git remote server is migrated and url is changed, this function allows to easily update
#' the url of local git repo to the new git remote url.
#'
#' This function need `git2r`, `urltools` and `glue` to work.
#'
@julientaq
julientaq / baseline.css
Created July 8, 2019 20:56
paged.js Baseline
:root {
--baseline: var(--font-lineHeight);
--baseline-color: red;
}
.pagedjs_page {
/* grid baseline */