Skip to content

Instantly share code, notes, and snippets.

View trinker's full-sized avatar

Tyler Rinker trinker

  • Kangarootime
  • Buffalo, NY
View GitHub Profile
@trinker
trinker / find_nonascii
Created December 13, 2017 03:40
Find non-ascii chars in package's data
library(pacman); library(textshape)
lapply(p_data(lexicon)$Data, function(x){
m <- eval(parse(text=x))
if (is.atomic(m)) return(sum(grepl('[^ -~]', m)))
sum(sapply(as.data.frame(m), function(y) sum(grepl('[^ -~]', y))))
}) %>%
setNames(p_data(lexicon)$Data) %>%
textshape::tidy_list()
@trinker
trinker / traverse_tree.R
Created November 26, 2017 05:09
Tree Traverse
if (!require("pacman")) install.packages("pacman")
pacman::p_load(data.tree, tidyverse)
dat <- data_frame(
OrgUnitIdentifier = c(1, 6, 72, 147, 1471, 1553, 1771, 283, 3762, 1112, 31, 4353, 9374, 2612),
Name = c(
'Main University', 'Academic Affairs', 'College of Arts & Science', 'Biology', 'Biochemistry & Molecular Bio',
'Earth Sciences', 'Environmental Studies', 'Chemistry/Physics', 'Chemistry', 'Physics', 'College of Health Sciences',
'Health Sciences', 'Occupational Therapy', 'Social Work'
@trinker
trinker / language_style_matching.R
Created November 26, 2017 03:44
language style matching
## http://faculty.wcas.northwestern.edu/eli-finkel/documents/InPress_IrelandSlatcherEastwickScissorsFinkelPennebaker_PSci.pdf
if (!require("pacman")) install.packages("pacman"); library(pacman)
p_load_current_gh('trinker/textcorpus')
p_load(tidyverse)
language_style_matching <- function(x, grouping.var, personal.pronouns, ...){
m <- termco::token_count(x, grouping.var, list(pp=unique(tolower(function.words))), keep.punctuation = FALSE, group.names = 'group')
@trinker
trinker / scraping_mwe
Created November 1, 2017 12:25
Scraping Minimal Example w/ Robots.txt Checking
if (!require("pacman")) install.packages("pacman")
pacman::p_load(robotstxt, dplyr, xml2, rvest)
path <- 'https://www.fluentu.com/blog/english/basic-english-phrases/'
paths_allowed(path)
path %>%
xml2::read_html() %>%
rvest::html_nodes('h4') %>%
@trinker
trinker / wizard_of_oz_sentiment
Last active May 5, 2020 15:06
wizzard of oz sentiment
if (!require("pacman")) install.packages("pacman")
pacman::p_load(robotstxt, dplyr, textshape, textclean, textreadr, xml2, rvest, stringi, sentimentr, magrittr, numform)
path <- 'http://www.wendyswizardofoz.com/printablescript.htm'
paths_allowed(path)
abbreviation_map <- list(
abb = c('o.s.', 'b.g.'),
rep = c('off screen', 'back ground')
)
@trinker
trinker / final.png
Created October 20, 2017 19:19 — forked from hrbrmstr/final.png
composite a footer onto a ggplot plot – highly recommend doubling h & w, res = 144 and more customizing. this was a quick hack for someone.
final.png
@trinker
trinker / final.png
Created October 20, 2017 19:19 — forked from hrbrmstr/final.png
composite a footer onto a ggplot plot – highly recommend doubling h & w, res = 144 and more customizing. this was a quick hack for someone.
final.png
@trinker
trinker / track_button_clicks
Last active August 10, 2017 12:39
Shiny: Truck Button Clicks
## reactiveValues makes a list of values that are reactive that can be altered
## by observe event. These reactives are then acted on in the server.R and
## passed back to the ui.R
library(shiny)
ui <- fluidPage(
actionButton(inputId = "clicker", label = "Next"),
textOutput("buttonval")
)
@trinker
trinker / nrc_emotions.R
Created August 3, 2017 15:39
nrc emotions analysis
## installing and loading dependencies
if (!require("pacman")) install.packages("pacman")
pacman::p_load_current_gh(
file.path('trinker', c(
"gofastr",
"textshape",
"lexicon",
"textclean",
"termco"
))
A Portrait of the Artist as a Young Man by James Joyce Chapter 1 Once upon a time and a very good time it was there was a moocow coming down along the road and this moocow that was coming down along the road met a nicens little boy named baby tuckoo His father told him that story : his father looked at him through a glass : he had a hairy face .<br><br>He was baby tuckoo .<br><br>The moocow came down the road where Betty Byrne lived : she sold lemon platt .<br><br>O , the wild rose blossoms On the little green place .<br><br>He sang that song .<br><br>That was his song .<br><br>O , the green wothe botheth .<br><br>When you wet the bed first it is warm then it gets cold .<br><br>His mother put on the oilsheet .<br><br>That had the queer smell .<br><br>His mother had a nicer smell than his father .<br><br>She played on the piano the sailor 's hornpipe for him to dance .<br><br>He danced : Tralala lala , Tralala tralaladdy , Tralala lala , Tralala lala .<br><br>Uncle Charles and Dante clapped .<br><br>They wer