Skip to content

Instantly share code, notes, and snippets.

View MilesMcBain's full-sized avatar

Miles McBain MilesMcBain

View GitHub Profile
@MilesMcBain
MilesMcBain / recurse_html.R
Created July 29, 2022 03:59
recurse_html.R
library(tibble)
library(purrr)
library(tidyr)
library(htmltools)
library(dplyr)
df <- tibble::tribble(
~level_1, ~level_2, ~level_3,
"coffee", "espresso", "with milk",
"coffee", "espresso", "without milk",
@MilesMcBain
MilesMcBain / bike_share_filter_rdeck.R
Created July 8, 2022 01:31
Demo of the {rdeck} feature editor with {shiny}
library(shiny)
library(rdeck)
library(sf)
sf::sf_use_s2(FALSE)
library(spData)
library(dplyr)
library(ggplot2)
bikes <-
spData::cycle_hire
@MilesMcBain
MilesMcBain / .Rprofile
Created June 29, 2022 00:08
remote .Rprofile VSCode settings
options(
vsc.rstudioapi = TRUE,
vsc.browser = "Beside",
vsc.dev.args = list(width = 1200, height = 900),
vsc.str.max.level = 2
)
@MilesMcBain
MilesMcBain / cloud_view.R
Created June 27, 2022 23:50
cloud_view()
cloud_view <- function(obj) {
withr::with_options(
list(viewer = function(url, ...) {
get_url_dir <- function(url) gsub("file://|/index.html", "", url)
server <- servr::httd(
dir = get_url_dir(url),
verbose = TRUE,
browser = FALSE
)
.vsc.browser(server$url, ...)
@MilesMcBain
MilesMcBain / base_r_travel_time_sim.R
Last active August 18, 2021 05:11
vectorised base R simulation
library(tidyverse)
do_sim <- function() {
n_locations <- 1000
n_stations <- 10
n_sources <- n_stations + n_locations
n_incidents <- 20000
n_replicates <- 100
probabilities <- seq(0.7, 1, by = 0.05)
@MilesMcBain
MilesMcBain / concat_maps.R
Last active April 15, 2021 23:52
concat_maps.R
concat_maps <- function(...) {
rdeck_maps <- list(...)
rdeck_map_names <- names(rdeck_maps)
rdeck_map_names[nzchar(rdeck_map_names) == 0] <- "Base layers"
# set up init for reduce
container <- rdeck_maps[[1]]
container$x$layers <-
map(container$x$layers, function(layer) {
layer$group_name <- rdeck_map_names[[1]]
layer$visibility_toggle <- TRUE
@MilesMcBain
MilesMcBain / example.R
Created March 12, 2021 11:25
Prepare languageserver tcp client
client <- TCPLanguageClient$new(port = 8888) #session 1
run(port = 8888) # session 2
client$start()
data <- client$fetch(blocking = TRUE)
client$handle_raw(data)
## do stuff with client
client %>% did_save(defn_file_path2)
result <- client %>% respond_document_symbol(defn_file_path2)
@MilesMcBain
MilesMcBain / crunchy.R
Last active March 5, 2021 02:08
ra30 res 9
system.time({
library(conflicted)
library(qfes)
library(tidyverse)
library(rmapshaper)
library(sf)
library(h3jsr)
library(furrr)
library(future)
library(rdeck)
@MilesMcBain
MilesMcBain / gist:8441f0a418bb4e8c6df7785f054906dd
Last active February 4, 2021 08:05
rolling_date_merge.R
library(tidyverse)
oms_db <-
tribble( ~id, ~data, ~start, ~end,
1, 1, '2020-01-01', '2020-01-04',
1, 2, '2020-01-04', '3000-01-01',
2, 1, '2020-01-01', '2020-01-04',
2, 2, '2020-01-04', '3000-01-01',
@MilesMcBain
MilesMcBain / rmd_vignette.r
Created January 17, 2021 05:15
rmd vignette
x <- vignette("dbplyr")
rstudioapi::navigateToFile(with(x, file.path(Dir, "doc", File)))