Skip to content

Instantly share code, notes, and snippets.

:bowtie:
Just typin' R code

Jonathan Carroll jonocarroll

:bowtie:
Just typin' R code
Block or report user

Report or block jonocarroll

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am jonocarroll on github.

  • I am jonocarroll (https://keybase.io/jonocarroll) on keybase.

  • I have a public key ASBY3mLwKW3JR6kHm4Pb0RN9EJIp6G3X8nD9SJMhylURGAo

@jonocarroll
jonocarroll / as.data.frame.matrix_diff.R
Last active Apr 20, 2019
Differences in as.data.frame.matrix between R 3.4.3 and R 3.5.3
View as.data.frame.matrix_diff.R
## create a copy of mtcars
m <- mtcars
## set every other value of cyl to NA
m$cyl <- m$cyl[c(TRUE, NA)]
## show a table of cyl vs am
table(m$cyl, m$am, useNA = "always")
# 0 1 <NA>
# 4 2 3 0
View threed_rotate_cube.R
library(threed)
library(dplyr)
library(gganimate)
library(ggplot2)
angles <- tail(seq(0, pi/2, length.out = 15), -1)
camera_to_world <- threed::look_at_matrix(eye = c(1.5, 1.75, 4), at = c(0, 0, 0))
objlist <- vector("list", length(angles))
@jonocarroll
jonocarroll / image_as_xaxis_latex.R
Created Oct 16, 2018
images as xaxis in R via LaTeX
View image_as_xaxis_latex.R
library(rvest)
## GDP per capita, top 11 countries
n_countries <- 11
url <- "https://en.wikipedia.org/wiki/List_of_countries_by_GDP_(nominal)_per_capita"
html <- read_html(url)
gdppc <- html_table(html_nodes(html, "table")[3])[[1]][1:n_countries, ]
## clean up; remove non-ASCII and perform type conversions
gdppc$Country <- gsub("Â ", "", gdppc$Country)
View tikz_image_x_axis.R
## flags borrowed from
## http://flagpedia.net/
## use LaTeX tikzDevice to render images as x-axis labels
## based on baptiste: https://gist.github.com/baptiste/9505ff4f54b31d1d7149e435faf295f9
library(tikzDevice)
library(ggplot2)
options(tikzLatexPackages = c(getOption("tikzLatexPackages"), "\\usepackage{graphicx}\n"))
@jonocarroll
jonocarroll / PDFanimation.Rmd
Created Oct 8, 2018
PDF Animations in RMarkdown
View PDFanimation.Rmd
---
title: "Test Animation in PDF"
author: "Jonathan Carroll"
date: "09/10/2018"
output: pdf_document
header-includes:
- \usepackage[final,autoplay]{animate}
---
```{r setup, include=FALSE}
@jonocarroll
jonocarroll / plus_character.R
Last active Oct 4, 2018
Python/Javascript String Concatenation in R
View plus_character.R
`+` <- function(e1, e2) {
## unary
if (missing(e2)) return(e1)
if (!is.na(suppressWarnings(as.numeric(e1))) & !is.na(suppressWarnings(as.numeric(e2)))) {
## both arguments numeric-like but characters
return(base::`+`(as.numeric(e1), as.numeric(e2)))
} else if ((is.character(e1) & is.na(suppressWarnings(as.numeric(e1)))) |
(is.character(e2) & is.na(suppressWarnings(as.numeric(e2))))) {
## at least one true character
return(paste0(e1, e2))
View datasauRus_gganimate.R
# modified from https://gist.github.com/sa-lee/c271b47d8065412d3d42c1ad8e63048d
library(datasauRus)
library(gganimate)
library(magrittr)
p <- datasaurus_dozen %>%
ggplot() +
geom_point(aes(x = x, y = y), col = "steelblue") +
theme(legend.position = 'none',
aspect.ratio = 1,
You can’t perform that action at this time.