Skip to content

Instantly share code, notes, and snippets.

View bastianolea's full-sized avatar
💭
🌸

Bastián Olea Herera bastianolea

💭
🌸
View GitHub Profile
@bastianolea
bastianolea / sf-x265-libheif-fix.md
Created September 11, 2026 20:20
Fixing R `sf` load failure on Intel macOS: `libx265.216.dylib` / `x265_api_get_216` not found

Fixing R sf load failure on Intel macOS: libx265.216.dylib / x265_api_get_216 not found

Platform: macOS 14.6.1 (Sonoma), Intel x86_64 · Homebrew 6.x · R 4.6.1 · sf linked to GDAL via Homebrew

If you landed here from an error like Library not loaded: libx265.216.dylib or Symbol not found: _x265_api_get_216 when loading sf (or terra, gdal, anything that pulls in libheif), this gist explains what happened, the fix that worked, and the alternative approaches.

Full error I got:

@bastianolea
bastianolea / show-quarto-toc-on-mobile.md
Last active September 10, 2026 19:53
Show Quarto TOC on mobile

Showing the Quarto TOC on mobile (and keeping it in place)

By default, Quarto hides the table of contents (TOC) on narrow screens. This gist shows how to bring it back on mobile, drop it inline at a specific point in the page, and stop it from following the scroll — while keeping the original desktop TOC untouched.

Written up from a real fix on a Quarto HTML site with a right-hand TOC (toc-location: right). Tested with a recent Quarto release.

@bastianolea
bastianolea / quarto_plot_height.qmd
Created September 2, 2026 17:06
Quarto figures with height calculated from data rows
---
title: "Plot height test"
format:
html:
embed-resources: true
---
With parametrized Quarto reports, certain figures are expected to grow or shrink in widht/height based on existing data. This Quarto report demonstrates how to automatically adjust figure height based on the number of rows present in data. A horizontal column plot (where Y values are groups and X values are a continuous variable, so that bars grow sideways) of fixed height would simply shrink all columns to make them fit in the default height, but in this example, the plot height itself will increase according to the number of rows, so that all plots will have roughly the same column widths.
```{r setup}
@bastianolea
bastianolea / brew_install_user_dir
Created August 28, 2026 20:22
Instalar programas o aplicaciones con Homebrew en carpeta de usuario
brew install <pkg> --appdir ~/Applications
brew install --cask <app> --appdir ~/Applications
@bastianolea
bastianolea / informes_consar.R
Created April 1, 2026 16:47
Descargar informes trimestrales de la Comisión Nacional del Sistema de Ahorro para el Retiro de México
# https://x.com/bastimapache/status/2039382214098534586
# script que descarga archivos de una página de internet
# pero además los clasifica en un dataframe con metadatos que vienen
# desde la misma página donde están alojados, ésto porque los nombres
# de los archivos no son consistentes en la descripción de su contenido
library(rvest)
# obtener código del sitio web
@bastianolea
bastianolea / datos_estructurados_llm.R
Created March 7, 2026 21:56
extracción de datos estructurados a partir de textos con R
# extracción de datos estructurados a partir de textos
# basado en el workshop [_LLMs in R for Data Analysis_](https://thisisnic.github.io/rainbowrworkshop/code.html) impartido por [Nic Crane](https://niccrane.com) en la fabulosa [conferencia de RainbowR 2026](https://conference.rainbowr.org)
# carga de datos
library(readr)
url = "https://github.com/bastianolea/prensa_chile/raw/main/prensa_datos_muestra_2025.csv"
noticias <- read_csv2(url)
@bastianolea
bastianolea / censo_genero_graficos_loop.R
Created February 18, 2026 15:25
Código en R para cargar datos del censo, crear funciones que los procesan, hacer una función para visualizar datos, y finalmente usar un loop para generar múltiples gráficos
# código para cargar datos del censo, crear funciones que los procesan, hacer una función para visualizar datos, y finalmente usar un loop para generar múltiples gráficos
library(readxl)
library(dplyr)
library(janitor)
library(tidyr)
library(ggplot2)
# setwd("~/Documents/Otros/blog/content/blog/2026-02-18b")
@bastianolea
bastianolea / mapas_censo_mapgl.R
Created December 17, 2025 20:01
Código para visualizar mapas interactivos con los datos del Censo 2024 a nivel de manzana con R
# código para visualizar mapas interactivos con los datos del Censo 2024 a nivel de manzana con R con {mapgl}
library(dplyr)
library(arrow)
library(mapgl)
manzanas <- read_parquet("datos/Cartografia_censo2024_Pais/Cartografia_censo2024_Pais_Manzanas.parquet")
manzanas |> names()
manzanas |> glimpse()
@bastianolea
bastianolea / mapas_censo_ggplot.R
Created December 17, 2025 20:00
Código para visualizar mapas con los datos del Censo 2024 a nivel de manzana
# código para visualizar mapas con los datos del Censo 2024 a nivel de manzana
library(dplyr)
library(arrow)
library(sf)
library(ggplot2)
# cargar datos
manzanas <- read_parquet("datos/Cartografia_censo2024_Pais/Cartografia_censo2024_Pais_Manzanas.parquet")
@bastianolea
bastianolea / rselenium_scroll.R
Created December 16, 2025 14:18
Script para manejar un navegador con R y hacer que se desplace por una página
# script para manejar un navegador con R y hacer que se desplace por una página
library(RSelenium)
# crear driver para controlar navegador
driver <- rsDriver(browser = "firefox",
port = 4560L, verbose = F,
chromever = NULL, phantomver = NULL)
remote <- driver$client