knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

rfdc: An R Interface to FoodData Central

Build Status license lifecycle Maintenance Project Status GitHub last commit GitHub issues GitHub issues-closed PRs Welcome

Background

This repository is intended to serve as a replacement to the R package usdar. This was necessary because the former API is slated for End of Life as explained in issue #2.

It is also based on pyfdc

Installation

To install the package, one requires to have devtools installed. The package is not on CRAN and the author does not intend to push it to CRAN unless specific need arises.

# install.packages("devtools")
#devtools::install_github("Nelson-Gon/rfdc")

Loading the package

library(rfdc)

Initial Setup

As a first step, we need to set an API key for the session via set_api_key as shown below.

set_api_key("key_here")

To signup for an API key:

key_signup()

Initialise an object

To intialise an object, we can use make_object. See details about each class below. For instance, to initialise an object of class FoodSearch with the search term indomie:

my_object <- make_object("FoodSearch",search_phrase="indomie")

Classes

  1. FoodSearch class

This class allows access to the food search endpoint i.e to search/query the database.

Available methods

  1. get_food_info

To get details about our object above:

get_food_info(my_object,"description")

To get multiple details:

get_food_info(my_object,c("description",'fdcId','score'))

Another example:

head(get_food_info(test,c('fdcId','description','score')))
  1. get_food_details

For the FoodDetails class, this returns details about a food data central id. You can get an fdcId using get_food_info from FoodSearch

test_object <-make_object("FoodDetails",fdc_id = 504905)

get_food_details(test_object, "ingredients")
  1. get_nutrients

To get nutrients corresponding to a food id:

head(get_nutrients(test_object))

Further exploration is left to the user.

Please note that the 'rfdc' project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.



Nelson-Gon/rfdc documentation built on Nov. 14, 2021, 3:23 a.m.