Skip to content

Commit 2f97fa7

Browse files
Complete API transition before v0.9.0 (#108)
2 parents 45a05de + 7d77e78 commit 2f97fa7

Some content is hidden

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

48 files changed

+249
-382
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
22

33
language: R
4+
r:
5+
- release
6+
- devel
47
sudo: false
58
cache: packages
69

@@ -10,3 +13,4 @@ git:
1013
before_install:
1114
- echo "BacDive_email=$ID" > ~/.Renviron
1215
- echo "BacDive_password=$PW" >> ~/.Renviron
16+
- tlmgr install texinfo

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: BacDiveR
22
Title: Programmatic Interface For The DSMZ' Bacterial Diversity Metadatabase
3-
Version: 0.8.0
4-
Date: 2019-01-28
3+
Version: 0.9.0
4+
Date: 2019-04-30
55
Authors@R:
66
person(given = "Katrin",
77
family = "Leinweber",
@@ -20,12 +20,12 @@ BugReports: https://github.com/TIBHannover/BacDiveR/issues
2020
Imports:
2121
httr (>= 1.3.0),
2222
jsonlite (>= 1.5),
23-
purrr (>= 0.2.5),
2423
utils (>= 3.5.0)
2524
Suggests:
2625
ggplot2 (>= 3.0.0),
2726
knitr (>= 1.20),
2827
magrittr (>= 1.5),
28+
purrr (>= 0.2.5),
2929
rmarkdown (>= 1.10),
3030
spelling (>= 1.2),
3131
testthat (>= 2.0.0)

NAMESPACE

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@ export(bd_retrieve)
44
export(bd_retrieve_by_culture)
55
export(bd_retrieve_by_search)
66
export(bd_retrieve_by_sequence)
7-
export(bd_retrieve_data)
87
export(bd_retrieve_taxon)
98
export(prepare_Renviron)
10-
export(retrieve_data)
11-
export(retrieve_search_results)

NEWS.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
All notable changes to this project will be documented in this file.
2-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4-
51
## Unreleased
62

73
### Added
@@ -11,6 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
117
### Fixed
128
### Security
139

10+
## BacDiveR 0.9.0
11+
12+
All notable changes to this project will be documented in this file.
13+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
14+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
15+
16+
### Changed
17+
18+
- NEW API: The deprecations announced in v0.8.0 are now completed: The
19+
`bd_retrieve()` family of functions has replaced `retrieve_data()` and
20+
`retrieve_search_results()` has been renamed to `bd_retrieve_by_search()`,
21+
see #96. **Please update scripts and other downstream code that use BacDiveR.**
22+
- `purrr` is no longer an imported / required dependency, but only suggested
23+
due to use in the [introductory vignette], see #98.
24+
25+
[introductory vignette]: ../articles/BacDive-ing-in.html#extracting-data-fields
26+
27+
28+
## BacDiveR 0.8.1
29+
30+
### Changed
31+
32+
- Warning message about no data being found is more informative now
33+
- Documentation to follow BacDive's database updates
34+
- Use pandoc 2.7.2 to generate the website
35+
1436

1537
## BacDiveR 0.8.0
1638

R/bd_retrieve.R

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#' Retrieve (a) Dataset(s) from BacDive
22
#'
3-
#' This function family replaces the old `retrieve_data(searchTerm = "…", searchType = "…")`
4-
#' function. It still works, but is deprecated and will be removed soon.
5-
#' Please update your scripts to these new functions!
6-
#'
73
#' @param id Mandatory character string or integer. The BacDive strain ID
84
#' whose data you want to retrieve.
95
#'

R/retrieve_search_results.R renamed to R/bd_retrieve_by_search.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
#' @export
2-
retrieve_search_results <- function(queryURL) {
3-
.Deprecated("bd_retrieve_by_search")
4-
bd_retrieve_by_search(queryURL)
5-
}
6-
71
#' Retrieve the Results of an Advanced Search
82
#'
93
#' [BacDive.DSMZ.de/AdvSearch](https://bacdive.dsmz.de/advsearch) returns a
@@ -18,7 +12,15 @@ retrieve_search_results <- function(queryURL) {
1812
#' @export
1913
#'
2014
#' @examples
21-
#' plant_animal_pathogens <- bd_retrieve_by_search(queryURL = "https://bacdive.dsmz.de/advsearch?site=advsearch&searchparams%5B5%5D%5Bsearchterm%5D=1&searchparams%5B157%5D%5Bsearchterm%5D=1&searchparams%5B158%5D%5Bsearchterm%5D=1&advsearch=search")
15+
#' plant_animal_pathogens <-
16+
#' bd_retrieve_by_search(
17+
#' queryURL = paste(
18+
#' "https://bacdive.dsmz.de/advsearch?site=advsearchsearch",
19+
#' "params%5B5%5D%5Bsearchterm%5D=1",
20+
#' "searchparams%5B157%5D%5Bsearchterm%5D=1",
21+
#' "searchparams%5B158%5D%5Bsearchterm%5D=1",
22+
#' "advsearch=search", sep = "&")
23+
#' )
2224
bd_retrieve_by_search <- function(queryURL) {
2325
# guard against other URLs
2426
if (!grepl(pattern = "^https:\\/\\/bacdive\\.dsmz\\.de\\/advsearch", queryURL) |

R/retrieve_data.R renamed to R/bd_retrieve_data.R

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
1-
#' @export
2-
retrieve_data <- function(searchTerm,
3-
searchType = "taxon") {
4-
.Deprecated(
5-
c(
6-
"bd_retrieve_by_culture",
7-
"bd_retrieve_by_sequence",
8-
"bd_retrieve",
9-
"bd_retrieve_taxon"
10-
)
11-
)
12-
13-
# guard against invalid input
14-
searchTerm <- sanitise_term(searchTerm)
1+
#' @keywords internal
2+
bd_retrieve_data <- function(searchTerm, searchType) {
153
searchType <- sanitise_type(searchType)
16-
17-
bd_retrieve_data(searchTerm, searchType)
18-
}
19-
20-
#' @export
21-
bd_retrieve_data <- function(searchTerm, searchType = "taxon") {
22-
23-
# expand taxon/species
24-
if (identical(searchType, "taxon") & grepl("\\s", searchTerm)) {
25-
searchTerm <- sanitise_taxon(searchTerm)
26-
}
4+
searchTerm <- sanitise_term(searchTerm, searchType)
275

286
payload <- download(construct_url(searchTerm, searchType))
297

@@ -43,11 +21,9 @@ bd_retrieve_data <- function(searchTerm, searchType = "taxon") {
4321
}
4422
else if (identical(payload$detail, "Not found")) {
4523
warning(
46-
"BacDive responded: 'Not found' to our query for '",
47-
searchType,
48-
" = ",
49-
searchTerm,
50-
"'. Please double-check both these query parameters, or try https://BacDive.DSMZ.de/AdvSearch"
24+
"BacDive responded: '", payload$detail,
25+
"' to our last search for '", searchTerm,
26+
"'. Please double-check this parameter or try https://TIBHannover.GitHub.io/BacDiveR/articles/pre-configuring-advanced-searches-and-retrieving-the-results.html"
5127
)
5228

5329
list()
@@ -76,15 +52,12 @@ is_results_list <- function(payload) {
7652
}
7753

7854
is_ID_reference <- function(payload) {
79-
all.equal(nrow(payload), ncol(payload), 1) &&
80-
# class(payload) == "data.frame" &&
81-
names(payload) == "url"
82-
# && grepl("https://bacdive.dsmz.de/api/bacdive/bacdive_id/\\d+/",
83-
# payload$url)
55+
all.equal(nrow(payload), ncol(payload), 1) &
56+
"url" %in% names(payload)
8457
}
8558

8659

87-
sanitise_term <- function(searchTerm) {
60+
sanitise_term <- function(searchTerm, searchType) {
8861
if (grepl(
8962
pattern = "[^[:alnum:] ]",
9063
x = searchTerm,
@@ -94,6 +67,9 @@ sanitise_term <- function(searchTerm) {
9467
stop(
9568
"Illegal character detected! My apologies, but your search can only contain letters, numbers and white-space. Abbreviating genus names (e.g. 'B. subtilis') is not supported. Please spell out your searchTerm ('Bacillus subtilis'), don't use any 'special' characters and try again."
9669
)
70+
} else if (identical(searchType, "taxon") & grepl("\\s", searchTerm)) {
71+
gsub(pattern = "\\s", replacement = "/", searchTerm)
72+
# expand "Taxon species" to "taxon/species"
9773
} else {
9874
searchTerm
9975
}
@@ -114,6 +90,16 @@ sanitise_type <- function(searchType) {
11490
}
11591

11692

117-
sanitise_taxon <- function(searchTerm) {
118-
gsub(pattern = "\\s", replacement = "/", searchTerm)
93+
construct_url <- function(searchTerm,
94+
searchType = "bacdive_id") {
95+
utils::URLencode(
96+
paste0(
97+
"https://bacdive.dsmz.de/api/bacdive/",
98+
searchType,
99+
"/",
100+
searchTerm,
101+
"/",
102+
"?format=json"
103+
)
104+
)
119105
}

R/bd_retrieve_taxon.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#' like "B. halotolerans" are not allowed!
44
#' @export
55
#' @examples
6-
#' datasets_Bh <- bd_retrieve_taxon(name = "Bacillus halotolerans")
7-
#' datasets_Thh <- bd_retrieve_taxon(name = "Tetragenococcus halophilus halophilus")
6+
#' datasets_Bh <- bd_retrieve_taxon(name = "Bacillus halotolerans")
7+
#' datasets_Thh <- bd_retrieve_taxon(name = "Tetragenococcus halophilus halophilus")
88
bd_retrieve_taxon <- function(name) {
99
bd_retrieve_data(searchTerm = name, searchType = "taxon")
1010
}

R/util-aggregate_datasets.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ aggregate_datasets <- function(payload, from_IDs = FALSE) {
22
if (from_IDs) {
33
warn_slow_download(length(payload))
44
IDs <- payload
5-
URLs <- purrr::map_chr(.x = IDs, .f = construct_url)
5+
URLs <- lapply(X = IDs, FUN = construct_url)
66
}
77
else {
88
warn_slow_download(payload$count)
@@ -17,7 +17,7 @@ aggregate_datasets <- function(payload, from_IDs = FALSE) {
1717
max(as.integer(IDs)),
1818
" (but not necessarily contiguously): "
1919
)
20-
taxon_data <- purrr::map(URLs, download)
20+
taxon_data <- lapply(X = URLs, download)
2121
names(taxon_data) <- IDs
2222

2323
taxon_data

R/util-construct_url.R

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

0 commit comments

Comments
 (0)