Skip to content

Commit d3e3f8b

Browse files
committed
add tests for cr_abstract; tweak cr_Abstract egs
1 parent f76f3be commit d3e3f8b

File tree

4 files changed

+175
-9
lines changed

4 files changed

+175
-9
lines changed

R/cr_abstract.R

+6-9
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,21 @@
55
#' @param ... Named parameters passed on to \code{\link[crul]{HttpClient}}
66
#' @examples \dontrun{
77
#' # abstract found
8-
#' cr_abstract(doi = '10.1109/TASC.2010.2088091')
8+
#' cr_abstract('10.1109/TASC.2010.2088091')
9+
#' cr_abstract("10.1175//2572.1")
10+
#' cr_abstract("10.1182/blood.v16.1.1039.1039")
911
#'
1012
#' # doi not found
1113
#' # cr_abstract(doi = '10.5284/1011335')
1214
#'
13-
#' # abstract not found, throws warning
15+
#' # abstract not found, throws error
1416
#' # cr_abstract(doi = '10.1126/science.169.3946.635')
15-
#' # cr_abstract(doi = '10.1371/journal.pone.0033693')
16-
#' # cr_abstract(doi = '10.1007/12080.1874-1746')
1717
#'
18+
#' # a random DOI
1819
#' # cr_abstract(cr_r(1))
19-
#'
20-
#' # loop through many DOIs, allowing for failures
21-
#' dois <- cr_r(10, filter = c(has_abstract = TRUE))
22-
#' res <- lapply(dois, function(z) tryCatch(cr_abstract(z), error = function(e) e))
2320
#' }
2421
cr_abstract<-function(doi, ...) {
25-
url<- paste0('http://api.crossref.org/works/', doi, '.xml')
22+
url<- paste0('https://api.crossref.org/works/', doi, '.xml')
2623
cli<-crul::HttpClient$new(
2724
url=url,
2825
opts=list(followlocation=1),

tests/fixtures/cr_abstract.yml

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
http_interactions:
2+
- request:
3+
method: get
4+
uri: https://api.crossref.org/works/10.1175//2572.1.xml
5+
body:
6+
encoding: ''
7+
string: ''
8+
headers:
9+
Accept-Encoding: gzip, deflate
10+
Accept: application/json, text/xml, application/xml, */*
11+
User-Agent: r-curl/4.3 crul/1.0.0 rOpenSci(rcrossref/1.1.0) (mailto:<crossref_email>)
12+
X-USER-AGENT: r-curl/4.3 crul/1.0.0 rOpenSci(rcrossref/1.1.0) (mailto:<crossref_email>)
13+
response:
14+
status:
15+
status_code: '200'
16+
message: OK
17+
explanation: Request fulfilled, document follows
18+
headers:
19+
status: HTTP/1.1 200 OK
20+
link: <http://dx.doi.org/10.1175//2572.1>; rel="canonical", <http://journals.ametsoc.org/mwr/article-pdf/131/8/1895/4208740/_2572_1.pdf>;
21+
version="vor"; type="application/pdf"; rel="item", <http://journals.ametsoc.org/mwr/article-pdf/131/8/1895/4208740/_2572_1.pdf>;
22+
version="vor"; rel="item"
23+
access-control-allow-origin: '*'
24+
access-control-allow-headers: X-Requested-With
25+
content-length: '7060'
26+
server: http-kit
27+
date: Fri, 02 Oct 2020 15:54:21 GMT
28+
x-rate-limit-limit: '50'
29+
x-rate-limit-interval: 1s
30+
connection: close
31+
body:
32+
encoding: UTF-8
33+
file: no
34+
string: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<crossref_result xmlns=\"http://www.crossref.org/qrschema/3.0\"
35+
version=\"3.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.crossref.org/qrschema/3.0
36+
http://www.crossref.org/schemas/crossref_query_output3.0.xsd\">\r\n <query_result>\r\n
37+
\ <head>\r\n <doi_batch_id>none</doi_batch_id>\r\n </head>\r\n <body>\r\n
38+
\ <query status=\"resolved\">\r\n <doi type=\"journal_article\">10.1175//2572.1</doi>\r\n
39+
\ <crm-item name=\"publisher-name\" type=\"string\">American Meteorological
40+
Society</crm-item>\r\n <crm-item name=\"prefix-name\" type=\"string\">American
41+
Meteorological Society</crm-item>\r\n <crm-item name=\"member-id\"
42+
type=\"number\">12</crm-item>\r\n <crm-item name=\"citation-id\" type=\"number\">8407024</crm-item>\r\n
43+
\ <crm-item name=\"journal-id\" type=\"number\">5839</crm-item>\r\n
44+
\ <crm-item name=\"deposit-timestamp\" type=\"number\">2020061721302561500</crm-item>\r\n
45+
\ <crm-item name=\"owner-prefix\" type=\"string\">10.1175</crm-item>\r\n
46+
\ <crm-item name=\"last-update\" type=\"date\">2020-06-18T01:31:13Z</crm-item>\r\n
47+
\ <crm-item name=\"created\" type=\"date\">2003-07-25T16:26:33Z</crm-item>\r\n
48+
\ <crm-item name=\"citedby-count\" type=\"number\">19</crm-item>\r\n
49+
\ <doi_record>\r\n <crossref xmlns=\"http://www.crossref.org/xschema/1.1\"
50+
xsi:schemaLocation=\"http://www.crossref.org/xschema/1.1 http://doi.crossref.org/schemas/unixref1.1.xsd\">\r\n
51+
\ <journal>\r\n <journal_metadata language=\"en\">\r\n
52+
\ <full_title>Monthly Weather Review</full_title>\r\n <issn
53+
media_type=\"electronic\">1520-0493</issn>\r\n <issn media_type=\"print\">0027-0644</issn>\r\n
54+
\ </journal_metadata>\r\n <journal_issue>\r\n <publication_date
55+
media_type=\"print\">\r\n <month>08</month>\r\n <day>01</day>\r\n
56+
\ <year>2003</year>\r\n </publication_date>\r\n
57+
\ <journal_volume>\r\n <volume>131</volume>\r\n
58+
\ </journal_volume>\r\n <issue>8</issue>\r\n
59+
\ </journal_issue>\r\n <journal_article publication_type=\"full_text\">\r\n
60+
\ <titles>\r\n <title>A Numerical Study of
61+
Early Summer Regional Climate and Weather over LSA-East. Part I: Model Implementation
62+
and Verification</title>\r\n </titles>\r\n <contributors>\r\n
63+
\ <person_name sequence=\"first\" contributor_role=\"author\">\r\n
64+
\ <given_name>Da-Lin</given_name>\r\n <surname>Zhang</surname>\r\n
65+
\ <affiliation>Department of Meteorology, University of
66+
Maryland, College Park, College Park, Maryland</affiliation>\r\n </person_name>\r\n
67+
\ <person_name sequence=\"first\" contributor_role=\"author\">\r\n
68+
\ <given_name>Wei-Zhong</given_name>\r\n <surname>Zheng</surname>\r\n
69+
\ <affiliation>Department of Meteorology, University of
70+
Maryland, College Park, College Park, Maryland</affiliation>\r\n </person_name>\r\n
71+
\ <person_name sequence=\"additional\" contributor_role=\"author\">\r\n
72+
\ <given_name>Yong-Kang</given_name>\r\n <surname>Xue</surname>\r\n
73+
\ <affiliation>Department of Geography, University of California,
74+
Los Angeles, Los Angeles, California</affiliation>\r\n </person_name>\r\n
75+
\ </contributors>\r\n <jats:abstract xmlns:jats=\"http://www.ncbi.nlm.nih.gov/JATS1\">\r\n
76+
\ <jats:title>Abstract</jats:title>\r\n <jats:p>The
77+
Pennsylvania State University–NCAR Mesoscale Model (MM5) and a simplified
78+
simple biosphere (SSiB) scheme are modified and then coupled to study various
79+
regional climate and weather problems. These modifications include correcting
80+
the moisture and cloud hydrometeor fields to ensure the mass conservation;
81+
incorporating the effects of dissipative heating to ensure total energy conservation;
82+
decoupling soil and vegetation types in specifying various surface parameters;
83+
and eliminating the shortwave radiation reaching the surface at points where
84+
deep convection occurs.</jats:p>\r\n <jats:p>A 30-day integration
85+
of June 1998 over the Midwest states was used to examine the model's capability
86+
in capturing the observed wet regional climate and the passage of several
87+
mesoscale weather events. It is found that the coupled model reproduces the
88+
distribution and magnitude of monthly accumulated precipitation, the time
89+
series of area-integrated precipitation, surface pressures, and diurnal changes
90+
in surface temperatures, low-level winds and precipitation, as well as the
91+
evolution of precipitation systems across the central United States. In particular,
92+
the model reproduces well many daily weather events, including the distribution
93+
and intensity of low-level temperature and pressure perturbations and precipitation,
94+
even up to a month. The results suggest that the daily temperature, clouds,
95+
and precipitation events from the weekly to monthly scales, as well as their
96+
associated regional climate phenomena, could be reasonably simulated if the
97+
surface, boundary layer, radiation, and convective processes are realistically
98+
parameterized, and the large-scale forcing could be reasonably provided by
99+
general circulation models.</jats:p>\r\n </jats:abstract>\r\n
100+
\ <publication_date media_type=\"print\">\r\n <month>08</month>\r\n
101+
\ <day>01</day>\r\n <year>2003</year>\r\n
102+
\ </publication_date>\r\n <publication_date media_type=\"online\">\r\n
103+
\ <month>08</month>\r\n <day>01</day>\r\n
104+
\ <year>2003</year>\r\n </publication_date>\r\n
105+
\ <pages>\r\n <first_page>1895</first_page>\r\n
106+
\ <last_page>1909</last_page>\r\n </pages>\r\n
107+
\ <doi_data>\r\n <doi>10.1175//2572.1</doi>\r\n
108+
\ <resource>https://journals.ametsoc.org/mwr/article/131/8/1895/67449/A-Numerical-Study-of-Early-Summer-Regional-Climate</resource>\r\n
109+
\ <collection property=\"crawler-based\">\r\n <item
110+
crawler=\"iParadigms\">\r\n <resource>http://journals.ametsoc.org/mwr/article-pdf/131/8/1895/4208740/_2572_1.pdf</resource>\r\n
111+
\ </item>\r\n </collection>\r\n <collection
112+
property=\"syndication\">\r\n <item>\r\n <resource
113+
content_version=\"vor\" mime_type=\"application/pdf\">http://journals.ametsoc.org/mwr/article-pdf/131/8/1895/4208740/_2572_1.pdf</resource>\r\n
114+
\ </item>\r\n </collection>\r\n </doi_data>\r\n
115+
\ </journal_article>\r\n </journal>\r\n </crossref>\r\n
116+
\ </doi_record>\r\n </query>\r\n </body>\r\n </query_result>\r\n</crossref_result>"
117+
recorded_at: 2020-10-02 15:54:20 GMT
118+
recorded_with: vcr/0.5.4, webmockr/0.7.0
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
http_interactions:
2+
- request:
3+
method: get
4+
uri: https://api.crossref.org/works/10.5284/1011335.xml
5+
body:
6+
encoding: ''
7+
string: ''
8+
headers:
9+
Accept-Encoding: gzip, deflate
10+
Accept: application/json, text/xml, application/xml, */*
11+
User-Agent: r-curl/4.3 crul/1.0.0 rOpenSci(rcrossref/1.1.0) (mailto:<crossref_email>)
12+
X-USER-AGENT: r-curl/4.3 crul/1.0.0 rOpenSci(rcrossref/1.1.0) (mailto:<crossref_email>)
13+
response:
14+
status:
15+
status_code: '404'
16+
message: Not Found
17+
explanation: Nothing matches the given URI
18+
headers:
19+
status: HTTP/1.1 404 Not Found
20+
content-type: text/plain
21+
access-control-allow-origin: '*'
22+
access-control-allow-headers: X-Requested-With
23+
content-length: '19'
24+
server: http-kit
25+
date: Fri, 02 Oct 2020 15:55:02 GMT
26+
x-rate-limit-limit: '50'
27+
x-rate-limit-interval: 1s
28+
connection: close
29+
body:
30+
encoding: UTF-8
31+
file: no
32+
string: Resource not found.
33+
recorded_at: 2020-10-02 15:55:01 GMT
34+
recorded_with: vcr/0.5.4, webmockr/0.7.0

tests/testthat/test-cr_abstract.R

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
skip_on_cran()
2+
3+
test_that("cr_abstract", {
4+
vcr::use_cassette("cr_abstract", {
5+
b<- cr_abstract("10.1175//2572.1")
6+
})
7+
8+
expect_is(b, "character")
9+
expect_match(b, "University")
10+
expect_gt(nchar(b), 1000L)
11+
})
12+
13+
test_that("cr_abstract not found", {
14+
vcr::use_cassette("cr_abstract_not_found", {
15+
expect_error(cr_abstract('10.5284/1011335'))
16+
})
17+
})

0 commit comments

Comments
 (0)
close