library(magrittr)
library(dplyr)
library(stringr)
df <- mtcars; df$car <- rownames(df)
df %>%
mutate(make = str_extract(car, "^[A-Za-z]+\\b")) %>%
group_by(make) %>%
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
--- | |
title: "dyEvent Example" | |
output: | |
html_document: | |
css: style.css | |
--- | |
```{r setup, echo = FALSE, warning = FALSE, message = FALSE} | |
library(xts) | |
library(dygraphs) |
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
suppressMessages({ | |
# Preamble ======================================== | |
# ======== Web Scraping =========================== | |
library(rvest) # install.packages('rvest') | |
library(magrittr) | |
# ======== I/O ==================================== | |
library(httr) # install.packages('httr') | |
}) | |
html <- read_html("https://wikipedia.org") |
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
## Script for scraping Wikipedia for data to use with the geom_flag() prototype | |
## CONTACT: Mikhail Popov (@bearloga // mikhail[at]mpopov[dot]com) | |
## URL: https://gist.github.com/bearloga/519a701a6a9bc7c3ba9f | |
# install.packages("import") | |
library(rvest) # install.packages("rvest") | |
library(magrittr) | |
import::from(dplyr, mutate, select, keep_where = filter, left_join, distinct) |
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
your_handle <- "bearloga" | |
# Note: must be logged in to twitter to view your own or anyone's list of followers | |
library(magrittr) # install.packages('magrittr') | |
library(rvest) # install.packages('rvest') | |
library(RSelenium) # install.packages('RSelenium') | |
# Scrolling solution by NicE (http://stackoverflow.com/a/29965233/1091835): | |
checkForServer() | |
startServer() |
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
--- | |
title: "Interactive Presentations" | |
author: "Mikhail Popov (@bearloga)" | |
date: "December 4, 2015" | |
output: ioslides_presentation | |
runtime: shiny | |
--- | |
## Reduce Demo |
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
#' Manual classification of observations | |
#' | |
#' \code{classify} launches a Shiny app to manually classify a subset of observations. | |
#' | |
#' @param x A character vector. | |
#' @param btn_labels A character vector of length 2 corresponding to 0 and 1. | |
#' @return A vector of 0/1 for each element in \code{x}. | |
#' @export | |
#' @examples \dontrun{ | |
#' foo <- sprintf('%s (%.2f miles per gallon)', rownames(mtcars), mtcars$mpg) |
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 <- 20 | |
time_pants <- 15 # seconds | |
# Average human swimming speed: 2 miles per hour | |
speed_avg <- birk::conv_unit(2, "mph", "m_per_sec") # install.packages('birk') | |
perc <- seq(0.25, 0.95, 0.01) | |
speed_slow <- speed_avg * perc | |
plot(perc * 100, (d / speed_slow)/60, type = "l", las = 1, lwd = 2, | |
xlab = "Speed in pants as % of average speed (2 mph ~ 0.89 m/s). In other words, how much the pants slow you down.", |
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(shape) # install.packages('shape') | |
magic_8ball <- function(x = c("yes","no")) { | |
greys <- greycol(50, interval = c(0, 1)) | |
colours <- shadepalette("#000079", "blue", n = 20) | |
emptyplot(xlim = c(-5, 5), ylim = c(-5, 5), col = "white", frame.plot = FALSE) | |
filledellipse(rx1 = 4.9, ry1 = 4.9, col = "black") | |
filledellipse(rx1 = 2, ry1 = 3.5, col = greys[2:50], angle = -45, dr = .1, mid = c(-2, 2)) | |
filledellipse(rx1 = 0.25, ry1 = 0.25, col = "white", mid = c(-2, 2)) | |
filledellipse(rx1 = 2.8, ry1 = 2.8, col = "white") |
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
# devtools::install_github("RcppCore/Rcpp") | |
# devtools::install_github("hadley/xml2") | |
# devtools::install_github("hadley/rvest") | |
# devtools::install_github("metacran/crandb") | |
# devtools::install_github('ironholds/practice') | |
# install.packages('dplyr') | |
library(rvest); library(crandb) | |
get_licensing_for_task <- function(task_url) { |