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
#' @param packages An optional vector of Campus Labs packages to install. | |
#' @param pattern An optional grep pattern of campus labs packages to install. | |
install_cl <- function(packages = NULL, pattern = '.', ...){ | |
try_install_cran <- function(package){ | |
if (!require(package, character.only = TRUE, quietly = TRUE)) { | |
message(sprintf('The "%s" package is missing; do you want me to install it?', package)) | |
ans <- menu(c("Yes", "No")) | |
if (ans == "2") { |
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
if (!require("pacman")) install.packages("pacman") | |
pacman::p_load(udpipe, BTM) | |
data("brussels_reviews_anno", package = "udpipe") | |
## Get and load the udpipe model | |
engmod <- udpipe_download_model(language = "english", udpipe_model_repo = "bnosac/udpipe.models.ud") | |
ud_engmod <- udpipe_load_model(engmod$file_model) | |
## Annotate the text data and merge back together | |
nr <- nrow(sentimentr::presidential_debates_2012) |
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
pacman::p_load(venneuler, tidyverse, ggforce) | |
## Make some fake data | |
set.seed(10) | |
dat <- data.frame( | |
Person = paste0('Person_', 1:10), | |
setNames(as.data.frame(matrix(rbinom(50, size = 1, prob=c(1/(1:5))), ncol = 5)), paste0('Attribute_', 1:5)), | |
stringsAsFactors = FALSE | |
) |
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(tidyverse) | |
map <- data_frame( | |
ins = c(LETTERS, letters), | |
outs = c(rev(LETTERS), rev(letters)) | |
) | |
map | |
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
min_max <- function(x, ...) { | |
m <- min(x, na.rm = TRUE) | |
(x - m)/(max(x, na.rm = TRUE) - m) | |
} | |
standardization <- function(x, ...) { | |
if (length(stats::na.omit(unique(x))) > 1) { | |
scale(x) | |
} else { |
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
## Taken from: http://news.mrdwab.com/install_github.R | |
## source("https://gist.githubusercontent.com/trinker/8a385892fac7d14a1f861f61394a2621/raw/95bdc672c632eff8dcfcd1f19233a0ed3cf85045/install_github.R") | |
## install_github("trinker/sentimentr") | |
#' install_github installs R packages directly from GitHub | |
#' | |
#' install_github is a very lightweight function with no dependencies | |
#' that installs R packages from GitHub. | |
#' |
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
fuzzy_map <- function(x, y, distance = 'cosine', cutoff = .40, | |
remove = c('the', 'a', 'an', 'at', 'of', 'in', '-', ' - CL', ' - OS'), | |
substitution = data.frame( | |
pattern = c('univ\\.', '\\bst\\.', '\\bmt\\.', '&'), | |
replacement = c('university', 'saint', 'mount', ' and '), | |
stringsAsFactors = FALSE | |
), | |
ngrams = 1, # choose 1 or 2 (2 is 2 words) | |
downweight.words = c('suny', 'cuny', 'college', 'university', 'state'), | |
# words that are less important - make smaller to make the words LESS important |
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
# Portraits |
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
tell_it_like_it_is <- function(){ | |
message <- paste0( | |
sprintf(cow, sample(mess, 1)), | |
"\n\n\n\n" | |
) | |
cat(message) | |
} | |
cow <- "\n ---------------- \n%s! \n ----------------- \n \\ ^__^ \n \\ (oo)\\ ________ \n (__)\\ )\\ /\\ \n ||------w|\n || ||" |
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
## Originally taken from: https://juliasilge.github.io/ibm-ai-day/slides.html#1 | |
if (!require("pacman")) install.packages("pacman") | |
pacman::p_load(tidyverse, gutenbergr) | |
## Scrape known books | |
titles <- c( | |
"Twenty Thousand Leagues under the Sea", | |
"The War of the Worlds", | |
"Pride and Prejudice", |