Skip to content

Instantly share code, notes, and snippets.

@aaronpeikert
aaronpeikert / skip_weekday.R
Last active February 2, 2022 14:34
Skip the weekend for formr (including tests and friday as weekend)
skip_weekend <-
function(datetime = lubridate::now(),
day_over = lubridate::hm("18:40")) {
stopifnot(lubridate::is.timepoint(datetime))
date <- lubridate::date(datetime)
time <- hms::as_hms(datetime)
is.wday <- function(date, what) {
lubridate::wday(date, label = TRUE) %in% what
}
if (is.wday(date, "Fri") & (time > day_over))
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="http://cmx.io/v/0.1/cmx.css"/>
<script src="http://cmx.io/v/0.1/cmx.js"></script>
<body>
<scene id="scene1">
<label t="translate(0,346)" pose="47,-15|3,-1">
<tspan x="0" y="0em">Back in history...</tspan>
</label>
<actor t="translate(71,19) rotate(-2)" pose="-11,9|-1,114|-11,99|-11,89|-11,79|-11,59|-16,34|-21,9|-6,34|-1,9|-18,79|-18,59|-6,79|13,83">
library(tidyverse)
# simulation --------------------------------------------------------------
add_noise <- function(x, sd, scale = TRUE){
out <- x + rnorm(length(x), sd = sd)
if(scale)out <- scale(out)
out
}
n <- 100
twins_m <-
string <- "Optional reference: @@reference2020
```{r}
myiris <- read.csv('iris.csv')
```
"
cat(cleancitations(string))

As promised, we get a little more practical and share our experience in creating "bulletproof" reproducible analyses. To that end, we get you started with RMarkdown, Git, Make and Docker. Even though we have the most experience in R, this workflow is perfectly compatible with other languages --- like Python or Julia --- and if there is interest, we go through how. We plan three sessions à two hours to tackle this but might spend an additional session on questions that arise as we go along.

  1. Get on track --- How to leverage literate programming and version control for reproducible data analysis projects. This first part of our series on reproducibility introduces you to Git & RMarkdown. A data project is seldom just code; RMarkdown helps you to combine the code, the thoughts that let to it and its results in an elegant report. You'll learn how to use Git to put such document at the centre of collaboration with your fellow data scientists (how to track files, create branches, forks and pull requests, etc.)
library(tidyverse)
library(lme4)
gen_level2 <- function(n = 30, offsetb0 = 0, scaleb0 = 1, offsetb1 = 0, scaleb1 = 1){
unit <- tibble::tibble(b0 = rnorm(n, offsetb0, scaleb0),
b1 = rnorm(n, offsetb1, scaleb1))
return(unit)
}
gen_level2()
@aaronpeikert
aaronpeikert / load_weird_sas.R
Last active September 3, 2019 09:30
How to load a weird sas file that was found in the wild, but refused to be read be haven::read_sas
library(tidyverse)
sas <- tempfile()
download.file("http://psych.colorado.edu/~carey/Courses/PSYC7291/DataSets/Documentation/InterestDataDoc.txt",
sas)
sas <- read_lines(sas)
starts_with_spaces <- function(string){
out <- seq_along(string)
for (i in out) {
if(grepl("^ ", string[i]))out[i] <- out[i-1]
}

Keybase proof

I hereby claim:

  • I am aaronpeikert on github.
  • I am aaronpeikert (https://keybase.io/aaronpeikert) on keybase.
  • I have a public key ASD1vjoYnsYfLP9Q6-rFsqwRWGdgMuMg8tY1XHobVZ7SfQo

To claim this, I am signing this object: