Skip to content

Instantly share code, notes, and snippets.

View mkearney's full-sized avatar
📈
Data Sciencing

Michael W. Kearney mkearney

📈
Data Sciencing
View GitHub Profile
@mkearney
mkearney / rtweets-revenge.R
Last active April 22, 2023 02:09
Using rtweet v0.7.0 to search Twitter's standard API
#------------------------------------------------------------------------------#
# API KEYS/SECRETS
#------------------------------------------------------------------------------#
# twitter keys - these are fake replace these with your twitter keys found
# at https://developer.twitter.com/en
# be careful with these – do not share or save to cloud. use environment
# variables, follow best practices, don't be careless :)
consumer_key = "IYWxHaPxjpalssdfkj"
consumer_secret = "Cyx8OqcOtniCe63ZmaPxvvq6HvstV6PuS1AjwY9g1awnbaIUp4"
@jnolis
jnolis / 3-legged-twitter-auth.R
Last active January 19, 2020 05:23
Do 3-legged Twitter authentication for rtweet
# _____ __ __
# |__ / / /__ ____ _____ ____ ____/ /
# /_ <______/ / _ \/ __ `/ __ `/ _ \/ __ /
# ___/ /_____/ / __/ /_/ / /_/ / __/ /_/ /
# /____/ /_/\___/\__, /\__, /\___/\__,_/
# /____//____/
# RTWEET + 3-LEGGED-AUTH DEMO
# This code demonstrates how to do 3-legged authentication for Twitter
# using the {rtweet} package. Based heavily on code from Michael Kearney and Calli Gross
@mkearney
mkearney / impeachment-twitter-sentiment-plot.R
Last active October 12, 2020 20:52
Visualizing Sentiment Analysis of Tweets about the 2019 Impeachment Hearings
## install these if not already
pkgs <- c("remotes", "syuzhet", "tfse", "rtweet", "ggplot2", "dplyr", "tidyr")
if (length(pkgs <- pkgs[!pkgs %in% installed.packages("remotes")]) > 0) {
install.packages(pkgs)
}
## install from github
remotes::install_github("mkearney/dataviz")
remotes::install_github("mkearney/dict")
@mkearney
mkearney / get-congress-follows.R
Created October 31, 2019 21:53
Get all accounts followed by members of the U.S. Congress
## load rtweet and congress116
library(rtweet)
library(congress116)
## create long-version of congress116 data (and drop rows w/o screen names)
sns <- with(congress116, data.frame(
bioguide = c(bioguide, bioguide[!is.na(screen_name_personal)]),
handle = c(screen_name_official, screen_name_personal[!is.na(screen_name_personal)]),
stringsAsFactors = FALSE
))
#' Conditionally apply expressions on a data object
#'
#' @param .data Input data
#' @param condition A logical value to determine whether to use .if or .else
#' @param .if Formula or function to apply to intput data when condition is TRUE
#' @param .else Formula or function to apply to intput data when condition is FALSE
#' @return Output of appropriate .if/.else call
#' @export
#' @importFrom rlang as_closure
do_if_else <- function(.data, condition, .if, .else = identity) {
@mkearney
mkearney / tax-tweets-to-trump.R
Last active February 7, 2019 21:21
Sentiment of tax-related tweets sent to:realDonaldTrump
## install packages (from CRAN) if not already
pkgs <- c("dplyr", "rtweet", "ggplot2", "syuzhet", "ggbeeswarm", "remotes")
if (any(!pkgs %in% installed.packages())) {
install.packages(pkgs[!pkgs %in% installed.packages()])
}
## install {dataviz} theme from github
remotes::install_github("mkearney/dataviz")
## define paste function I really like rn
@mkearney
mkearney / get-gh-stars.R
Last active February 22, 2019 09:16
Get a tidy data frame of information about all of your Github stars (repos you've starred)
## install {remotes} pkg
if (!requireNamespace("remotes", quietly = TRUE)) {
install.packages("remotes")
}
## install {tfse} from github
remotes::install_github("mkearney/tfse")
## load {tfse}
library(tfse)
library(V8)
library(rvest)
library(hrbrthemes)
library(tidyverse)
ctx <- v8()
pg <- read_html("https://www.tiobe.com/tiobe-index/")
html_nodes(pg, xpath=".//script[contains(., 'series:')]") %>%
library(stats)
library(VIM)
library(mice)
library(car)
library(Hmisc)
library(dplyr)
setwd('~/R')
#import and prepare the master data.
full_golf=read.csv('full_golf_new.csv',strip.white=T,stringsAsFactors=FALSE)
@arfon
arfon / generate
Last active April 6, 2023 10:37
Let's try and generate some codemeta files.
#!/usr/bin/ruby
# For an OO language, this is distinctly procedural. Should probably fix that.
require 'json'
details = Hash.new({})
capture_params = [
{ :name => "title", :message => "Enter project name." },
{ :name => "url", :message => "Enter the URL of the project repository." },