library(ggplot2)
library(tidyverse)
library(patchwork)
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, proj.4 4.9.3
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
nc_12 <- tibble::rownames_to_column(nc[1:2,], "id")
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(sf) | |
library(ggplot2) | |
do_bench <- function(n) { | |
d <- data.frame( | |
x = runif(n) * 360, | |
y = runif(n) * 180 | |
) | |
d_sf <- st_multipoint(as.matrix(d)) %>% |
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(sf) | |
# load data | |
nc <- read_sf(system.file("shape/nc.shp", package="sf")) | |
# get bbox | |
b <- st_bbox(nc) | |
# calculate tile number --------------------------- |
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(dplyr) | |
call_as_pipable <- function(g, ...) { | |
# get the current function name as string | |
fun_name <- deparse(match.call()[[1]]) | |
# remove "add_" and find the correspondent function | |
fun <- get(gsub("^add_", "", fun_name), | |
envir = asNamespace("ggplot2")) | |
g + fun(...) |
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
reprex::reprex_info() | |
#> Created by the reprex package v0.1.1.9000 on 2018-01-22 | |
library(dplyr, warn.conflicts = FALSE) | |
data("flights", package = "nycflights13") | |
microbenchmark::microbenchmark( | |
summarise_only = flights %>% | |
group_by(year, month, day, origin) %>% | |
summarise(dep_delay_avg = mean(dep_delay), |
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
# w/ purrrlyr | |
df.jp.prefs.hex %>% | |
purrrlyr::slice_rows("id") %>% | |
purrrlyr::by_slice(make_hex) %>% magrittr::use_series(.out) %>% | |
sf::st_sfc() | |
# w/ purrr | |
df.jp.prefs.hex %>% | |
split(.$id) %>% | |
purrr::map(make_hex) %>% |
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(DBI) | |
observer <- getOption("connectionObserver") | |
observer$connectionOpened(type = "HOXOM", | |
displayName = "HOXOM", | |
host = "", | |
connectCode = "", | |
disconnect = function(...) NULL, | |
listObjectTypes = function(...) list(schema = list()), | |
listObjects = function(...) list(), |
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
reprex::reprex_info() | |
#> Created by the reprex package v0.1.1.9000 on 2017-10-16 | |
library(dplyr, warn.conflicts = FALSE) | |
replace_cols1 <- function(df, cols, pos) { | |
cbind( | |
df[, 1:(pos-1), drop=FALSE], | |
cols, | |
df[, (pos+1):ncol(df), drop=FALSE] |
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
;; add load-paths | |
(add-to-list 'load-path "~/.emacs.d/elisp") | |
(require 'package) | |
;; MELPA | |
(add-to-list | |
'package-archives | |
'("melpa" . "http://melpa.org/packages/") t) |
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
f <- function(return_true = TRUE) { | |
function(return_true = return_true) { | |
if (return_true) return(TRUE) | |
FALSE | |
} | |
} | |
f() | |
#> function(return_true = return_true) { | |
#> if (return_true) return(TRUE) | |
#> FALSE |