Download FOODB compound data

download_foodb_compound(compound_id = "all", path = ".")

Arguments

compound_id

"all": download all compounds, or a vector of compound IDs.

path

Default is .

Value

FOODB compound database, rda format.

Details

#' @title Request one specific the food information in FoodB #' @description Request one specific the food information in FoodB #' @author Xiaotao Shen #' shenxt1990@outlook.com #' @param url Default is "https://foodb.ca/foods". #' @param food_id food id. For example, FOOD00971 #' @param return_form data.frame or list. #' @return A data frame or list. #' @importFrom XML xmlTreeParse xmlToList #' @importFrom magrittr #' @export #' @examples #' x = request_foodb_food( food_id = "FOOD00971", return_form = "list") #' x #' y = request_foodb_food( food_id = "FOOD00971", return_form = "data.frame") #'

request_foodb_food <- function(url = "https://foodb.ca/foods", food_id = "FOOD00971", return_form = c("list" ,"data.frame")) return_form <- match.arg(return_form) result <- readLines(paste0(url, "/", food_id, ".xml")) result <- XML::xmlTreeParse(file = result, asText = TRUE) result <- XML::xmlToList(result) # names(result) if (return_form == "list") result <- result else version <- result$version foods <- paste(unlist(result$foods[1, ]), collapse = "") result <- data.frame( version = version, creation_date = result$creation_date, update_date = result$update_date, accession = result$accession, name = result$name, description = result$description, synonyms = paste(unlist(result$synonyms), collapse = ""), chemical_formula = result$chemical_formula, average_molecular_weight = as.numeric(result$average_molecular_weight), monisotopic_moleculate_weight = as.numeric(result$monisotopic_moleculate_weight), iupac_name = ifelse(is.null(result$iupac_name), NA, result$iupac_name), traditional_iupac = ifelse( is.null(result$traditional_iupac), NA, result$traditional_iupac ), cas_registry_number = ifelse( is.null(result$cas_registry_number), NA, result$cas_registry_number ), smiles = ifelse(is.null(result$smiles), NA, result$smiles), inchi = ifelse(is.null(result$inchi), NA, result$inchi), inchikey = ifelse(is.null(result$inchikey), NA, result$inchikey), state = ifelse(is.null(result$state), NA, is.null(result$state)), pathways = ifelse(is.null(result$pathways), NA, is.null(result$pathways)), hmdb_id = ifelse(is.null(result$hmdb_id), NA, is.null(result$hmdb_id)), pubchem_food_id = ifelse( is.null(result$pubchem_food_id), NA, is.null(result$pubchem_food_id) ), chemspider_id = ifelse( is.null(result$chemspider_id), NA, is.null(result$chemspider_id) ), kegg_id = ifelse(is.null(result$kegg_id), NA, is.null(result$kegg_id)), chebi_id = ifelse(is.null(result$chebi_id), NA, is.null(result$chebi_id)), biocyc_id = ifelse(is.null(result$biocyc_id), NA, is.null(result$biocyc_id)), het_id = ifelse(is.null(result$het_id), NA, is.null(result$het_id)), wikipidia = ifelse(is.null(result$wikipidia), NA, is.null(result$wikipidia)), vmh_id = ifelse(is.null(result$vmh_id), NA, is.null(result$vmh_id)), fbonto_id = ifelse(is.null(result$fbonto_id), NA, is.null(result$fbonto_id)), foodb_id = ifelse(is.null(result$foodb_id), NA, is.null(result$foodb_id)), general_references = ifelse( is.null(result$general_references), NA, is.null(result$general_references) ), foods = foods, flavors = ifelse(is.null(result$flavors), NA, is.null(result$flavors)), enzymes = ifelse(is.null(result$enzymes), NA, is.null(result$enzymes)), health_effects = ifelse( is.null(result$health_effects), NA, is.null(result$health_effects) ) ) invisible(result)

Author

Xiaotao Shen shenxt1990@outlook.com