I hereby claim:
- I am mkearney on github.
- I am kearneymw (https://keybase.io/kearneymw) on keybase.
- I have a public key ASAprxnmWoBc1OCGFVW6Lid1F4IXNx6uabYjq-hOiDx_hQo
To claim this, I am signing this object:
| ## install {remotes} pkg | |
| if (!requireNamespace("remotes", quietly = TRUE)) { | |
| install.packages("remotes") | |
| } | |
| ## install {tfse} from github | |
| remotes::install_github("mkearney/tfse") | |
| ## load {tfse} | |
| library(tfse) |
I hereby claim:
To claim this, I am signing this object:
| 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:')]") %>% |
| jlfacts <- function(dir = path.expand("~")) { | |
| if (file.exists(file.path(dir, ".jeffleekfacts.rds"))) { | |
| jlrtfacts <- readRDS(file.path(dir, ".jeffleekfacts.rds")) | |
| } else if ("rtweet" %in% install.packages()) { | |
| jlrt <- rtweet::search_tweets("\"jeff leek\"", n = 500, include_rts = FALSE) | |
| jlrtfacts <- trimws(unique(gsub("@[[:alnum:]_:]+", "", jlrt$text))) | |
| jlrtfacts <- grep("http", jlrtfacts, invert = TRUE, value = TRUE) | |
| saveRDS(jlrtfacts, path.expand(file.path("~", ".jeffleekfacts.rds"))) | |
| } else { | |
| jlrtfacts <- "jeff leek doesn't use soap; he uses rm(list = ls())." |
| #' R script from Rmarkdown file | |
| #' | |
| #' Converts Rmarkdown to R script file | |
| #' | |
| #' @param x File name of Rmd file | |
| #' @param verbose Logical indicating whether to print (cat) the | |
| #' script code. Defaults to TRUE. | |
| #' @return String with script syntax. | |
| rRMD <- function(x, verbose = TRUE) { | |
| ## read Rmd file |
| library(rtweet) | |
| ## number of iterations | |
| n <- 5 | |
| ## to do a certain task (e.g., searching for tweets on a topic), | |
| ## twitter policy says you should use one token | |
| ## so select one token | |
| token <- get_tokens() | |
| if (!"Token" %in% class(token)) { |
| library(rtweet) | |
| ## use stream_tweets() to capture an hour of tweets | |
| "wikileaks,assange,hacking,russia,putin" %>% | |
| stream_tweets( | |
| parse = FALSE, | |
| timeout = (60 * 60), | |
| file_name = "wikileaks.json") | |
| ## read and parse data | |
| rt <- parse_stream("wikileaks.json") |
| ## download dev version of rtweet (from github) | |
| install.packages("devtools") | |
| devtools::install_github("mkearney/rtweet") | |
| library(rtweet) | |
| ## search for 15k tweets using keywords | |
| ## (my goal was to explore current political opinions | |
| ## so it made sense to me to exclude retweets and | |
| ## use personal/opinion keywords, e.g., "i think") | |
| rt <- search_tweets( |
| dots <- function(...) { | |
| as.character(eval(substitute(alist(...)))) | |
| } | |
| unL <- function(x) unlist(x, use.names = FALSE) | |
| ## easy as df | |
| as.df <- function(x, ...) { | |
| vars <- dots(...) | |
| if (identical(vars, "FALSE")) { | |
| as.data.frame(x, stringsAsFactors = FALSE) |
| #' xiny | |
| #' | |
| #' Returns logical value indicating whether named | |
| #' object includes var name. Functions do the following: | |
| #' | |
| #' \itemize{ | |
| #' \item \code{\%xy\%} returns logical for each value of x | |
| #' \item \code{\%any\%} returns TRUE if y contains any of x | |
| #' \item \code{\%all\%} returns TRUE if y contains all of x | |
| #' } |