ZRH --:--:--

Building my first R package

Notes on structuring an R package: dependencies, DESCRIPTION files, documentation and testing.

Tools2024RPackage development
On this page

Installing Packages

install.packages("devtools")
install.packages("usethis")

Create Package

library(usethis)
create_package('~/Documents/siliconPackage')

Create file

library(usethis)
use_r('silicon')

Package vs R Script

In normal R Scripts you call libraries but in a package you track dependencies differently with using use_package() which adds the package to the DESCRIPTION file.

use_package('ggplot2')

By default, r looks for function inside your own package first so we do not explicitly state the package name. But for external packages like ggplot2 we would use ggplot2::function

.Rprofile

With an .Rprofile file we can add libraries that should be loaded after opening the Package Project in R

if (!require(devtools)) {
  install.packages("devtools")
  library(devtools)
}

Do Checks

devtools::check()

Publish on Github

First init git with use_git('init package')

use_github()
#or
use_github('NameOfOrganization')

Download Package

devtools::install_github('username/packagename')

Documentation

Roxygen2 is a way of documenting function and with @export we tell roxygen2 that this function is ready for export and is accessible for other users that load the package. We can also call the usual ?function the returns our short description. Other function without @export are internal function and can’t be accessed.

#' Title
#'
#' Short description of function with *markdown* syntax
#'
#' @export
function_name <- function(){

}

To make the documentation call the following in the console:

devtools::document()
use_mit_license()

Test created functions

use_testthat()

use_test('nameOfRRcript')

test()

Alternatively in RStudio we can use Build to run all tests.

Rename file

rename_file('old', 'new')

Add readme for github

use_readme_rmd()
build_readme()

Back to top

Esc

Type at least two letters. Search covers every project and knowledge-base note.

oz@zrh: ~
QUICK DOSSIER · 30 SEC READ

OLIVER ZINGG

Psychologist and data scientist in Zürich. I design the study, model the data and explain what it means.

STATUS
Open to full-time data science roles from January 2027
NOW
Working student, data science & project management at Zurich Insurance (since Nov 2025)
THESIS
M.Sc. thesis (HSLU): leveraging double machine learning for robust decision-making, due December 2026
EDUCATION
M.Sc. Psychology (UZH, 5.6) · M.Sc. Applied Information & Data Science (HSLU, Dec 2026)
TOOLS
R, Python, SQL, Matlab · Power BI, Tableau · mixed models, ML, BERTopic

TOP CASE FILES

  1. Learning and memory formation in children and adolescents with psychiatric disordersMaster's thesis, UZH · 2023
  2. Support vector machines vs. CNNs for Alzheimer's disease classificationBachelor's thesis, UZH · 2021
  3. Simpson's paradox and mixed-effects modelsStatistics · 2023