You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/r/sdirect.md
+65-23Lines changed: 65 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,40 +1,72 @@
1
+
---
2
+
title: "ScienceDirect API in R"
3
+
output:
4
+
html_document:
5
+
keep_md: true
6
+
---
7
+
1
8
# ScienceDirect API in R
2
9
3
10
by Michael T. Moen
4
11
5
-
These recipe examples demonstrate how to use Elsevier’s [ScienceDirect API](https://dev.elsevier.com/) to retrieve full-text articles in various formats (XML, text).
12
+
These recipe examples demonstrate how to use Elsevier’s <ahref="https://dev.elsevier.com/"target="_blank">ScienceDirect API</a> to retrieve full-text articles in various formats (XML, text).
6
13
7
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 Elsevier.*
8
15
9
-
-**Documentation**
10
-
-[ScienceDirect API](https://dev.elsevier.com/)
11
-
-[ScienceDirect API Documentation](https://dev.elsevier.com/sd_api_spec.html)
12
-
13
-
-**Terms**
14
-
-[ScienceDirect API Terms of Use](https://dev.elsevier.com/api_key_settings.html)
16
+
Please see the following resources for more information on API usage:
15
17
16
-
-**Data Reuse**
17
-
-[Elsevier Text & Data Mining](https://dev.elsevier.com/tecdoc_text_mining.html)
- <ahref="https://dev.elsevier.com/sd_api_spec.html"target="_blank">ScienceDirect API Documentation</a>
21
+
- Terms\n",
22
+
- <ahref="https://dev.elsevier.com/api_key_settings.html"target="_blank">ScienceDirect API Terms of Use</a>
23
+
- Data Reuse
24
+
- <ahref="https://dev.elsevier.com/tecdoc_text_mining.html"target="_blank">Elsevier Text & Data Mining</a>
18
25
19
-
> **Note:** See your institution's rate limit in the [ScienceDirect API Terms of Use](https://dev.elsevier.com/api_key_settings.html).
26
+
_**NOTE:**_ See your institution's rate limit with <ahref="https://dev.elsevier.com/api_key_settings.html"target="_blank">ScienceDirect API Terms of Use</a>.
20
27
28
+
*If you have copyright or other related text and data mining questions, please contact The University of Alabama Libraries or your respective library/institution.*
21
29
22
-
*These recipe examples were tested on February 7, 2025.*
30
+
*These recipe examples were tested on October 27, 2025.*
23
31
24
32
## Setup
25
33
26
34
### Import Libraries
27
35
28
-
```r
36
+
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()`.
37
+
38
+
- <ahref="https://cran.r-project.org/web/packages/httr/index.html"target="_blank">httr: Tools for Working with URLs and HTTP</a>
39
+
40
+
We load the libraries used in this tutorial below:
41
+
42
+
43
+
```r
29
44
library(httr)
30
45
```
31
46
32
47
### Import API Key
33
48
34
-
An API key is required to access the ScienceDirect API. Registration is available on the [Elsevier developer portal](https://dev.elsevier.com/). The key is imported from an environment variable below:
49
+
An API key is required for to access the ScienceDirect API. You can sign up for one at <ahref="https://dev.elsevier.com/"target="_blank">Elsevier developer portal</a>.
50
+
51
+
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.
35
52
36
-
```r
37
-
myAPIKey<- Sys.getenv("sciencedirect_key")
53
+
```text
54
+
SCIENCE_DIRECT_API_KEY="PUT_YOUR_API_KEY_HERE"
55
+
```
56
+
57
+
Below, we can test to whether the key was successfully imported.
58
+
59
+
60
+
```r
61
+
if (nzchar(Sys.getenv("SCIENCE_DIRECT_API_KEY"))) {
62
+
print("API key successfully loaded.")
63
+
} else {
64
+
warning("API key not found or is empty.")
65
+
}
66
+
```
67
+
68
+
```
69
+
## [1] "API key successfully loaded."
38
70
```
39
71
40
72
### Identifier Note
@@ -43,41 +75,51 @@ We will use DOIs as the article identifiers. See our Crossref and Scopus API tut
0 commit comments