• Lab manual
  • 1 Welcome to the Benjamin-Chung Lab!
    • 1.1 About the lab
    • 1.2 About this lab manual
  • 2 Culture and conduct
    • 2.1 Lab culture
    • 2.2 Diversity, equity, and inclusion
    • 2.3 Protecting human subjects
    • 2.4 Authorship
  • 3 Communication and coordination
    • 3.1 Slack
    • 3.2 Email
    • 3.3 Trello
    • 3.4 Google Drive
    • 3.5 Stanford Medicine Box
    • 3.6 Meetings
  • 4 Reproducibility
    • 4.1 What is the reproducibility crisis?
    • 4.2 Study design
    • 4.3 Register study protocols
    • 4.4 Write pre-analysis plans
    • 4.5 Register pre-analysis plans
    • 4.6 Create reproducible workflows
    • 4.7 Process and analyze data with internal replication and masking
    • 4.8 Use reporting checklists with manuscripts
    • 4.9 Publish preprints
    • 4.10 Publish data (when possible) and replication scripts
  • 5 Getting started
    • 5.1 The tools and how they connect
    • 5.2 RStudio
    • 5.3 GitHub intro
    • 5.4 The terminal
    • 5.5 Sherlock
    • 5.6 Box
    • 5.7 A typical first week
  • 6 Using generative AI to code
    • 6.0.1 Benjamin-Chung Lab Policy on use of AI in Research
    • 6.1 Three key issues
    • 6.2 Bottom line
      • 6.2.1 Research accuracy and the value of experience
      • 6.2.2 Impeding learning? An open question
      • 6.2.3 Data safety in a research context
      • 6.2.4 Understanding agentic AI permission prompts
    • 6.3 Best practices
      • 6.3.1 For learning and skill development
      • 6.3.2 For research accuracy
      • 6.3.3 For data protection
    • 6.4 Configuring permissions for agentic AI
      • 6.4.1 Permission modes
    • 6.5 Disclosing use of generative AI in research
    • 6.6 Know your target journal’s AI policy before you start
  • 7 Code repositories
    • 7.1 Project Structure
    • 7.2 0-functions folder
    • 7.3 .Rproj files
    • 7.4 Configuration (‘config’) File
    • 7.5 Order Files and Directories
    • 7.6 Using Bash scripts to ensure reproducibility
  • 8 Coding practices
    • 8.1 Organizing scripts
    • 8.2 Documenting your code
      • 8.2.1 File headers
      • 8.2.2 Sections and subsections
      • 8.2.3 Code folding
      • 8.2.4 Comments in the body of your script
      • 8.2.5 Function documentation
    • 8.3 Object naming
    • 8.4 Function calls
    • 8.5 The here package
    • 8.6 Reading/Saving Data
      • 8.6.1 .RDS vs .RData Files
      • 8.6.2 CSVs
    • 8.7 Tidyverse
    • 8.8 Coding with R and Python
    • 8.9 Repeating analyses with different variations
      • 8.9.1 lapply() and sapply()
      • 8.9.2 mapply() and pmap()
      • 8.9.3 Parallel processing with parallel and future packages
    • 8.10 Reviewing Code
      • 8.10.1 Why we review code
      • 8.10.2 What to look for in a code review
      • 8.10.3 How to give feedback
      • 8.10.4 When to approve
      • 8.10.5 Creating a Pull Request Template
  • 9 Coding style
    • 9.1 Comments
    • 9.2 Line breaks
    • 9.3 Automated Tools for Style and Project Workflow
      • 9.3.1 Styling
  • 10 Working with Big Data
    • 10.1 The data.table package
    • 10.2 Using downsampled data
    • 10.3 Optimal RStudio set up
  • 11 Tidy evaluation and programming with dplyr
    • 11.1 General Overview
      • 11.1.1 What is Tidy Evaluation?
      • 11.1.2 Using tidy evaluation for data masking
    • 11.2 Technical Overview
      • 11.2.1 Example
  • 12 Data validation and unit testing
    • 12.1 Data validation with assertions in analysis scripts
      • 12.1.1 After merges and joins
      • 12.1.2 After filters and subsets
      • 12.1.3 After variable creation
      • 12.1.4 Checking for unexpected missing data
    • 12.2 Writing a validation function
    • 12.3 Unit testing with testthat
      • 12.3.1 Setting up unit tests
      • 12.3.2 Writing unit tests
      • 12.3.3 Running tests
      • 12.3.4 What to test
    • 12.4 Summary of practices
  • 13 Github
    • 13.1 Basics
    • 13.2 Github in Command Line vs. Github Desktop
    • 13.3 Git Branching
    • 13.4 Example Workflow
    • 13.5 Commonly Used Git Commands
    • 13.6 How often should I commit?
    • 13.7 What not to put on Github
    • 13.8 What should be pushed to Github?
    • 13.9 More resources
  • 14 Unix commands
    • 14.1 Basics
    • 14.2 Syntax for both Mac/Windows
    • 14.3 Running Bash Scripts
    • 14.4 Running Rscripts in Windows
      • 14.4.1 Common Mistakes
    • 14.5 Checking tasks and killing jobs
    • 14.6 Running big jobs
      • 14.6.1 Example code for runfileSaveLogs
      • 14.6.2 Example usage for runfileSaveLogs
  • 15 Reproducible Environments
    • 15.1 Package Version Control with renv
      • 15.1.1 Introduction
      • 15.1.2 Implementing renv in projects
      • 15.1.3 Using projects with renv
    • 15.2 Documenting the R version
    • 15.3 Ensuring consistency between local and cluster environments
  • 16 Code Publication
    • 16.1 Checklist overview
    • 16.2 Fill out file headers
    • 16.3 Clean up comments
    • 16.4 Document functions
    • 16.5 Remove deprecated filepaths
    • 16.6 Ensure project runs via bash
    • 16.7 Complete the README
    • 16.8 Clean up feature branches
    • 16.9 Create Github release
  • 17 Data Publication
    • 17.1 Overview
    • 17.2 Removing PHI
      • 17.2.1 Personal information
      • 17.2.2 Dates
      • 17.2.3 Geographic information
    • 17.3 Create public IDs
      • 17.3.1 Rationale
      • 17.3.2 A single set of public IDs for each study
      • 17.3.3 Example scripts
    • 17.4 Create a data repository
      • 17.4.1 Steps for creating an Open Science Framework (OSF) repository:
    • 17.5 Edit and test analysis scripts
    • 17.6 Create a public GitHub page for public scripts
    • 17.7 Go live
  • 18 Slurm and cluster computing
    • 18.1 Getting started
      • 18.1.1 One-Time System Set-Up
    • 18.2 Moving files to Sherlock
    • 18.3 Installing packages on Sherlock
    • 18.4 Testing your code
      • 18.4.1 The command line
      • 18.4.2 The Sherlock OnDemand Dashboard
      • 18.4.3 Filepaths & configuration on Sherlock
    • 18.5 Storage & group storage access
      • 18.5.1 Individual storage
      • 18.5.2 Group storage
      • 18.5.3 Folder permissions
    • 18.6 Running big jobs
  • 19 Checklists
    • 19.1 Pre-analysis plan checklist
    • 19.2 Code checklist
    • 19.3 Manuscript checklist
    • 19.4 Figure checklist
  • 20 Resources
    • 20.1 Resources for R
    • 20.2 Resources for Git & Github
    • 20.3 Scientific figures
    • 20.4 Writing
    • 20.5 Presentations
    • 20.6 Professional advice
    • 20.7 Funding
    • 20.8 Ethics and global health research
  • Published with bookdown

Using Generative AI to Code

Chapter 20 Resources

by Jade Benjamin-Chung and Kunal Mishra

20.1 Resources for R

  • dplyr and tidyr cheat sheet
  • ggplot cheat sheet
  • data table cheat sheet
  • RMarkdown cheat sheet
  • Hadley Wickham’s R Style Guide
  • Jade’s R-for-epi course
  • Tidy Eval in 5 Minutes (video)
  • Tidy Evaluation (e-book)
  • Data Frame Columns as Arguments to Dplyr Functions (blog)
  • Standard Evaluation for *_join (stackoverflow)
  • Programming with dplyr (package vignette)

20.2 Resources for Git & Github

  • Data Camp introduction to Git
  • Introduction to Github

20.3 Scientific figures

  • Ten Simple Rules for Better Figures

20.4 Writing

  • Tips on how to write a great science paper
  • ICMJE Definition of authorship
  • Nature article on elements of style for scientific writing
  • The Pathway to Publishing: A Guide to Quantitative Writing in the Health Sciences
  • Secret, actionable writing tips

20.5 Presentations

  • How to tell a compelling story in scientific presentations
  • How to give a killer narratively-driven scientific talk
  • How to make a better poster
  • How to make an even better poster

20.6 Professional advice

  • Professional advice, especially for your first job

20.7 Funding

  • Building Your Funding Train

20.8 Ethics and global health research

  • Global Code of Conduct For Research in Resource-Poor Settings
  • Who is a global health expert? Advice for aspiring global health experts
  • Transforming Global Health Partnerships