vallenderlab / MicrobiomeR

A comprehensive and customizable R package for microbiome analysis.
https://vallenderlab.github.io/MicrobiomeR/
MIT License
20 stars 4 forks source link

Make a better way to access our "static data". #43

Closed grabear closed 5 years ago

grabear commented 5 years ago

Our current way of doing this is using a function and adding the data to the global environment with:

# A function for accessing variables.
get_static_data <- function(...) {
  data <- list()
  # Create a list for validating metacoder observation data
  basic_names <- c("otu_abundance", "otu_annotations")
  analyzed_names <- c("taxa_abundance", "otu_proportions", "taxa_proportions")
  all_names <- c(basic_names, analyzed_names)
  valid_list <- list(basic = basic_names, analyzed = analyzed_names, all = all_names)
  # Create various rank based lists
  ranks <- list(c("Kingdom"), c("Phylum"), c("Class"), c("Order"), c("Family"), c("Genus"), c("Species"))
  rank_index <- list("Kingdom" = 1, "Phylum" = 2, "Class" = 3, "Order" = 4, "Family" = 5, "Genus" = 6, "Species" = 7)
  mc_df_rank_list <- list("Kingdom" = 4, "Phylum" = 5, "Class" = 6, "Order" = 7, "Family" = 8, "Genus" = 9, "Species" = 10)
  format_list <- list("phyloseq_format" = 0, "raw_format" = 1, "basic_format" = 2, "analyzed_format" = 3)
  data <- list(valid_list = valid_list, ranks = ranks, rank_index = rank_index, mc_df_rank_list = mc_df_rank_list)
  list2env(data[...], envir = .GlobalEnv)
}

However a more elegant solution might be to create a "package environment" (link so that this data does not easily disrupt the end users experience.

grabear commented 5 years ago

Duplicate of #8