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(dplyr) | |
library(htmlwidgets) | |
library(rpivotTable) | |
mtcars %>% | |
rpivotTable(rows = "gear", | |
cols = c("cyl", "carb"), | |
vals = "hp", | |
# Step 1. Make this line accomplish the same thing as the 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
grouply <- function(f, ...) { | |
groups <- lazyeval::lazy_dots(...) | |
function(tbl, ...) { | |
dplyr::group_by_(tbl, .dots = groups) %>% | |
f(...) %>% | |
dplyr::ungroup() | |
} | |
} |
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
# $ brew install libssh2 | |
# $ brew install libgit2 | |
## $ export CMAKE_INCLUDE_PATH="/usr/local/Cellar/libssh2/1.7.0/include" | |
## $ export CMAKE_LIBRARY_PATH="/usr/local/Cellar/libssh2/1.7.0/lib" | |
# NOTE: re: git2r: https://github.com/ropensci/git2r/issues/236 | |
install_CRAN <- function (pkg, repos = "http://cran.rstudio.com", verbose = TRUE, ...) { | |
if (pkg %in% installed.packages()) message(pkg, " is already installed") | |
else install.packages(pkg, repos = repos, verbose = verbose, ...) | |
} |
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
# | |
# Context: | |
# | |
# https://cran.r-project.org/web/packages/ensurer/vignettes/ensurer.html says: | |
# "It is also possible to use the dot, ., directly in anonymous error handlers defined directly in the call to e.g. ensure_that." | |
# | |
# I must be misunderstanding the statement above! | |
# | |
library(ensurer) |
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
eval({ | |
ensure_nonnull <- ensures_that(!is.null(.) ~ "Must not be NULL" ) | |
ensure_nonempty <- ensures_that(length(.) > 0 ~ "Must not be empty", +ensure_nonnull ) | |
ensure_finite <- ensures_that(all(is.finite(.)) ~ "Must be finite", +ensure_nonempty ) | |
ensure_positive <- ensures_that(all(. > 0) ~ "Must be positive", +ensure_finite ) | |
ensure_nonnegative <- ensures_that(all(. >= 0) ~ "Must be positive or zero", +ensure_finite ) | |
ensure_unique <- ensures_that(length(unique(.)) == 1) | |
}) | |
# Wrapped in `eval({...})` b/c otherwise RStudio will complain about syntax |
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(ensurer) # awesome | |
# Example 1 --- OK | |
groceries <- c("eggs", "bread", "milk") | |
check_that(groceries, "bread" %in% .) | |
# Example 2 --- :-( | |
# I'd really like this to work! It's quite readable. | |
# Doesn't work b/c `ensurer` (v1.1) doesn't first evaluate calls. | |
contains <- function (what) function (x) { what %in% x } |
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
#' Filter (subset) a Spatial*DataFrame object | |
#' | |
#' @param object a \code{Spatial*DataFrame} | |
#' @param ... see \link{subset} | |
#' @param .dots | |
#' | |
#' @importFrom lazyeval all_dots lazy_eval | |
#' | |
#' @return a subset of the original \code{Spatial*DataFrame} | |
#' |
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
install_from_source <- function (pkg, args = NULL, repos = "http://cran.rstudio.com", overwrite = FALSE, ...) { | |
if (!overwrite) { | |
if (pkg %in% installed.packages()) { | |
message(pkg, " is already installed") | |
return() | |
} | |
} | |
install.packages( |
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
# via https://support.rstudio.com/hc/en-us/articles/200552326-Running-RStudio-Server-with-a-Proxy | |
user nginx; | |
worker_processes 4; | |
# daemon off; | |
pid /run/nginx.pid; | |
events { | |
worker_connections 768; | |
# multi_accept on; |
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
#' (Left) join with a custom comparator | |
#' | |
#' @param left data.frame | |
#' @param right data.frame | |
#' @param by names of columns to join by | |
#' @param fun custom comparator (see examples) | |
#' | |
#' @examples | |
#' my_df <- data.frame(cyl = c(4, 4, 6, 8), vs = c(0, 1, NA, NA), foo = c("A", "B", "C", "D")) | |
#' my_fun <- function (e1, e2) (e1 == e2) | is.na(e2) |