This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ditto <- function(expr) { | |
plus_fun <- function(e1, e2) { | |
if (is.list(e1)) { | |
c(e1, list(e2)) | |
} else { | |
list(e1, e2) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tutorial.js <- system.file("lib", "tutorial", "tutorial.js", package = "learnr") | |
tutorial_format.js <- system.file("rmarkdown", "templates", "tutorial", "resources", "tutorial-format.js", package = "learnr") | |
changes <- list( | |
run_code = list( | |
text = "Correr Código", | |
file = tutorial.js, | |
pattern = 'var run_button = add_submit_button("fa-play", "btn-success",', | |
code = 'var run_button = add_submit_button("fa-play", "btn-success", "{text}", false)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Adds tags to facets | |
#' | |
#' @export | |
facet_tags <- function(position = "tl", tag_pool = letters, open = "", close = ")", stroke = 0.15, stroke.color = "white", | |
color = "black") { | |
if (!is.list(position)) { | |
position <- switch(position, | |
tl = list(x = 0, y = 1, hjust = 0, vjust = 1), | |
tr = list(x = 1, y = 1, hjust = 1, vjust = 1), | |
bl = list(x = 0, y = 0, hjust = 0, vjust = 0), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## List system dependenceis for a local project (with a DESCRIPTION file) | |
## and create an "apt install" command that installs them. Put it in your | |
## dockerfile and be happy. | |
library(magrittr) | |
all_types <- c("Imports", "Depends", "Suggests") | |
description_file <- here::here("DESCRIPTION") | |
direct_deps <- all_types %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read -p "Usuario en el servidor: " USUARIO | |
read -p "Servidor: " SERVER | |
read -p "Puerto [4572]: " PUERTO | |
PUERTO=${PUERTO:-4572} | |
read -p "Nombre del tunel (y el comando) [rstudioserver]: " NOMBRE | |
NOMBRE=${NOMBRE:-rstudioserver} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(data.table) | |
library(magrittr) | |
library(ggplot2) | |
url_movility <- "https://raw.githubusercontent.com/githubmg/reduccion_movilidad/master/data/Global_Mobility_Report.csv" | |
url_deaths <- "https://raw.githubusercontent.com/githubmg/reduccion_movilidad/master/data/time_series_covid19_deaths_global.csv" | |
mov <- fread(url_movility) %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is an experiment to wrap CDO in R in a intuitive and pipe friendly way. | |
# Usage: | |
# cdo_* will create a string with a commmand. If any of the "input_file" arguments | |
# is a cdo command, it will append "-" to it so that it can be chained. | |
# This is good for efficiency as it will allow you to apply multiple | |
# operations without having to write to disk the intermediate files. | |
## "Internal" functions in which the magic happens | |
.enchain <- function(input) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(data.table) | |
library(magrittr) | |
# From https://www.ssa.gov/oact/babynames/limits.html | |
file <- "https://www.ssa.gov/oact/babynames/state/namesbystate.zip" | |
destination <- "/home/elio/Downloads/babies.zip" | |
download.file(file, destination) | |
dir <- "/home/elio/Downloads/babies" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(data.table) | |
library(magrittr) | |
library(ggplot2) | |
set.seed(42) | |
do_bench <- function(N) { | |
dt <- suppressWarnings(data.table(x = rnorm(N), | |
group = letters[1:3])) | |
pipe <- function() { | |
dt %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Tweet thread" | |
author: "Elio Campitelli" | |
output: github_document | |
--- | |
```{r} | |
knitr::opts_chunk$set(dev = "png", | |
tweet_this = TRUE) |