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
# | |
# This is a Shiny web application. You can run the application by clicking | |
# the 'Run App' button above. | |
# | |
# Find out more about building applications with Shiny here: | |
# | |
# http://shiny.rstudio.com/ | |
# | |
library(shiny) |
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
call <- substitute(ifelse(v == 1, | |
"banana", | |
ifelse(v == 2, | |
2, | |
NA)) | |
) | |
parse_ifelse <- function(call) { | |
if (deparse(call[[3]][[1]]) == "ifelse") { | |
top_call <- deparse(call[[2]]) |
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
tbl.mock_db <- function(src, name, ...) { | |
return(src[[name]]) | |
} | |
new_mock_db <-function(path) { | |
files <- list.files(path, full.names = TRUE) | |
con <- purrr::map(files, ~readr::read_csv(., col_types = classes[[basename(.)]])) | |
names(con) <- gsub(".csv$", "", basename(files)) | |
class(con) <- c("mock_db", "list") |
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
releasePackages <- function() { | |
dir.create("builds") | |
on.exit(unlink("builds", recursive = TRUE)) | |
if (repository_head()$name != "master") { | |
stop("You can only release the master branch. Merge your changes into master before releasing.") | |
} | |
repo <- gitPath("repo") | |
released <- readRDS(file.path(repo, "src", "contrib", "PACKAGES.rds")) |
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
match_vector <- function(vec) { | |
name <- deparse(substitute(vec)) | |
length <- length(vec) | |
if (length < 10) { | |
identity_test <- glue::glue("expect_equal({name}, c(", | |
paste0(vec, collapse = ", "), | |
")") | |
} | |
expectations <- c( | |
glue::glue("expect_is({name}, 'vector')"), |
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
library(tidyverse) | |
add <- function(...){ | |
args <- eval(substitute(alist(...))) | |
args <- replaceMissingWithZero(args) | |
args %>% purrr::reduce(sum) | |
} | |
replaceMissingWithZero <- function(l){ | |
out <- lapply(l, function(x){ | |
if (rlang::is_missing(x)) { |
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
> test_df6 <- create_test_df(cols=4, rows=40, levels_per_var= 6) # See appendix for 'create_test_df' | |
> g_test_df6 <- group_by(test_df6, a, b, c) | |
> | |
> base_split <- function(df)split(test_df6 , test_df6[, c('a', 'b', 'c')]) | |
> | |
> microbenchmark::microbenchmark( | |
+ base_split(test_df6), | |
+ split(g_test_df6) | |
+ ) | |
#Unit: milliseconds |
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
str <- "asdfasdf" | |
char <- data_frame( | |
letters = unlist(strsplit(str, "")), | |
skip = FALSE) | |
uniques <- c() | |
for (q in nchar(str):1) { | |
for (i in 1:(nchar(str) - q + 1)) { | |
start <- i | |
end <- i + q - 1 | |
if (all( char$skip[start:end])) { |
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
basic_output <- structure(list(name = "new_var", derivation = structure(list( | |
`function` = "case", args = list(structure(list(column = structure(1:3, class = "AsIs"), | |
type = structure(list(value = structure(list(class = "categorical", | |
categories = list(structure(list(id = 1L, name = "one", | |
numeric_value = NULL, missing = FALSE), .Names = c("id", | |
"name", "numeric_value", "missing")), structure(list( | |
id = 2L, name = "two", numeric_value = NULL, | |
missing = FALSE), .Names = c("id", "name", "numeric_value", | |
"missing")), structure(list(id = 3L, name = "three", | |
numeric_value = NULL, missing = FALSE), .Names = c("id", |
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
`%d%` <- function(vars, list){ | |
for(i in vars){ | |
assign(i, list[[i]], envir = .GlobalEnv) | |
} | |
} | |
c("mpg", "cyl") %d% mtcars | |
test_list = list(cars = mtcars, | |
numbers = 1:500, |