Skip to content

Instantly share code, notes, and snippets.

View jonocarroll's full-sized avatar
👨‍💻
Learning all the languages

Jonathan Carroll jonocarroll

👨‍💻
Learning all the languages
View GitHub Profile
mutate2 <- function(.data, ...) {
dots <- rlang::enquos(...)
has_tilde_lgl <- sapply(dots, function(x) {
expr <- rlang::quo_get_expr(x)
is.call(expr) && identical(expr[[1]], quote(`~`))
})
inds <- which(has_tilde_lgl)
nms <- names(dots)[inds]
exprs <- vector("list", length(inds))
for(i in seq_along(inds)) {
# Install and load required packages
install.packages("needs")
library(needs)
needs(tidyverse, magrittr, animation, pdftools, png, scales)
# Function that extracts data from Google Mobility PDFs
process_google_mobility <- function(country_code, start_date, end_date){
# Convert first page of PDF into high-res PNG
pdf_convert(paste0("https://www.gstatic.com/covid19/mobility/",end_date,"_",country_code,"_Mobility_Report_en.pdf"), format = "png", pages = 1, dpi = 300, filenames = "IMG1.png")
@rmflight
rmflight / warnings_errors.md
Last active January 15, 2020 15:01
Common messages and errors in R, and what they mean

Notice!

This gist is no longer going to be updated. Instead, check out the page at https://rmflight.github.io/rerrors/, or the GitHub project itself at https://rmflight.github.io/rerrors/

Installing packages

You don't need to do 'install.packages("tidyverse")' every time. Install is installing it on your system. You only need to do it again if you re-install R, or want a newer version. 'library()' loads it for use, and 'install.packages()' installs it to your computer.

Error in instal.packages("tidyverse") : could not find function "instal.packages

@Wikunia
Wikunia / graph_coloring_mip.jl
Created October 15, 2019 09:55
Graph Coloring MIP using JuMP
using JuMP, GLPK
function graph_coloring(;fast=true, benchmark=false)
m = Model(with_optimizer(GLPK.Optimizer, msg_lev = 3))
@variable(m, max_color, Int)
@variable(m, c[1:49,1:4], Bin)
@objective(m, Min, max_color)
@malcolmbarrett
malcolmbarrett / move_slides_to_web.R
Last active April 2, 2019 10:28
Move R Markdown HTML slides to Blogdown and Push to Web
# install.packages(c("here", "fs", "stringr", "purrr", "git2r"))
# to add invisibly in your R profile, open with usethis::edit_r_profile()
# then define it in an environment, e.g.
# .env <- new.env()
# .env$move_slides_to_web <- {function definition}
move_slides_to_web <- function(folder = NULL, index = NULL) {
if (is.null(folder)) {
fun_labels <- function(x) sprintf("<b>%s</b>", x)
ggplot() +
scale_x(breaks = c('a','b','c')) +
theme(axis.label = element_sticker(grob = fancyGrob, dictionary = fun_labels))
my_labels <- tibble(label = letters[1:3], grobs = I(lapply(1:3, fancyGrob)))
@peterdesmet
peterdesmet / CONTRIBUTING.md
Last active February 10, 2021 17:34
My CONTRIBUTING.md template for R packages. Released under CC0, so replace our_package, our_org, and maintainer_email and adapt as you see fit. 😌 For more info, see https://help.github.com/articles/setting-guidelines-for-repository-contributors

Contributing to our_package

First of all, thanks for considering contributing to our_package! 👍 It's people like you that make it rewarding for us - the project maintainers - to work on our_package. 😊

our_package is an open source project, maintained by people who care. We are not directly funded to do so.

@tjmahr
tjmahr / sort.R
Last active September 30, 2018 13:52
sorting photos
# R script for sorting the pictures in my OneDrive's camera roll folder. Photos
# in the directory are uploaded and backed up here automatically from the iOS
# OneDrive app. This script puts the photos into Year / Month subfolders.
dir <- "F:/Tristan/OneDrive/Pictures/Camera Roll"
ps <- list.files(dir, "*.(jpg|png)", full.names = TRUE)
library(exiftoolr)
library(dplyr)
@brodieG
brodieG / cran-check.R
Last active June 18, 2019 21:02
Check CRAN Results
# started with `foghorn`, but that comes with dependencies and
# slows down R startup. `browseURL` just barely slows startup,
# even if actual page is slow to load.
check_cran_old <- function(email) {
utils::browseURL(
sprintf(
"https://cran.r-project.org/web/checks/check_results_%s.html",
gsub("[^A-Za-z0-9_:.-]", "_", sub("@", "_at_", email))
) ) }
gh_migrate("YOUR_GITHUB_USERNAME", "GITHUB_REPO")
gitea_user <- function(gitea_username,
api_endpoint = Sys.getenv("GITEA_BASE_URL"),
gitea_token = Sys.getenv("GITEA_PAT")) {
require("httr", quietly = TRUE)
require("jsonlite", quietly = TRUE)
httr::GET(