Skip to content

Commit 7ab29a3

Browse files
committed
Update Wiley TDM in R recipe
1 parent cace395 commit 7ab29a3

1 file changed

Lines changed: 35 additions & 18 deletions

File tree

src/r/wiley-tdm.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "wiley-tdm"
2+
title: "Wiley Text and Data Mining (TDM) in R"
33
output:
44
html_document:
55
keep_md: true
@@ -9,26 +9,32 @@ output:
99

1010
by Michael T. Moen
1111

12-
This tutorial is designed to support academic research. Please consult your institution’s library or legal office regarding its Text and Data Mining license agreement with Wiley.
12+
The Wiley Text and Data Mining (TDM) API allows users to retrieve the full-text articles of subscribed Wiley content in PDF form. TDM use is for non-commercial scholarly research, see terms and restrictions in below links.
1313

14-
### Documentation
15-
- [Wiley Text and Data Mining](https://onlinelibrary.wiley.com/library-info/resources/text-and-datamining)
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 Wiley.*
1615

17-
### Terms of Use
18-
- [Wiley Text and Data Mining Agreement](https://onlinelibrary.wiley.com/library-info/resources/text-and-datamining#accordionHeader-3)
16+
Please see the following resources for more information on API usage:
1917

20-
### Data Reuse
21-
- [Service Name] Data Reuse *(link to be provided by the service)*
18+
- Documentation
19+
- <a href="https://onlinelibrary.wiley.com/library-info/resources/text-and-datamining" target="_blank">Wiley Text and Data Mining</a>
20+
- Terms
21+
- <a href="https://onlinelibrary.wiley.com/library-info/resources/text-and-datamining#accordionHeader-3" target="_blank">Wiley Text and Data Mining Agreement</a>
22+
- Data Reuse
23+
- <a href="https://onlinelibrary.wiley.com/library-info/resources/text-and-datamining#accordionHeader-3" target="_blank">Wiley TDM Data Reuse</a> (see sections 4 and 5 of Text and Data Mining Agreement)
2224

23-
*These recipe examples were tested on February 12, 2025.*
25+
*These recipe examples were tested on October 27, 2025.*
2426

2527
**_NOTE:_** The Wiley TDM API limits requests to a maximum of 3 requests per second.
2628

2729
## Setup
2830

2931
### Import Libraries
3032

31-
This tutorial uses the following libraries:
33+
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()`.
34+
35+
- <a href="https://cran.r-project.org/web/packages/httr/index.html" target="_blank">httr: Tools for Working with URLs and HTTP</a>
36+
37+
We load the libraries used in this tutorial below:
3238

3339

3440
``` r
@@ -37,14 +43,27 @@ library(httr)
3743

3844
### Text and Data Mining Token
3945

40-
A token is required to access the Wiley TDM API. Sign up can be found [here](https://onlinelibrary.wiley.com/library-info/resources/text-and-datamining#accordionHeader-2). Import your token below:
46+
A token is required for text and data mining with Wiley. You can sign up for one on the <a href="https://onlinelibrary.wiley.com/library-info/resources/text-and-datamining#accordionHeader-2" target="_blank">Wiley Text and Data Mining page</a>.
47+
48+
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.
49+
50+
```text
51+
WILEY_TDM_TOKEN="PUT_YOUR_TOKEN_HERE"
52+
```
53+
54+
Below, we can test to whether the key was successfully imported.
4155

4256

4357
``` r
44-
wiley_token <- Sys.getenv("wiley_token")
58+
if (nzchar(Sys.getenv("WILEY_TDM_TOKEN"))) {
59+
print("API key successfully loaded.")
60+
} else {
61+
warning("API key not found or is empty.")
62+
}
63+
```
4564

46-
# The token will be sent as a header in the API calls
47-
headers <- add_headers("Wiley-TDM-Client-Token" = wiley_token)
65+
```
66+
## [1] "API key successfully loaded."
4867
```
4968

5069
## 1. Retrieve full-text of an article
@@ -59,14 +78,13 @@ In the first example, we download the full-text of the article with the DOI "10.
5978
doi <- "10.1002/net.22207"
6079
url <- paste0("https://api.wiley.com/onlinelibrary/tdm/v1/articles/", doi)
6180

62-
response <- GET(url, headers)
81+
response <- GET(url, add_headers("Wiley-TDM-Client-Token" = Sys.getenv("WILEY_TDM_TOKEN")))
6382

6483
if (status_code(response) == 200) {
6584
# Download if status code indicates success
6685
filename <- paste0(gsub("/", "_", doi), ".pdf")
6786
writeBin(content(response, "raw"), filename)
6887
cat(paste0(filename, " downloaded successfully\n"))
69-
7088
} else {
7189
# Print status code if unsuccessful
7290
cat(paste0("Failed to download PDF. Status code: ", status_code(response), "\n"))
@@ -96,14 +114,13 @@ dois <- c(
96114
# Loop through DOIs and download each article
97115
for (doi in dois) {
98116
url <- paste0("https://api.wiley.com/onlinelibrary/tdm/v1/articles/", doi)
99-
response <- GET(url, headers)
117+
response <- GET(url, add_headers("Wiley-TDM-Client-Token" = Sys.getenv("WILEY_TDM_TOKEN")))
100118

101119
if (status_code(response) == 200) {
102120
# Download if status code indicates success
103121
filename <- paste0(gsub("/", "_", doi), ".pdf")
104122
writeBin(content(response, "raw"), filename)
105123
cat(paste0(filename, " downloaded successfully\n"))
106-
107124
} else {
108125
# Print status code if unsuccessful
109126
cat(paste0("Failed to download PDF. Status code: ", status_code(response), "\n"))

0 commit comments

Comments
 (0)