Skip to content

Instantly share code, notes, and snippets.

library(tidyverse)
df <- tribble(
~Age, ~WeeklyWages, ~HoursWorkedPerWeek,
48, 500, 38,
50, 200, 38,
39, 200, 38,
56, 200, 40
)
# Option 1: First column for variables and other columns for metrics
library(tidyverse)
economics %>%
ggplot(aes(x = date, y = unemploy)) +
geom_line(data = economics %>% filter(date < '1990-01-01'), color = "grey") +
geom_line(data = economics %>% filter(date < '2000-01-01') %>% filter(date > '1990-01-01'), color = "blue") +
geom_line(data = economics %>% filter(date >= '2000-01-01'), color = "grey")
# Usage example:
# excel_data_write("data/clean-data.xlsx",
# tibble(
# sheetName = c("months"),
# data = list(clean_data)
# )
# )
# excel_data_read("data/clean-data.xlsx", sheetName = "months")
excel_data_write = function(file, df)
# Datastudio formula
CASE
WHEN CAST(REGEXP_EXTRACT(Month, '^(\\d+)/') AS Number ) = YEAR(TODAY(), '%Y') AND CAST(REGEXP_EXTRACT(Month, '/(\\d+)/') AS Number ) = MONTH(TODAY(), '%m') THEN DAY(TODAY(), '%d')
WHEN REGEXP_CONTAINS(Month, '/(04|06|09|11)/') THEN 30
WHEN REGEXP_CONTAINS(Month, '/02/') THEN 28
ELSE 31
END
@jrosell
jrosell / puppeteer-fetch-and-render-docker.js
Created October 27, 2020 14:12
Fetch and render using an specific google chrome version. We'll use appropiate zenika/alpine-chrome docker image.
// puppeteer-fetch-and-render-docker.js
// Fetch and render using an specific google chrome version
// We'll use appropiate zenika/alpine-chrome docker image. More information: https://github.com/Zenika/alpine-chrome
// Run:
// $ docker run -it --mount src="$(pwd)",target=/myproject,type=bind zenika/alpine-chrome:76-with-puppeteer /bin/sh
// /usr/src/app# cp /myproject/puppeteer-fetch-and-render.js .
// /usr/src/app# node puppeteer-fetch-and-render.js
// /usr/src/app# cp screenshot.png /myproject
// /usr/src/app# exit
@jrosell
jrosell / conflicted.R
Created July 31, 2020 07:28
Como visualizar y resolver los conflictos entre distintos paquetes en R usando el paquete conflicted.
if(!require(tidyverse)) install.packages("tidyverse")
if(!require(conflicted)) install.packages("conflicted")
tidyverse_update()
library(tidyverse)
library(MASS)
library(conflicted)
conflict_scout()
Cars93 %>% dplyr::select(Origin)
@jrosell
jrosell / trello-to-pdf.Rmd
Last active July 28, 2020 16:06
Código de ejemplo de generación de un PDF a partir de un board de Trello. En este caso https://trello.com/b/NoiWfLdi/trello-backend-example-public
---
title: "Trello to PDF"
author: "jrosell"
date: "2020-07-28"
output: pdf_document
---
## R Markdown
This is an R Markdown document. It gets Trello cards and its attachments from specific list on a public board and build a PDF document from it.
if(!require(tidyverse)) install.packages("tidyverse")
if(!require(patchwork)) install.packages("patchwork")
library(patchwork)
library(tidyverse)
library(lubridate)
# Añadir anotaciones
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(color = class)) +
geom_smooth(se = FALSE) + labs(
---
title: "Impuestos y sueldos por país en Europa"
author: "Jordi Rosell"
date: "2020-06-08"
output:
html_document:
df_print: paged
---
```{r setup, include=FALSE}
@jrosell
jrosell / procesar.R
Last active June 1, 2022 11:42
Procesado de datos tabulares: vectores (string, decimales, enteros, logicos, fechas y horas, factores), listas (vectores de vectores), combinar o filtrar 2 o más tablas, iteraciones con map, pmap, invoke_map
if(!require(tidyverse)) install.packages("tidyverse")
if(!require(patchwork)) install.packages("patchwork")
if(!require(nycflights13)) install.packages('nycflights13')
if(!require(tidymodels)) install.packages("tidymodels")
if(!require(modelr)) install.packages("modelr")
library(tidymodels)
library(nycflights13)
library(patchwork)
library(tidyverse)
library(lubridate)