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(XML) | |
library(httr) | |
library(stringr) | |
pantone_cotd <- function(cotd_url = "https://www.pantone.com/pages/colorstrology/colorstrology.aspx") { | |
# have to fake a real user agent to get the color | |
agent <- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.78.2 (KHTML, like Gecko) Version/7.0.6 Safari/537.78.2" | |
try(pantone <- GET(cotd_url, user_agent(agent))) |
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(XML) | |
library(httr) | |
library(rvest) | |
library(magrittr) | |
# setup connection & grab HTML the "old" way w/httr | |
freak_html <- htmlParse(content(GET("http://torrentfreak.com/top-10-most-pirated-movies-of-the-week-130304/"), as="text")) | |
# do the same the rvest way, using "html_session" since we may need connection info in some scripts | |
freak <- html_session("http://torrentfreak.com/top-10-most-pirated-movies-of-the-week-130304/") |
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(ggplot2) | |
library(ggmap) | |
vectorDestination <- function(lonlatpoint, travelvector) { | |
Rearth <- 6372795 | |
Dd <- travelvector$magnitude / Rearth | |
Cc <- travelvector$direction | |
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(rvest) | |
library(httr) | |
dem <- html_session("http://www.despair.com/demotivators.html", | |
user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.78.2 (KHTML, like Gecko) Version/7.0.6 Safari/537.78.2")) | |
quotes <- data.frame(category=dem %>% html_nodes(xpath="//div/a/h3") %>% html_text(), | |
text=dem %>% html_nodes(xpath="//div[@class='tilecontents']/p") %>% html_text(), | |
image_url=dem %>% html_nodes(xpath="//img[@class='tileimg']") %>% html_attr("src"))[-1,] |
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(rgeos) | |
library(rgdal) # needs gdal > 1.11.0 | |
library(ggplot2) | |
# map theme | |
devtools::source_gist("https://gist.github.com/hrbrmstr/33baa3a79c5cfef0f6df") | |
# adapted from http://stackoverflow.com/questions/6862742/draw-a-circle-with-ggplot2 | |
# computes a circle from a given diameter. we add "id" so we can have one big | |
# data frame and group them for plotting |
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
#include <Rcpp.h> | |
#include <arpa/inet.h> | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <netdb.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
using namespace Rcpp ; |
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(reshape2) | |
library(ggplot2) | |
library(scales) | |
library(RColorBrewer) | |
dat <- read.table(text="Crime Frequently Occassionally Rarely_Never Does_not_apply rank | |
Credit_card_hacked 41 28 29 2 1 | |
Computer_smartphone_hacked 34 28 35 4 2 | |
Home_burglarized_not_present 18 27 55 1 3 | |
Car_stolen_not_present 15 27 56 2 4 |
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
--- | |
title: "twee demo" | |
author: "Jenny Bryan" | |
date: "17 August, 2014" | |
output: | |
html_document: | |
toc: TRUE | |
keep_md: TRUE | |
--- |
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
doInstall <- TRUE | |
toInstall <- c("XML", "maps", "ggplot2", "sp") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
myURL <- "http://en.wikipedia.org/wiki/United_States_presidential_election,_2012" | |
allTables <- readHTMLTable(myURL) | |
str(allTables) # Look at the allTables object to find the specific table we want | |
stateTable <- allTables[[14]] # We want the 14th table in the list (maybe 13th?) |