Skip to content

Commit 77433fc

Browse files
MoenMidachambers
andauthored
Update R Recipes (#175)
* Update branch (#172) * docs: Update README and Introduction page * chore: Add robots.txt * fix: Roll back some changes * fix: Remove duplicated canonical link * docs: Update links to fix build warning --------- Co-authored-by: dachambers <dachambers@ua.edu> * feat: Add plotly support * chore: Update .gitignore for easier management of R recipes * chore: Clean up * chore: Update arXiv in R recipe * chore: Update College Scorecard in R recipe * fix: Resolve Jupyter Book build warning from RST file * chore: Update Library of Congress overview page * chore: Update Library of Congress in R recipe * chore: Update _toc.yml to reflect R changes * chore: Update Crossref in R recipe * chore: Update ScienceDirect in R * feat: Add Sage in R recipe * chore: Update Wiley in R * chore: Update USAspending in R * chore: Update U.S. Census in R * chore: Update SEC EDGAR in R * Update branch (#173) * docs: Update README and Introduction page * chore: Add robots.txt * fix: Roll back some changes * fix: Remove duplicated canonical link * docs: Update links to fix build warning --------- Co-authored-by: dachambers <dachambers@ua.edu> * docs: Update USGS National Map blurb * feat: Update CAS Common Chemistry in R recipe * docs: Fix capitalization * fix: Corrected sphinx extenssion reference * feat: Update World Bank in Python recipe * feat: Update PubChem in R recipe * feat: Update PubMed in R * feat: Update World Bank in R recipe * chore: Update introdution page * docs: Update README and licensing text * chore: Rerun and slightly update some Python recipes * docs: Update Python recipe template --------- Co-authored-by: dachambers <dachambers@ua.edu>
1 parent 5473b65 commit 77433fc

137 files changed

Lines changed: 32232 additions & 7515 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ _build/
22
.ipynb_checkpoints/
33
.env
44
.Renviron
5+
rmarkdown/_figures*
6+
rmarkdown/*.md
7+
rmarkdown/*.html

LICENSE_selected_R_tutorials

Lines changed: 0 additions & 675 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
> [!IMPORTANT]
77
> Please check the individual scholarly API documentation for current information on API usage and policies.
88
>
9-
> November 2024 - Some R code tutorials that were originally MIT Licensed, are now licensed under the GPL-3 License to comply with the licensing terms of dependent R libraries.
9+
> April 2026 - Some earlier R code tutorials in this repository were licensed under the GPL‑3.0 License. The tutorials have since been revised, and the current versions are licensed under the MIT License.
1010
1111
The University of Alabama Libraries Scholarly API Cookbook is an open online book containing short scholarly API code examples (i.e., "recipes") that demonstrate how to work with various scholarly web service APIs. It is part of the University of Alabama Libraries efforts to support Research Data Services. Read the book [here](https://ua-libraries-research-data-services.github.io/UALIB_ScholarlyAPI_Cookbook).
1212

1313
## License and Reuse
1414

15-
Most of the code in this repository is licensed under the [MIT License](https://github.com/UA-Libraries-Research-Data-Services/UALIB_ScholarlyAPI_Cookbook/blob/main/LICENSE), but some of the R tutorial scripts are under the [GPL-3 License](https://github.com/UA-Libraries-Research-Data-Services/UALIB_ScholarlyAPI_Cookbook/blob/main/LICENSE_selected_R_tutorials). Please see the [License and Reuse page](https://ua-libraries-research-data-services.github.io/UALIB_ScholarlyAPI_Cookbook/about/license-reuse) for more information about licensing and reuse. We have endeavored to follow the appropriate terms and usage policies of each scholarly API, web service, and Z39.50 server. We have linked to the terms and policies where possible. If you reuse the code, attribution would be appreciated. Please link to the Cookbook and see the [Cite page](https://ua-libraries-research-data-services.github.io/UALIB_ScholarlyAPI_Cookbook/about/cite) for full citation information.
15+
The code in this repository is licensed under the [MIT License](https://github.com/UA-Libraries-Research-Data-Services/UALIB_ScholarlyAPI_Cookbook/blob/main/LICENSE). Please see the [License and Reuse page](https://ua-libraries-research-data-services.github.io/UALIB_ScholarlyAPI_Cookbook/about/license-reuse) for more information about licensing and reuse. We have endeavored to follow the appropriate terms and usage policies of each scholarly API, web service, and Z39.50 server. We have linked to the terms and policies where possible. If you reuse the code, attribution would be appreciated. Please link to the Cookbook and see the [Citing the Cookbook page](https://ua-libraries-research-data-services.github.io/UALIB_ScholarlyAPI_Cookbook/about/cite) for full citation information.
1616

1717
## Archived Recipes
1818

recipe-templates/python.ipynb

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# [API Name] in Python\n",
8+
"\n",
9+
"By [Author Name], [Author Name], and [Author Name]\n",
10+
"\n",
11+
"<!-- Brief 1-2 sentence description of the API -->\n",
12+
"\n",
13+
"<!-- Include the following sentence if applicable: -->\n",
14+
"<!-- *This tutorial content is intended to help facilitate academic research. Please check your institution for their Text and Data Mining or related License Agreement with [Company name].* -->\n",
15+
"\n",
16+
"Please see the following resources for more information on API usage:\n",
17+
"\n",
18+
"- Documentation\n",
19+
" - <a href=\"\" target=\"_blank\">[Service Name]</a>\n",
20+
" - <a href=\"\" target=\"_blank\">[Service Name] Documentation</a>\n",
21+
"- Terms\n",
22+
" - <a href=\"\" target=\"_blank\">[Service Name] Terms of Use</a>\n",
23+
"- Data Reuse\n",
24+
" - <a href=\"\" target=\"_blank\">[Service Name] Data Reuse</a>\n",
25+
"<!-- Link to license (e.g. CC-BY-SA 4.0), if applicable. -->\n",
26+
"<!-- Use official names provided by the service when describing the content in the links above. -->\n",
27+
"<!-- Also include links to any licenses, official code examples, and other useful sources above. -->\n",
28+
"<!-- If you are using any specific libraries for accessing the API, include terms of use, documentation, etc. for those as well. -->\n",
29+
"\n",
30+
"**_NOTE:_** The [API Name] limits requests to a maximum of [limit].\n",
31+
"\n",
32+
"*These recipe examples were tested on [Month] [Date], [Year].*"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"metadata": {},
38+
"source": [
39+
"## Setup\n",
40+
"\n",
41+
"<!-- If there is only one category necessary for the tutorial, then remove the level 3 header (i.e., if `### Import Libraries` is the only header under `## Setup`, then remove `### Import Libraries` and just have the other markdown text and code directly under `## Setup`). -->\n",
42+
"\n",
43+
"### Import Libraries\n",
44+
"\n",
45+
"The following external libraries need to be installed into your environment to run the code examples in this tutorial:\n",
46+
"\n",
47+
"- <a href=\"https://github.com/ipython/ipykernel\" target=\"_blank\">ipykernel</a>\n",
48+
"<!-- - <a href=\"https://github.com/matplotlib/matplotlib\" target=\"_blank\">matplotlib</a> -->\n",
49+
"<!-- - <a href=\"https://github.com/numpy/numpy\" target=\"_blank\">numpy</a> -->\n",
50+
"<!-- - <a href=\"https://github.com/pandas-dev/pandas\" target=\"_blank\">pandas</a> -->\n",
51+
"<!-- - <a href=\"https://github.com/theskumar/python-dotenv\" target=\"_blank\">python-dotenv</a> -->\n",
52+
"<!-- - <a href=\"https://github.com/psf/requests\" target=\"_blank\">requests</a> -->\n",
53+
"\n",
54+
"We import the libraries used in this tutorial below:"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": null,
60+
"metadata": {},
61+
"outputs": [],
62+
"source": [
63+
"from dotenv import load_dotenv\n",
64+
"import matplotlib.pyplot as plt\n",
65+
"import numpy as np\n",
66+
"import os\n",
67+
"import pandas as pd\n",
68+
"import requests\n",
69+
"from time import sleep"
70+
]
71+
},
72+
{
73+
"cell_type": "markdown",
74+
"metadata": {},
75+
"source": [
76+
"### Import API Key / Set User Info / Define User-Agent\n",
77+
"\n",
78+
"An API key is required to access the [API name]. You can sign up for one at the <a href=\"\" target=\"_blank\">Developer Portal</a>.\n",
79+
"\n",
80+
"We keep our API key in a `.env` file and use the `dotenv` library to access it. If you would like to use this method, create a `.env` file and add the following line to it:\n",
81+
"\n",
82+
"```text\n",
83+
"API_NAME_KEY=PUT_YOUR_API_KEY_HERE\n",
84+
"```"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": null,
90+
"metadata": {},
91+
"outputs": [],
92+
"source": [
93+
"load_dotenv()\n",
94+
"try:\n",
95+
" API_KEY = os.environ[\"API_NAME_KEY\"]\n",
96+
"except KeyError:\n",
97+
" print(\"API key not found. Please set 'API_NAME_KEY' in your .env file.\")"
98+
]
99+
},
100+
{
101+
"cell_type": "markdown",
102+
"metadata": {},
103+
"source": [
104+
"### API Data Download\n",
105+
"\n",
106+
"<!-- Some APIs will offer bulk downloads. If this exists, link to it here (replacing the `### API Data Download` with the official name of the service), and encourage users who require a lot of data to use that if it fits their use case. -->\n",
107+
"\n",
108+
"The [Service name] offers the [Data download name] for bulk download. Consider using this is you require a large amount of data to be more considerate of [Service name]'s servers."
109+
]
110+
},
111+
{
112+
"cell_type": "markdown",
113+
"metadata": {},
114+
"source": [
115+
"## 1. Example API Use Case\n",
116+
"\n",
117+
"<!-- Make sure that all of the headers use title capitalization. -->\n",
118+
"\n",
119+
"<!-- The first example should be straightforward, typically composing of a single API call and parsing out simple information from the response, showing how some of the returned data is structured. -->"
120+
]
121+
},
122+
{
123+
"cell_type": "code",
124+
"execution_count": null,
125+
"metadata": {},
126+
"outputs": [],
127+
"source": [
128+
"# Comments should start with a space followed by a capital letter"
129+
]
130+
},
131+
{
132+
"cell_type": "markdown",
133+
"metadata": {},
134+
"source": [
135+
"## Checklist Before Publishing\n",
136+
"\n",
137+
"General:\n",
138+
"- Are all titles capitalized?\n",
139+
"- Do all authors have their preferred name listed (e.g. Vincent F. Scalfani, Avery Fernandez, etc.)?\n",
140+
"- Does the header follow the correct formatting according to the template?\n",
141+
" - Is the documentation linked?\n",
142+
" - Is there a link to the TOS, license, or other usage guidelines?\n",
143+
" - Are any rate limits included?\n",
144+
" - Is the date of the code execution accurate?\n",
145+
" - Have you checked the licensing of any libraries used?\n",
146+
"- Is the filename `api-name.ipynb`, consistent with other tutorials?\n",
147+
"\n",
148+
"Code:\n",
149+
"- Are all comments properly spaced and capitalized?\n",
150+
"- Is each line of code under 95 characters in length (not a strict guideline, but encouraged)?\n",
151+
"- Has the `output_scroll` tag been set for any long outputs?\n",
152+
"- Is any sensitive data exposed in any code outputs?\n",
153+
"- Do you import any libraries that go unused?\n",
154+
"\n",
155+
"Try to stick to the formatting defined in this template as closely as possible for consistency with other tutorials, but feel free to stray from the guidelines if needed."
156+
]
157+
}
158+
],
159+
"metadata": {
160+
"kernelspec": {
161+
"display_name": "Python 3",
162+
"language": "python",
163+
"name": "python3"
164+
},
165+
"language_info": {
166+
"codemirror_mode": {
167+
"name": "ipython",
168+
"version": 3
169+
},
170+
"file_extension": ".py",
171+
"mimetype": "text/x-python",
172+
"name": "python",
173+
"nbconvert_exporter": "python",
174+
"pygments_lexer": "ipython3",
175+
"version": "3.11.9"
176+
}
177+
},
178+
"nbformat": 4,
179+
"nbformat_minor": 2
180+
}

recipe-templates/r.Rmd

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: "[API Name] in R"
3+
output:
4+
html_document:
5+
keep_md: true
6+
---
7+
8+
```{r setup, include=FALSE}
9+
knitr::opts_chunk$set(
10+
fig.path = "_figures/[API NAME]/"
11+
)
12+
```
13+
14+
# [API Name] in R
15+
16+
By [Author Name], [Author Name], and [Author Name]
17+
18+
<!-- Brief 1-2 sentence description of the API -->
19+
20+
<!-- *This tutorial content is intended to help facilitate academic research. Please check your institution for their Text and Data Mining or related License Agreement with [Company name].* -->
21+
22+
Please see the following resources for more information on API usage:
23+
- Documentation
24+
- <a href="" target="_blank">[Service Name]</a>
25+
- <a href="" target="_blank">[Service Name] Documentation</a>
26+
- Terms
27+
- <a href="URL" target="_blank">[Service Name] Terms of Use</a>
28+
- Data Reuse
29+
- <a href="URL" target="_blank">[Service Name] Data Reuse</a>
30+
31+
<!-- Use official names provided by the service when describing the content in the links above. -->
32+
<!-- Also include links to any licenses, official code examples, and other useful sources above. -->
33+
<!-- Use title capitalization in the bolded text above. -->
34+
<!-- Also include links to any licenses, official code examples, and other useful sources above. -->
35+
<!-- If you are using any specific libraries for accessing the API, include terms of use, documentation, etc. for those as well. -->
36+
37+
_**NOTE:**_ The [API Name] limits requests to a maximum of [limit].
38+
39+
*These recipe examples were tested on [Month] [Date], [Year].*
40+
41+
<!-- Try to stick to the formatting defined in this template as closely as possible for consistency with other tutorials, but prioritize please break the guidelines to include necessary info if needed. -->
42+
43+
## Setup
44+
45+
<!-- If there is only one category necessary for the tutorial, then remove the level 3 header (i.e., if `### Import Libraries` is the only header under `## Setup`, then remove `### Import Libraries` and just have the other markdown text and code directly under `## Setup`). -->
46+
47+
### Load Libraries
48+
49+
The following packages need to be installed into your environment to run the code examples in this tutorial. These packages can be installed with `install.packages()`.
50+
51+
- <a href="https://cran.r-project.org/web/packages/dplyr/index.html" target="_blank">dplyr: A Grammar of Data Manipulation</a>
52+
- <a href="https://cran.r-project.org/web/packages/ggplot2/index.html" target="_blank">ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics</a>
53+
- <a href="https://cran.r-project.org/web/packages/httr/index.html" target="_blank">httr: Tools for Working with URLs and HTTP</a>
54+
- <a href="https://cran.r-project.org/web/packages/imager/index.html" target="_blank">imager: Image Processing Library Based on 'CImg'</a>
55+
- <a href="https://cran.r-project.org/web/packages/jsonlite/index.html" target="_blank">jsonlite: A Simple and Robust JSON Parser and Generator for R</a>
56+
- <a href="https://cran.r-project.org/web/packages/knitr/index.html" target="_blank">knitr: A General-Purpose Package for Dynamic Report Generation in R</a>
57+
- <a href="https://cran.r-project.org/web/packages/magick/index.html" target="_blank">magick: Advanced Graphics and Image-Processing in R</a>
58+
- <a href="https://cran.r-project.org/web/packages/purrr/index.html" target="_blank">purrr: Function Programming Tools</a>
59+
- <a href="https://cran.r-project.org/web/packages/tidyverse/index.html" target="_blank">tidyverse: Easily Install and Load the 'Tidyverse'</a>
60+
61+
We load the libraries used in this tutorial below:
62+
63+
```{r}
64+
library(httr)
65+
```
66+
67+
### Import API Key
68+
69+
An API key is required for to access the [API Name]. You can sign up for one at <a href="" target="_blank">webpage name</a>.
70+
71+
We keep our token in a `.Renviron` file that is stored in the working directory and use `Sys.getenv()` to access it. The `.Renviron` should have an entry like the one below.
72+
73+
```text
74+
API_KEY="PUT_YOUR_API_KEY_HERE"
75+
```
76+
77+
Below, we can test to whether the key was successfully imported.
78+
79+
```{r}
80+
if (nzchar(Sys.getenv("API_KEY"))) {
81+
print("API key successfully loaded.")
82+
} else {
83+
warning("API key not found or is empty.")
84+
}
85+
```

0 commit comments

Comments
 (0)