Skip to content

Instantly share code, notes, and snippets.

---
title: "Using Gensim in R"
author: "Adam Lauretig"
date: "3/17/2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
@tjvananne
tjvananne / process GloVe pre-trained word vector.R
Created May 4, 2017 14:45
How to read and process a downloaded pre-trained GloVe word vector (turn it into a data.frame) in base R
#' A word vector is a giant matrix of words, and each word contains a numeric array that represents the semantic
#' meaning of that word. This is useful so we can discover relationships and analogies between words programmatically.
#' The classic example is "king" minus "man" plus "woman" is most similar to "queen"
# function definition --------------------------------------------------------------------------
# input .txt file, exports list of list of values and character vector of names (words)
proc_pretrained_vec <- function(p_vec) {
@hrbrmstr
hrbrmstr / do_rpt.r
Last active March 16, 2023 21:51
parallel, parameterized knitr reports
library(doParallel)
rpts <- list(list(out="one.html", params=list(some_var="One")),
list(out="two.html", params=list(some_var="Two")),
list(out="three.html", params=list(some_var="Three")),
list(out="four.html", params=list(some_var="Four")))
do_rpt <- function(r) {
require(rmarkdown)
@klmr
klmr / sys.r
Created February 18, 2015 17:04
A command line script wrapper module for R
# Command line tools don’t want to clutter their output with unnecessary noise.
library = function (...)
suppressMessages(base::library(...))
#' The command line arguments
args = commandArgs(trailingOnly = TRUE)
#' The name of the script
#'
#' @note If the script was invoked interactively, this is the empty string.
'''
@author Michael J Bommarito II
@date Mar 2, 2010
This file can determine the average pairwise stability for
a dynamic graph. Growing graphs, constant vertex count graphs, and
even graphs with deleted vertices are supported.
It supports the following methods:
* betweenness