Skip to content

Instantly share code, notes, and snippets.

View JohnCoene's full-sized avatar
🍰
Cake!

John Coene JohnCoene

🍰
Cake!
View GitHub Profile
@JohnCoene
JohnCoene / ropenlp
Created November 10, 2017 21:12
R & openNLP
library(rJava)
library(NLP)
library(openNLP)
s <- "The UK has two weeks to clarify key issues or make concessions if progress is to be made in Brexit talks, the bloc's chief negotiator has said.
Michel Barnier was speaking after meeting the Brexit secretary for talks on citizens' rights, the Irish border, and the UK's 'divorce bill'.
David Davis said it was time for both sides 'to work to find solutions'. Before the talks, Theresa May said she wanted the UK's exit date set in law, and warned MPs not to block Brexit.Speaking at a press conference in Brussels, Mr Barnier suggested Britain would have to clarify its position in the next fortnight on what it would pay to settle its obligations to the EU if the talks were to have achieved 'sufficient progress' ahead of December's European Council meeting.
'It is just a matter of settling accounts as in any separation,' Mr Barnier said.Mr Barnier also said both sides had to work towards an 'objective interpretation' of Prime Minister Theresa May's pledge that no m
@JohnCoene
JohnCoene / gltf.R
Last active January 18, 2020 14:28
aframer models
library(aframer)
library(aextras)
embed_aframe(
a_scene(
a_dependency(),
aextras_dependency(),
a_assets(
a_primitive(
"asset-item",
@JohnCoene
JohnCoene / triangle.R
Last active December 21, 2018 23:35
Tidy Pascal's triangle
# Essentially what I want is the unique combinations of a vector of factors/characters
x <- LETTERS[1:5]
# x is of length 5
# Therefore, according to Pascal's triangle
# https://en.wikipedia.org/wiki/Pascal%27s_triangle
#
# (n * (n - 1)) / k
k <- 2
n <- length(x)
@JohnCoene
JohnCoene / saveecharst4r
Created November 30, 2018 15:21
Save echarts4r
library(echarts4r)
# create viz
e <- mtcars %>%
e_charts(mpg) %>%
e_scatter(qsec, wt)
# save as html
htmlwidgets::saveWidget(e, file = "echarts4r.html")
@JohnCoene
JohnCoene / app.R
Last active January 14, 2019 13:38
library(DT)
library(rvest)
library(dplyr)
library(shiny)
library(purrr)
library(tidytext)
library(echarts4r)
response <- httr::GET(
"https://api.weforum.org/v1/articles?page%5Bnumber%5D=2&page%5Bsize%5D=100"
@JohnCoene
JohnCoene / echarts4r_group.R
Created February 24, 2019 21:26
echarts4r multiple series
df <- data.frame(
x = LETTERS[1:5],
y = runif(5, 1, 5),
z = runif(5, 3, 7)
)
# gather the variables
df_gather <- df %>% tidyr::gather("group", "y_axis", y, z)
# plot
@JohnCoene
JohnCoene / expr.R
Last active March 11, 2019 23:51
String & expression
library(shiny)
string <- "print('from string')"
installExprFunction({print("from expression")}, "expr")
ui <- fluidPage(
verbatimTextOutput("string"),
verbatimTextOutput("expression")
)
@JohnCoene
JohnCoene / envir.R
Last active March 12, 2019 09:03
Environment var
library(magrittr)
db <- new.env(hash = TRUE)
define_vars <- function(...){
assign("my_vars", ..., envir = db)
}
print_vars <- function(){
print(
@JohnCoene
JohnCoene / qualtrics_methods.R
Created March 13, 2019 15:21
Qualtrics Ping Method Proposal
############# FUNCTIONS
#' A ping function that returns an object of say `qualtricsDemands`
#' @param ids Vector of survey ids
demand_downloads <- function(ids){
# simulate ping
pinged <- purrr::map(ids, function(x) sample(c("failure", "success"), 1))
# construct object
@JohnCoene
JohnCoene / Customised.R
Last active April 17, 2019 15:44
how to change the line width based on variables in the data
library(echarts4r)
flights <- read.csv(
paste0("https://raw.githubusercontent.com/plotly/datasets/",
"master/2011_february_aa_flight_paths.csv")
)
flights <- flights %>%
dplyr::mutate(width = scales::rescale(cnt, to = c(0, 5)))