Skip to content

Instantly share code, notes, and snippets.

View ateucher's full-sized avatar

Andy Teucher ateucher

View GitHub Profile
library(ggplot2)
library(viridis)
#> Loading required package: viridisLite

my_data <- data.frame(val = rnorm(15), 
                      cat = rep(letters[1:5], 3), 
                      x = 1:15)

my_viridis_scale &lt;- scale_color_viridis(discrete = TRUE, 
@ateucher
ateucher / RStudio_View_HOME.md
Last active January 4, 2018 22:13
Slow RStudio View() on PC with HOME drive on a network

Using View() is very slow - RStudio v1.1.336 on Windows 7 in an enterprise environment

In RStudio View(iris) is very slow - it locks up RStudio for ~5-10s or more. I have no idea why this difference exists.

I ran the following to find out my HOME directory:

$ echo $HOME

This returns /h/ - my Home drive on the network

@ateucher
ateucher / bec_leaflet.R
Created September 14, 2017 00:04
BC WMS in R Leaflet
library(leaflet)
leaflet() %>% addTiles() %>%
setView(-127, 52, 6) %>%
addWMSTiles("https://openmaps.gov.bc.ca/geo/pub/WHSE_FOREST_VEGETATION.BEC_BIOGEOCLIMATIC_ZONE_2M_SPG/ows",
layers = "pub:WHSE_FOREST_VEGETATION.BEC_BIOGEOCLIMATIC_ZONE_2M_SPG",
options = WMSTileOptions(
format = "image/png",
transparent=TRUE,
styles = "BEC_Cartographic_Zones_2M_Colour_Themed"))
@ateucher
ateucher / git-email-prompt.sh
Created September 19, 2017 17:48 — forked from depressiveRobot/git-email-prompt.sh
prompt for email address to use for current git repository
#!/bin/bash
# bash prompt which asks for email address
# to configure for current git repository
# set your available emails
MAILS=([email protected] [email protected] [email protected])
# prompt for email
echo
@ateucher
ateucher / git-function.sh
Last active September 19, 2017 17:53 — forked from depressiveRobot/git-function.sh
bash function to override git init/clone commands
function git() {
for i do
lastArgument=$i # last argument can be the directory or the repository url
done
command git $@
if [[ $? -eq 0 ]] # only show prompt if git command was successful
then
@ateucher
ateucher / setup.sh
Created September 20, 2017 20:00 — forked from smnorris/setup.sh
# install gdal, python, postgresql/postgis on Ubuntu 16.04
# install dependencies
sudo apt install unzip
sudo apt-get update
sudo apt-get install python-pip
sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update
sudo apt-get install gdal-bin libgdal-dev
pip install --upgrade pip
@ateucher
ateucher / geom_sf_slow_with_quartz.md
Last active January 27, 2019 18:59
geom_sf very slow with large sf objects using Mac OS quartz graphic device

I am on a Mac (2016 MBP 15" with 16GB memory) and am testing out the development version of ggplot2 with sf plotting support.

Overall I am loving it, but I am finding geom_sf to be very slow when plotting larger sf polygons objects. I think I've narrowed it down to the quartz graphics device, which is much slower than X11 on these large objects (however quartz produces nicer graphics than X11).

I would be happy to just use X11 but I do like having plots appear in the plot pane in RStudio, and I believe the RStudio Graphics Device uses quartz on Mac OS and I don't think there's a way to change that. So I'm not sure if this is really a ggplot2/sf issue or if it's a Mac quartz issue... or possibly even an RStudio issue, but I thought I would post it here first to see if others are experiencing the same thing.

I also did the same comparison with sf's plot method - there is still a large difference between X11 and quartz, however overall it is faster than ggplot2::geom_sf.

Inte

@ateucher
ateucher / advent_of_code_day_1.R
Last active December 2, 2017 04:26
Advent of Code
test_input <- "8231753674683997878179259195565332579493378483264978184143341284379682788518559178822225126625428318115396632681141871952894291898364781898929292614792884883249356728741993224889167928232261325123447569829932951268292953928766755779761837993812528527484487298117739869189415599461746944992651752768158611996715467871381527675219481185217357632445748912726487669881876129192932995282777848496561259839781188719233951619188388532698519298142112853776942545211859134185231768952888462471642851588368445761489225786919778983848113833773768236969923939838755997989537648222217996381757542964844337285428654375499359997792679256881378967852376848812795761118139288152799921176874256377615952758268844139579622754965461884862647423491918913628848748756595463191585555385849335742224855473769411212376446591654846168189278959857681336724221434846946124915271196433144335482787432683848594487648477532498952572515118864475621828118274911298396748213136426357769991314661642612786847135485969889237193822718111269561741
library(sf)
#> Linking to GEOS 3.6.2, GDAL 2.2.3, proj.4 4.9.3
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':