Writing DRY code in R with functions

April 26, 2021 • PD Schloss • 1 min read

Code

This is where we started before the episode

library(tidyverse)
library(readxl)
library(glue)
library(ggtext)

set.seed(19760620)

metadata <- read_excel(path="raw_data/schubert.metadata.xlsx", na="NA") %>%
  mutate(disease_stat = factor(disease_stat,
                               levels=c("NonDiarrhealControl",
                                        "DiarrhealControl",
                                        "Case")
                               )
  )

alpha_diversity <- read_tsv("raw_data/schubert.groups.ave-std.summary") %>%
  filter(method == "ave") %>%
  select(-label, -method)

disease_invsimpson <- inner_join(metadata, alpha_diversity,
                             by=c('sample_id'='group')) %>%
	select(disease_stat, invsimpson)

Installations

comments powered by Disqus