Skip to content

Instantly share code, notes, and snippets.

@njtierney
njtierney / gist:d5a877a6dc8a97f2b4a5
Last active June 3, 2019 13:27
This chunk is what I usually write at the start of most rmarkdown documents.
```{r global_options, include=FALSE, cache=FALSE}
library(knitr)
# Set basic options. You usually do not want your code, messages, warnings etc.
# to show in your actual manuscript however for the first run or two these will
# be set on.
opts_chunk$set(echo=FALSE,
warning=FALSE,
message=FALSE,
cache = TRUE,
include = FALSE,
@rmflight
rmflight / adv-r.md
Last active June 7, 2017 04:07
compiling @hadley books

In the shell:

git clone https://github.com/hadley/adv-r.git
gem install jekyll mime-types

In R:

@sebkopf
sebkopf / README.md
Last active January 22, 2025 08:35
wolfram alpha from R

Wolfram Alpha API from R

The attached code file provides an easy basic interface to the Wolfram Alpha API. Inspired by the wolframalpha module available for Python.

source("wa_lib.R")

Initialize client

@petermeissner
petermeissner / to_char_bars.md
Last active August 29, 2015 14:16
How to get numbers transformed to character bar charts ... to_char_bars()
@jennybc
jennybc / r-fcsn-in-wild-search.md
Last active January 6, 2020 08:09
Search for "natural" usage of a function across all CRAN packages

What if a function in a package has no examples? Or is poorly exampled? Wouldn't it be nice to find functioning instances of it "in the wild"?

Via Twitter, Noam Ross taught me a clever way to do such searches on GitHub. Put this into the GitHub search box to see people using the llply() function from plyr:

"llply" user:cran language:R

Or just click here.

@sfsheath
sfsheath / oa.R
Created February 27, 2015 21:59
(Not counting calls to library) 2 lines of R code that map data from Open Access
# install.packages("plotGoogleMaps")
# install.packages("jsonlite")
# install.packages("rgdal")
library(jsonlite)
library(rgdal)
library(plotGoogleMaps)
readOGR(dsn = "http://146.148.79.138/sets/Cyprus.json?q=african&response=geo-record&rows=10000", layer = "OGRGeoJSON") -> oa.json
m1<-plotGoogleMaps(oa.json,zcol = "early.bce.ce", filename="oa.html")
@hadley
hadley / advise.md
Created February 13, 2015 21:32
Advise for teaching an R workshop

I think the two most important messages that people can get from a short course are:

a) the material is important and worthwhile to learn (even if it's challenging), and b) it's possible to learn it!

For those reasons, I usually start by diving as quickly as possible into visualisation. I think it's a bad idea to start by explicitly teaching programming concepts (like data structures), because the pay off isn't obvious. If you start with visualisation, the pay off is really obvious and people are more motivated to push past any initial teething problems. In stat405, I used to start with some very basic templates that got people up and running with scatterplots and histograms - they wouldn't necessary understand the code, but they'd know which bits could be varied for different effects.

Apart from visualisation, I think the two most important topics to cover are tidy data (i.e. http://www.jstatsoft.org/v59/i10/ + tidyr) and data manipulation (dplyr). These are both important for when people go off and apply

@shawngraham
shawngraham / getting a History Machine
Last active August 29, 2015 14:14
setting up a history research machine. Follow the instructions.
# By Ben Marwick, from: https://gist.github.com/benmarwick/11204658 with modifications by S. Graham
Short instructions to setup a Lubuntu Virtual Machine with
R & RStudio:
1. Download these:
http://lubuntu.net/ (Intel x86 desktop cd)
https://www.virtualbox.org/wiki/Downloads (Oracle VM VirtualBox)
2. Install Oracle VM VirtualBox, open it (if using windows,
@Robinlovelace
Robinlovelace / if-devtools.R
Last active October 29, 2020 06:34
Installs devtools if needed (put at top of R scripts)
# Install devtools if needed
if(!require(devtools)) install.packages("devtools")
@Pakillo
Pakillo / word-character-count-Rstudio.md
Last active June 25, 2020 21:24
Count words and characters in Rstudio

As far as I know Rstudio does not count words or characters at the moment, which would be useful particularly when writing Rmarkdown.

This is a quick shortcut using word_count and character_count functions from qdap package. See below for two wrapper functions that simplify their use.

library("qdap")

Just select and copy the text to the clipboard and then run in the console: