library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 3.6.1
conditional_filter <- function(l_disp = NULL, u_disp = NULL, l_hp = NULL, u_hp = NULL) {
mtcars %>%
# tidy up mtcars
rownames_to_column() %>%
as_tibble() %>%
select(rowname, disp, hp) %>%
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
# powershell script to get latest himawari imagery as a wallpaper. | |
# either run manually or use with task scheduler (but not *too* often!) like: | |
# powershell.exe -ExecutionPolicy Bypass -NonInteractive -WindowStyle Hidden -File C:\Users\rensa\himawari-wallpaper.ps1 -wallpaperdir C:\Users\rensa\Pictures\wallpapers | |
# create a himawari subfolder, change the windows wallpaper to slideshow and point it to this subfolder | |
# remember to respect the bom's anon ftp policy! http://www.bom.gov.au/catalogue/anon-ftp.shtml | |
param ( | |
[String]$wallpaperdir = "C:\Users\Public\Pictures\wallpapers" | |
) |
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
# https://carbon.now.sh/iYHN1JgadkF76T9rXC7q | |
# parse_time_dimensions: given a numeric vector of dates or datetimes, and | |
# a character vector of the form "[units] since [epoch]", return a POSIXct | |
# vector of date-times that are parsed element-wise. useful if you have, | |
# say, a list of netcdfs with varied epochs and units. | |
# example: | |
# > test %>% mutate(target = parse_time_dimensions(n, t)) | |
# # A tibble: 3 x 3 | |
# n t target | |
# <int> <chr> <dttm> |
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
// handleJSONRequest: a generic function for ensuring that non-ok (200) | |
// responses get thrown as errors. use this after fetches and catch with a | |
// StatusBanner | |
export function handleJSONRequest(res) { | |
if (!res.ok) { | |
return res.text().then(body => { | |
throw { | |
status: res.status, | |
statusText: res.statusText, | |
message: body |
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(ggtext) | |
ggplot(mtcars) + | |
aes(x = mpg, y = hp) + | |
geom_point() + | |
labs( | |
title = 'This plot has a delightfully long title', | |
subtitle = 'And a very important message that you should definitely take to heart') + | |
scale_x_continuous(sec.axis = dup_axis()) |
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(tidyverse) | |
my_gradient <- grid::linearGradient( | |
colours = c("#020024", "#102b81", "#833ab4"), | |
stops = c(0, 0.4, 1)) | |
# works! | |
myplot <- | |
ggplot(mtcars) + |
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 script recursively transfers the contents of a folder to another | |
# (including a team/shared drive) | |
# configure it with the ids of your source and target folders below! | |
# james goldie, june 2021 | |
library(tidyverse) | |
library(googledrive) | |
library(collateral) | |
library(tictoc) |
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(tidyverse) | |
# based on {searchable} and https://stackoverflow.com/a/64931927/3246758 | |
# stats::setNames is fine too! | |
invert <- function(x) { | |
set_names(names(x), x) | |
} | |
# let's map the coded names to our friendly ones! | |
fruit <- c( |
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
# start with the rocker base | |
FROM rocker/r-ver:latest | |
# using littler, install some extra packages | |
RUN install2.r jsonlite | |
# add our script | |
COPY myprogram.r /myprogram.r | |
# myprogram.r is the entrypoint. when you run the image, ENTRYPOINT + CMD run by default... |
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
[ | |
// open r help | |
{ | |
"key": "shift+cmd+h", | |
"command": "r.helpPanel.openForSelection" | |
}, | |
// insert a magrittr pipe %>% in editor or terminal | |
{ | |
"key": "shift+cmd+m", | |
"command": "editor.action.insertSnippet", |