db_search: Plain Text Database Search

Description Usage Arguments Value Examples

View source: R/db_search.R

Description

Provides a plain text option to search the database.

Usage

1
2
3
db_search(api_key = NULL, result_type = NULL, search_term = NULL,
  data_source = NULL, food_group = NULL, sort_by = "r",
  max_rows = 50, offset = 0)

Arguments

api_key

An API key as obtained from the USDA NDB.

result_type

The nature of the return result. Supports one of "xml" and "json"

search_term

A plain text string of the desired search term.

data_source

A string. One of Branded Food Products and Standard Release.

food_group

A string. A specific food_group. See examples below.

sort_by

One of 'r' for relevance and 'n' for name that decides the nature of sorting for the return items.

max_rows

The maximum number of rows to return.

offset

Determines the starting point for "indexing". Defaults to 0.

Value

A processed JSON result or xml result as may be requested.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
#set_apikey("key here if not set for the session")
#sorted by relevance
db_search(result_type = "json",search_term = "Acerola",
sort_by = "r")
# sorted by name
db_search(result_type = "json",search_term = "Acerola",
sort_by = "n")
# return xml
res<-db_search(result_type = "xml",search_term = "Acerola",
sort_by = "r")
#process xml
pretty_xml(res, tag="name")

## End(Not run)

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