get_list: Get Lists from the USDA Food Composition Databases

Description Usage Arguments Details Value References See Also Examples

View source: R/get_lists.R

Description

A convenient wrapper function to obtain lists from the USDA nutrient databases. It queries the database for a list of foods, food groups or nutrients.

Usage

1
2
3
get_list(list_type = "f", sort_by = "n", api_key = NULL,
  max_items = 30, offset = 0, format = "json",
  return_request = FALSE)

Arguments

list_type

A character(string). One of f,n,ns,nr,f, and g. See details below.

sort_by

A character(string). How would you like to sort the lists? One of n for name and id. id differs depending on the list type.

api_key

string. A valid api_key obtained from https://ndb.nal.usda.gov/ndb/doc/index#

max_items

integer. Maximum number of items to return.

offset

integer. Where should querying start? Defaults to 0.

format

string. What kind of output do you need? Supports "xml" and "json"

return_request

If format is set to json, this controls whether the initial request is returned to the user. Defaults to FALSE.

Details

For list_type d represents derived foods, f for food, n for all nutrients, ns speciality nutrients, nr for standard nutrients and g for food group. Details available at https://ndb.nal.usda.gov/ndb/doc/apilist/API-LIST.md

Value

A list depending on the requested format type. For JSON, a list of length 2 if return request is requested. Otherwise a list of length 1 with a semi_processed JSON object. The return value for XML is an xml document.

References

https://ndb.nal.usda.gov/ndb/doc/apilist/API-LIST.md

See Also

get_nutrients pretty_xml get_nutrient_info

Examples

1
2
3
4
5
6
7
8
9
## Not run: 
res <- get_list(
list_type = "ns",sort_by = "id",
max_items = 50,offset = 12,format = "xml")
res
usdar::pretty_xml(res,tag="name")
usdar::pretty_json(res)

## End(Not run)

Nelson-Gon/usdandbr documentation built on Jan. 22, 2020, 4:07 a.m.