This file contains hidden or 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
snippet .arr | |
arrange(desc(${1:vars})) | |
snippet .group_sum | |
group_by(${1:vars}) %>% | |
summarize(${2:value} = ${3:expression}) %>% | |
ungroup() | |
snippet .group_mut | |
group_by(${1:vars}) %>% |
This file contains hidden or 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
# Symmetrical set-difference | |
# from: https://github.com/tidyverse/dplyr/issues/4811 | |
symdiff <- function(x, y) { | |
setdiff(union(x, y), intersect(x, y)) | |
} | |
# Inserting join | |
# from: https://github.com/tidyverse/dplyr/issues/1275 | |
insert <- function(data, insertData, by) { | |
data %>% |
This file contains hidden or 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
# What you need to know: | |
# * environments -- inheritance of definition | |
# * frames -- call reference | |
# | |
# What does that mean? | |
# * environments are inherited when a function is defined (i.e. f <- function () {}) | |
# * frames refer to where a function was called from, not where it was defined | |
i <- 1 |
This file contains hidden or 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
price_type <- c("henry_hub_spot", "future_contract_1", | |
"future_contract_2", "future_contract_3", | |
"future_contract_4") | |
make_proper_names <- function (x) { | |
stringr::str_replace_all(x, "_", " ") %>% | |
stringr::str_to_title() | |
} | |
make_proper_names(price_type) |
This file contains hidden or 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
apply_rows <- function (x, fun, ...) apply(x, 1, fun, ...) | |
apply_columns <- function (x, fun, ...) apply(x, 2, fun, ...) | |
apply_groups <- function (x, groups, fun, ...) tapply(x, groups, fun, ...) |
This file contains hidden or 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
# Produces an 'unmatched length' error | |
last_by_group <- function (x, group = NULL, order_by = NULL, default = default_missing(x)) { | |
if (is.null(group)) { | |
return(last(x, order_by = order_by, default, default)) | |
} else { | |
tapply(X = x, INDEX = group, FUN = last) | |
} | |
} |
This file contains hidden or 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
options( | |
usethis.description = list( | |
`Authors@R` = 'person("Luke", "Smith", email = "[email protected]", role = c("aut", "cre"))', | |
License = "GPL-3" | |
) | |
) |
This file contains hidden or 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_bbox_nudge_x <- function (b, i) { | |
if (length(i) == 1) { | |
b[c(1, 3)] <- b[c(1, 3)] + c(i, -i) | |
} else { | |
b[c(1, 3)] <- b[c(1, 3)] + c(i[1], i[2]) | |
} | |
b | |
} |
- [R] snippet intro -- https://jozef.io/r906-rstudio-snippets/
- [R] 11 snippets -- https://gitlab.com/jozefhajnala/gists/tree/master/rstudio/snippets
- [R] Kriging -- https://swilke-geoscience.net/post/2020-09-10-kriging_with_r/kriging/
- [R] Geospatial interpolation -- https://swilke-geoscience.net/post/spatial_interpolation/
- [R] Spatial Interpolation -- https://rspatial.org/raster/analysis/4-interpolation.html
- [R] Rayshader example -- https://gist.github.com/tylermorganwall/da117be116635e1d8dff61dbc7f9dc68
- [R] Re-center longitude -- AustralianAntarcticDivision/SOmap#34
- [R] Dot plot -- https://gist.github.com/ikashnitsky/2f3e2b2af6f50911bb775bbce6eb0fb8
- [R] Population Line Plot -- https://github.com/tylerjtran/populationLines/blob/master/populationLinesScript.R
- [JavaScript] Density Contour Matrix for Geospatial Datasets -- https://observablehq.com/@pstuffa/density-contour-matrix-for-geospatial-datasets
NewerOlder