Good coding practices
2026-06-12
Where can errors happen during data collection or data analysis? Be creative!
.-problem”); with correct coding marital infidelity is at 6%Taken from a presentation from Katrin Auspurg & Josef Brüderl. All examples are from publications in the American Sociological Review, considered one of the very top journals in sociology.
The summarytools package makes this really easy:
alternatively: codebook package by Ruben Arslan (also has an RStudio plugin). Has some nice convenience functions, e.g. when importing SPSS or other data files.
set.seed(123))
sessionInfo() of the analytical pipeline in the README file when you submit a paper, and for every revisionR: packages renv, checkpoint, or packratWhich is an example of a sensible file naming convention?
YYYY-MM-DD.Absolute path:
C:/Users/felix/Empra_Project/raw_data/study1.csv
Relative path: relative to the root folder:
C:/Users/felix/Empra_Project/raw_data/study1.csv
R by creating a .Rproj file in C:/Users/felix/Empra_Project/read.csv("raw_data/study1.csv")/cache. If you refer to this data file in subsequent scripts, you do not have to run the preprocessing script every time. All files in /processed_data can be safely deleted, as they can be reconstructed by running all script files in the correct order.README.md) as it is rendered in Github and other repositoriessnake_case, camelCase, PascalCase, dot.style, sTUdLy_cAPs?
## This source code is licensed under the FreeBSD License (see ...)
## (c) 2017 Felix Schönbrodt
## This file runs the Monte-Carlo simulations reported
## in Schönbrodt & Perugini (2013). doi:10.1016/j.jrp.2013.05.009
library(dplyr)
library(doParallel)
# Register multicore
nCore <- 10
registerDoParallel(cores=nCore)
# Load Ruscio's function for inducing a correlation into an
# existing empirical marginal distributions
source("00-Ruscio_GenData.R")
## Simulation parameters
popsize <- 1000000 # size of population from which samples are drawn
n.max <- 1000 # maximum sample sizeForschungsorientierte Praktikum I – Empirisches Praktikum, Ludwig-Maximilians-Universität München