{"id":15938129,"url":"https://github.com/nelson-gon/rfdc","last_synced_at":"2026-05-03T02:38:25.253Z","repository":{"id":211009806,"uuid":"221853247","full_name":"Nelson-Gon/rfdc","owner":"Nelson-Gon","description":"An R interface to FoodData Central","archived":false,"fork":false,"pushed_at":"2021-11-10T09:49:58.000Z","size":129,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T08:19:03.189Z","etag":null,"topics":["agriculture","fdc","food","html","json","nutrition","nutrition-information","nutritionfacts","r","r-package","r-stats","rest","rest-api","rstats","s4","usda","user-interface","xml"],"latest_commit_sha":null,"homepage":"https://nelson-gon.github.io/rfdc/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nelson-Gon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-11-15T05:48:57.000Z","updated_at":"2021-11-10T09:59:59.000Z","dependencies_parsed_at":"2023-12-06T01:56:34.269Z","dependency_job_id":null,"html_url":"https://github.com/Nelson-Gon/rfdc","commit_stats":null,"previous_names":["nelson-gon/rfdc"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nelson-Gon%2Frfdc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nelson-Gon%2Frfdc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nelson-Gon%2Frfdc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nelson-Gon%2Frfdc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nelson-Gon","download_url":"https://codeload.github.com/Nelson-Gon/rfdc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247070928,"owners_count":20878586,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agriculture","fdc","food","html","json","nutrition","nutrition-information","nutritionfacts","r","r-package","r-stats","rest","rest-api","rstats","s4","usda","user-interface","xml"],"created_at":"2024-10-07T05:21:17.413Z","updated_at":"2026-05-03T02:38:20.221Z","avatar_url":"https://github.com/Nelson-Gon.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"Nelson Gonzabato\n2021-11-10\n\n# rfdc: An R Interface to FoodData Central\n\n[![R-CMD-check](https://github.com/Nelson-Gon/rfdc/actions/workflows/check-pkg.yaml/badge.svg)](https://github.com/Nelson-Gon/rfdc/actions/workflows/check-pkg.yaml)\n[![license](https://img.shields.io/badge/license-GPL--3-blue.svg)](https://www.gnu.org/licenses/old-licenses/gpl-3.0.html)\n[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Nelson-Gon/rfdc/graphs/commit-activity)\n[![Project\nStatus](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)\n[![GitHub last\ncommit](https://img.shields.io/github/last-commit/Nelson-Gon/rfdc.svg)](https://github.com/Nelson-Gon/rfdc/commits/master)\n[![GitHub\nissues](https://img.shields.io/github/issues/Nelson-Gon/rfdc.svg)](https://GitHub.com/Nelson-Gon/rfdc/issues/)\n[![GitHub\nissues-closed](https://img.shields.io/github/issues-closed/Nelson-Gon/rfdc.svg)](https://GitHub.com/Nelson-Gon/rfdc/issues?q=is%3Aissue+is%3Aclosed)\n[![PRs\nWelcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\n# Background\n\nThis repository is intended to serve as a replacement to the R package\n[usdar](https://github.com/Nelson-Gon/usdar). This was necessary because\nthe former API is slated for End of Life as explained in issue\n[#2](https://github.com/Nelson-Gon/usdar/issues/2).\n\nIt is also based on [pyfdc](https://github.com/Nelson-Gon/pyfdc)\n\n**Installation**\n\nTo install the package, one requires to have `devtools` installed. The\npackage is not on CRAN and the author does not intend to push it to CRAN\nunless specific need arises.\n\n``` r\ninstall.packages(\"devtools\")\ndevtools::install_github(\"Nelson-Gon/rfdc\")\n```\n\n**Loading the package**\n\n``` r\nlibrary(rfdc)\n#\u003e Please run set_api_key first.Run key_signup to get an API key.\n```\n\n**Initial Setup**\n\nAs a first step, we need to set an API key for the session via\n`set_api_key` as shown below.\n\n``` r\nset_api_key()\n#\u003e AN API key already exists, enjoy!\n```\n\nTo signup for an API key:\n\n``` r\nkey_signup()\n```\n\n**Initialise an object**\n\nTo intialise an object, we can use `make_object`. See details about each\nclass below. For instance, to initialise an object of class `FoodSearch`\nwith the search term `indomie`:\n\n``` r\nmy_object \u003c- make_object(\"FoodSearch\",search_phrase=\"indomie\")\n```\n\n**Classes**\n\n1.  `FoodSearch` class\n\nThis class allows access to the food search\n[endpoint](https://fdc.nal.usda.gov/api-guide.html) i.e to search/query\nthe database.\n\n**Available methods**\n\n1.  `get_food_info`\n\nTo get details about our object above:\n\n``` r\nget_food_info(my_object,\"description\")\n#\u003e [1] \"CHICKEN INSTANT NOODLES, CHICKEN\"                    \n#\u003e [2] \"CHICKEN CURRY FLAVOUR INSTANT NOODLES, CHICKEN CURRY\"\n#\u003e [3] \"SPECIAL CHICKEN FLAVOUR INSTANT NOODLES, CHICKEN\"\n```\n\nTo get multiple details:\n\n``` r\nget_food_info(my_object,c(\"description\",'fdcId','score'))\n#\u003e                                            description   fdcId     score\n#\u003e 1                     CHICKEN INSTANT NOODLES, CHICKEN 1816702 -537.7092\n#\u003e 2 CHICKEN CURRY FLAVOUR INSTANT NOODLES, CHICKEN CURRY 1987917 -537.7092\n#\u003e 3     SPECIAL CHICKEN FLAVOUR INSTANT NOODLES, CHICKEN 1987671 -537.7092\n```\n\nAnother example:\n\n``` r\nhead(get_food_info(my_object,c('fdcId','description','score')))\n#\u003e     fdcId                                          description     score\n#\u003e 1 1816702                     CHICKEN INSTANT NOODLES, CHICKEN -537.7092\n#\u003e 2 1987917 CHICKEN CURRY FLAVOUR INSTANT NOODLES, CHICKEN CURRY -537.7092\n#\u003e 3 1987671     SPECIAL CHICKEN FLAVOUR INSTANT NOODLES, CHICKEN -537.7092\n```\n\n2.  `get_food_details`\n\nFor the `FoodDetails` class, this returns details about a food data\ncentral id. You can get an fdcId using `get_food_info` from `FoodSearch`\n\n``` r\ntest_object \u003c-make_object(\"FoodDetails\",fdc_id = 504905)\n\nget_food_details(test_object, \"ingredients\")\n#\u003e [1] \"Using URL: https://api.nal.usda.gov/fdc/v1/food/504905?api_key=*****\u0026nutrients=\"\n#\u003e $ingredients\n#\u003e [1] \"MECHANICALLY SEPARATED CHICKEN, CHICKEN BROTH, WATER, CONTAINS LESS THAN 2% OF: SALT, SUGAR, SPICES, SODIUM PHOSPHATE, SODIUM ASCORBATE, SODIUM NITRITE, NATURAL FLAVORS, EXTRACTIVES OF PAPRIKA.\"\n```\n\n3.  `get_nutrients`\n\nTo get nutrients corresponding to a food id:\n\n``` r\nhead(get_nutrients(test_object))\n#\u003e [1] \"Using URL: https://api.nal.usda.gov/fdc/v1/food/504905?api_key=*****\u0026nutrients=\"\n#\u003e     id number                                     name rank unitName serving\n#\u003e 1 1079    291                     Fiber, total dietary 1200        g    0.00\n#\u003e 2 1089    303                                 Iron, Fe 5400       mg    0.83\n#\u003e 3 1110    324 Vitamin D (D2 + D3), International Units 8650       IU    0.00\n#\u003e 4 1087    301                              Calcium, Ca 5300       mg   62.00\n#\u003e 5 1092    306                             Potassium, K 5700       mg   54.00\n#\u003e 6 1235    539                            Sugars, added 1540        g    0.80\n#\u003e                                                       serving_descr\n#\u003e 1 Calculated from a daily value percentage per serving size measure\n#\u003e 2 Calculated from a daily value percentage per serving size measure\n#\u003e 3 Calculated from a daily value percentage per serving size measure\n#\u003e 4 Calculated from a daily value percentage per serving size measure\n#\u003e 5 Calculated from a daily value percentage per serving size measure\n#\u003e 6                    Calculated from value per serving size measure\n```\n\nA `get_label_nutrients` method for a given Food Data Central can also be\nused as follows. Unfortunately, it is unclear what the provided values\nmean nutrition wise.\n\n``` r\nget_label_nutrients(test_object)\n#\u003e [1] \"Using URL: https://api.nal.usda.gov/fdc/v1/food/504905?api_key=*****\u0026nutrients=\"\n#\u003e   fat saturatedFat transFat cholesterol sodium carbohydrates fiber sugars\n#\u003e 1  15          4.5        0        84.5   1060             2     0      1\n#\u003e   protein calcium iron potassium addedSugar calories\n#\u003e 1      10    80.6 1.08      70.2       1.04      179\n```\n\nFurther exploration is left to the user.\n\nPlease note that the ‘rfdc’ project is released with a [Contributor Code\nof Conduct](.github/CODE_OF_CONDUCT.md). By contributing to this\nproject, you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnelson-gon%2Frfdc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnelson-gon%2Frfdc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnelson-gon%2Frfdc/lists"}