Skip to content

Instantly share code, notes, and snippets.

View jhollist's full-sized avatar

Jeffrey W Hollister jhollist

View GitHub Profile
@djhocking
djhocking / dplyr-select-names.R
Last active February 28, 2022 19:08
Select columns by vector of names using dplyr
one <- seq(1:10)
two <- rnorm(10)
three <- runif(10, 1, 2)
four <- -10:-1
df <- data.frame(one, two, three)
df2 <- data.frame(one, two, three, four)
str(df)
@jennybc
jennybc / 2014-10-12_stop-working-directory-insanity.md
Last active September 23, 2022 04:43
Stop the working directory insanity

There are packages for this now!

2017-08-03: Since I wrote this in 2014, the universe, specifically Kirill Müller (https://github.com/krlmlr), has provided better solutions to this problem. I now recommend that you use one of these two packages:

  • rprojroot: This is the main package with functions to help you express paths in a way that will "just work" when developing interactively in an RStudio Project and when you render your file.
  • here: A lightweight wrapper around rprojroot that anticipates the most likely scenario: you want to write paths relative to the top-level directory, defined as an RStudio project or Git repo. TRY THIS FIRST.

I love these packages so much I wrote an ode to here.

I use these packages now instead of what I describe below. I'll leave this gist up for historical interest. 😆

@jennybc
jennybc / 2014-09-18_verbatim-r-chunks-in rmd.rmd
Created September 19, 2014 05:57
How to get verbatim R chunks in R markdown. Again. Writing it down now.
---
title: "Get verbatim R chunks in R Markdown"
author: "Jenny Bryan"
date: "18 September, 2014"
output:
html_document:
keep_md: TRUE
---
My periodic revisitation of "how can I include a verbatim R chunk in `.rmd`"? This time I am writing it down! Various proposed solutions:
@noamross
noamross / get_peerj_subject_dois.R
Created June 12, 2014 11:54
Grab DOIs of all PeerJ articles from a subject area
#Get DOIs for subject area from PeerJ
library(httr)
library(plyr)
#JSON for Ecology articles (paginated):
ecol_url = "https://peerj.com/articles/index.json?subject=1100"
dois = list()
repeat {

Install alm package from CRAN

install.packages("alm")
library(alm)

Get metrics on a DOI, specifying info=history gives you the detailed data instead of totals. Note that counter is PLOS's views (includes page views of html, downloads of XML and PDF).

@hadley
hadley / curriculum.md
Created September 27, 2013 20:24
My first stab at a basic R programming curriculum. I think teaching just these topics without overall motivating examples would be extremely boring, but if you're a self-taught R user, this might be useful to help spot your gaps.

Notes:

  • I've tried to break up in to separate pieces, but it's not always possible: e.g. knowledge of data structures and subsetting are tidy intertwined.

  • Level of Bloom's taxonomy listed in square brackets, e.g. http://bit.ly/15gqPEx. Few categories currently assess components higher in the taxonomy.

Programming R curriculum

Data structures

@wch
wch / server.r
Last active September 8, 2023 20:25
Shiny example: dynamic input fields
data_sets <- c("mtcars", "morley", "rock")
shinyServer(function(input, output) {
# Drop-down selection box for which data set
output$choose_dataset <- renderUI({
selectInput("dataset", "Data set", as.list(data_sets))
})
# Check boxes