head(mtcars)
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(shiny) | |
library(httr) | |
# OAuth setup -------------------------------------------------------- | |
# Most OAuth applications require that you redirect to a fixed and known | |
# set of URLs. Many only allow you to redirect to a single URL: if this | |
# is the case for, you'll need to create an app for testing with a localhost | |
# url, and an app for your deployed app. |
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) | |
library(gapminder) | |
gapminder | |
gapminder <- gapminder %>% mutate(year1950 = year - 1950) | |
# Nested data ------------------------------------------------------------- | |
by_country <- gapminder %>% | |
group_by(continent, country) %>% |
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
path <- "~/Documents/ingest/readxl/inst/extdata/datasets.xlsx" | |
zip_file <- function(path) { | |
stopifnot(file.exists(path)) | |
path <- normalizePath(path) | |
contents <- utils::unzip(path, list = TRUE) | |
names(contents) <- c("path", "size", "date") | |
contents <- contents[contents$size > 0, , drop = FALSE] |
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
only_if <- function(if_false, cond, if_true) { | |
if (cond) { | |
if_true | |
} else { | |
if_false | |
} | |
} |
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(data.table) | |
dt <- data.table(x = 1:10) | |
bad_fun <- function(x) { | |
if (x > 5) | |
stop("Uhoh") | |
x * 10L | |
} | |
dt[, x := bad_fun(x), by = x] | |
dt |
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
#include <Rcpp.h> | |
using namespace Rcpp; | |
inline SEXP subset_element(SEXP x, int i) { | |
size_t n = Rf_length(x); | |
if (i < 0 || i >= n || i == NA_INTEGER) | |
stop("Invalid subscript"); | |
return VECTOR_ELT(x, i); |
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(purrr) | |
library(github) # install_github("cscheid/rgithub") | |
library(dplyr) | |
library(stringr) | |
library(magrittr) | |
# Download issues --------------------------------------------------------- | |
ctx <- interactive.login("56b637a5baffac62cad9", "8e107541ae1791259e9987d544ca568633da2ebf") | |
issues1 <- get.repository.issues("hadley", "dplyr", per_page = 100) |
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
msg <- function(..., prob = 0.25) { | |
if (runif(1) > prob) { | |
return(invisible()) | |
} | |
messages <- c(...) | |
message(sample(messages, 1)) | |
} | |
encourage <- function() { |
diamonds <- ggplot2::diamonds
pryr::object_size(diamonds)
#> 3.46 MB
diamonds2 <- transform(diamonds, price_per_carat = price / carat)
pryr::object_size(diamonds2)
#> 3.89 MB
# Size of both data frames combined