library(tidyverse)
mock_data <- tribble(
~park_name, ~count_2015,
"DISNEY_ANIMAL_KINGDOM", 10262808.79,
"DISNEY_CALIFORNIA_ADVENTURE", 7859777.858,
"DISNEY_HOLLYWOOD_STUDIOS", 10161975.17,
"DISNEYLAND", 15850608.32,
"DISNEYLAND_PARIS", 11303153.4,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# taken from https://www.r-bloggers.com/list-of-user-installed-r-packages-and-their-versions/ | |
ip <- as.data.frame(installed.packages()[,c(1,3:4)]) | |
rownames(ip) <- NULL | |
ip <- ip[is.na(ip$Priority),1:2,drop=FALSE] | |
write.csv(ip, "r_package_list.csv") | |
print(ip, row.names=FALSE) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f2 <- function(a, b, ...) { | |
a * 10 | |
} | |
f2(10, stop("This is an error!")) | |
objs <- mget(ls("package:base"), inherits = TRUE) | |
funs <- Filter(is.function, objs) | |
is_not_primitive <- function(x){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# find the names in one but not the other | |
# names(dat_dist)[((names(dat_dist) %in% names(dat_dist_aed)) == FALSE)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is taken from Amy Whitehead's great blog: https://amywhiteheadresearch.wordpress.com/2016/12/01/santas-little-helper/ | |
SantasLittleHelper <- function(myFrame,guestList,conflictCols = NULL){ | |
myTest <- TRUE | |
nElves <- 0 | |
while (myTest == TRUE){ | |
myOut <- data.frame(gifter = myFrame[,guestList], | |
giftee = sample(myFrame[,guestList], | |
replace = FALSE, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
# running | |
## Requires package 'openNLPmodels.en' from the repository at | |
## <http://datacube.wu.ac.at>. | |
# install.packages("openNLPmodels.en", | |
# repos = "http://datacube.wu.ac.at/", | |
# type = "source") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matrix_to_df_firstline_header <- function(mat){ | |
requireNamespace("purrr") | |
mat %>% | |
## cut columns into lists | |
apply(2, function(s) list(s)) %>% | |
flatten %>% | |
map(flatten_chr) %>% | |
## set names to the first element of the list | |
{set_names(x = map(., ~ .x[-1]), |
library(magrittr)
extract_bibtex <- function(x){
purrr::map(x,
.f = citation) %>%
purrr::map(toBibtex)
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Nick’s R Style Guide" | |
author: "Nicholas Tierney" | |
date: "12 September 2016" | |
output: html_document | |
--- | |
I've decided to have a go at documenting my R Coding style, so that I can point at it when I want something done a certain way, but also so that I can better work out exactly what it is I prefer, and why. | |
This is based off of [Hadley Wickham's style guide](), with a few of my own additions regarding whitespace. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# combine pdfs into a single pdf. | |
# credit to noam ross and Thomas Leepers for this | |
tabulizer::merge_pdfs(c('in1.pdf', 'in2.pdf'), 'out.pdf') |