Skip to content

Instantly share code, notes, and snippets.

View Robinlovelace's full-sized avatar

Robin Lovelace Robinlovelace

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Robinlovelace
Robinlovelace / 1_ubuntu_terminal_command
Last active October 23, 2023 22:31 — forked from lucasdavila/1_ubuntu_terminal_command
Installing Source Code Pro fonts in ubuntu
# to execute this gist, run the line bellow in terminal
\curl -L https://raw.github.com/gist/af96b42f98cc6cbb777d0634a6677a22/install_source_code_pro.sh | sh
t11_raw = readxl::read_excel("nat-chil-meas-prog-eng-2020-2021-tab.xlsx", sheet = "Table 11", skip = 13)
t11 = t11_raw %>%
janitor::clean_names()
# names(t11)
names(t11)[1:2] = c("class", "year")
t11_most_deprived = t11 %>%
select(class, year, prevalence_3) %>%
fill(class) %>%
filter(str_detect(string = class, pattern = "Reception|Year")) %>%
slice(-c(1:2)) %>%
---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, PBC"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
lib_dir: libs
nature:
remotes::install_cran("questionr")
#> Skipping install of 'questionr' from a cran remote, the SHA1 (0.7.0) has not changed since last install.
#> Use `force = TRUE` to force installation
library(questionr)
d = data.frame(name = c("robin", "milena"), favourite_drink = c("coffee", "tea"))
lookfor(data = d, "drink")
#> variable
#> 2 favourite_drink
# <sup>Created on 2019-03-07 by the [reprex package](https://reprex.tidyverse.org) (v0.2.1)</sup>
url_csv = "https://github.com/d3/d3-plugins/raw/master/graph/data/cities.csv"
# read-in non-spatial table:
c = readr::read_csv(url_csv)
# convert to spatial:
cs1 = sf::st_as_sf(c, coords = c("longitude", "latitude"))
download.file(url = url_csv, destfile = "cities.csv")
age4 <- c(346,81,435)
age5_19 <- c(580,420,1730)
age20_34 <- c(726,354,1321)
age35_64 <- c(1296,823,2567)
age65 <- c(2028,1112,2883)
@Robinlovelace
Robinlovelace / 10-centroid-alg.R
Created July 19, 2018 03:40
Script for teaching, part of the book Geocompuation with R, the original of which can be found here: https://github.com/Robinlovelace/geocompr/blob/master/code/10-centroid-alg.R
# Aim: take a matrix representing a convex polygon, return its centroid,
# demonstrate how algorithms work
# Pre-requisite: an input object named poly_mat with 2 columns representing
# vertices of a polygon, with 1st and last rows identical
# Step 1: create sub-triangles, set-up ------------------------------------
O = poly_mat[1, ] # create a point representing the origin
i = 2:(nrow(poly_mat) - 2)
``` r
pkgs = c("stringr", "emojifont")
if(any(!pkgs %in% installed.packages())) {
install.packages(pkgs)
}
story_original = "🍞🍻🐢😱🏥😷💊➡🥛☕💪🍅🚲🍻"
# something funny with 9th char
char_broken = stringr::str_sub(story_original, start = 9, end = 9)
emojifont::search_emoji("bottle")
#> [1] "baby_bottle"
@Robinlovelace
Robinlovelace / gifski.R
Last active May 17, 2018 09:27
Demo of using gifski (+ youtube-dl) from within R
``` r
library(future)
plan(multiprocess)
devtools::install_github("r-rust/gifski")
#> Using GitHub PAT from envvar GITHUB_PAT
#> Skipping install of 'gifski' from a github remote, the SHA1 (6f921380) has not changed since last install.
#> Use `force = TRUE` to force installation
system("pip3 install youtube-dl")
system("youtube-dl https://youtu.be/CzxeJlgePV4 -o v.mp4")
system("ffmpeg -i v.mp4 -t 00:00:03 -c copy out.mp4")