Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit56fbb9f

Browse files
committed
Remove all types of whitespace#31
1 parent601ec14 commit56fbb9f

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

‎R/oadoi_fetch.r‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,15 @@ oadoi_fetch <-
183183
#' }
184184
#' @export
185185
oadoi_fetch_<-function(doi=NULL,email=NULL) {
186+
check_wsp_dois(doi)
186187
u<-httr::modify_url(
187188
oadoi_baseurl(),
188189
query=list(email=email),
189-
path= c(oadoi_api_version(), trimws(doi))
190+
path= c(oadoi_api_version(),
191+
gsub("[[:space:]]","",doi))
190192
)
191193
# Call Unpaywall Data API
192-
resp<-httr::RETRY("GET",u,ua)
194+
resp<-httr::RETRY("GET",u,ua,httr::timeout(5))
193195

194196
# test for valid json
195197
if (httr::http_type(resp)!="application/json") {

‎R/utils.r‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,14 @@ email_regex <-
3939
# nolint start
4040
"^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z]{2,4})$"
4141
# nolint end
42+
43+
#' White space check
44+
#'
45+
#' @noRd
46+
check_wsp_dois<-function(x) {
47+
wsp_doi<-x[grepl("[[:space:]]",x)]
48+
if (!is.null(wsp_doi))
49+
message(
50+
paste("Removed white space character(s) from:",wsp_doi))
51+
}
52+

‎tests/testthat/test_oadoi_fetch.r‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,15 @@ test_that("emails are validated", {
8686
expect_error(oadoi_fetch("10.1038/ng.3260",email="najko@gnx"))
8787
expect_error(oadoi_fetch("10.1038/ng.3260",email="FOOL"))
8888
})
89+
90+
test_that("oadoi_fetch removes all types of whitespace", {
91+
skip_on_cran()
92+
dois<- c("10.1177/ 0042098012452322",
93+
"10.1038/ng.3260",
94+
" 10. 7717/peerj.2323
95+
")
96+
a<- expect_message(
97+
oadoi_fetch(dois,email="najko.jahn@gmail.com")
98+
)
99+
expect_equal(nrow(a),3)
100+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp