Skip to content

Instantly share code, notes, and snippets.

View ColinFay's full-sized avatar
🦷
Because why not

Colin Fay ColinFay

🦷
Because why not
View GitHub Profile
@ColinFay
ColinFay / breizh-data-tweets.R
Created October 25, 2017 20:21
Breizh Data Day Tweets
library(tidyverse)
library(rtweet)
library(proustr)
library(tidytext)
bdd <- search_tweets("#BreizhDataDay", n = 3000)
bdd_day <- bdd %>%
filter(created_at < "2017-10-20 00:00:00", created_at > "2017-10-18 23:59:59")
@ColinFay
ColinFay / networks_bdd.R
Created November 18, 2017 18:04
Network Breizh Data Day
library(tidyverse)
library(ggraph)
library(igraph)
library(tidytext)
library(proustr)
bdd <- read.csv("breizhdataday.csv", stringsAsFactors = FALSE)
sw <- data.frame(word = c(as.character(proust_stopwords()$word),
"https","rt", "d'une", "t.co"))
library(purrr)
library(tidystringdist)
(comb <- tidy_comb_all(names(airquality)))
pmap(comb, ~ cor.test(airquality[[.x]], airquality[[.y]])) %>%
map_df(broom::tidy) %>%
cbind(comb, .)
library(tidyverse)
library(rlang)
library(glue)
library(stringr)
small_iris <- slice(iris, 1)
set_names(small_iris, ~ glue("{.x}_small"))
set_names(small_iris, ~ tolower(.x))
set_names(small_iris, ~ str_replace_all(.x, "\\.", "_"))
set_names(small_iris, ~ str_replace_all(.x, "\\.", "_") %>% tolower())
library(tidyverse)
files <- list.files("../open-data/", pattern = "^2017", full.names = TRUE)
full <- map_df(files, read_csv)
dplyr::glimpse(full)
# With names
files <- list.files("../open-data/", pattern = "^2017", full.names = TRUE) %>%
set_names(basename(.))
full <- map_df(files, read_csv, .id = "file")
library(purrr)
pos_log <- possibly(log, otherwise = NA)
l <- list(1,2,3, "a", 4, "b")
map(l, pos_log) %>% discard(is.na)
library(purrr)
l <- list(list(1:10, 1:20), list(20:30, 40:50))
modify_depth(l, 2, ~ append(.x, sum(.x)))
# Classic character vector
paste0("as",".","numeric")
# getting a function
get(paste0("as",".","numeric"))
# getting and running a function
get(paste0("as",".","numeric"))("1")
# With objects
# Make a function sleep
sleepy <- function(fun, sleep){
function(...){
Sys.sleep(sleep)
fun(...)
}
}
sleep_print <- sleepy(print, 2)
snippet module
${1:name}UI <- function(id){
ns <- NS(id)
tagList(
)
}
${1:name} <- function(input, output, session){