Skip to content

Commit

Permalink
wrap cr_works
Browse files Browse the repository at this point in the history
  • Loading branch information
maxheld83 committed Mar 4, 2021
1 parent 5235d75 commit d0bf62c
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
22 changes: 22 additions & 0 deletions R/import.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,25 @@ get_cr_md <- function(dois,
}
out
}

#' Get Crossref Works
#'
#' Type-/length-stable, defensive and cached variant of [rcrossref::cr_works()].
#'
#' @details
#' This wrapper changes the underlying behavior as follows:
#' - vectorised by [purrr::map_dfr()]
#'
#' @inheritParams biblids::as_doi
#' @inheritDotParams rcrossref::cr_works
#' @family import
#' @keywords internal
cr_works2 <- function(x, ...) {
x <- biblids::as_doi(x)
# remove this hackfix https://github.com/subugoe/metacheck/issues/182
x <- as.character(x)
res <- purrr::map_dfr(.x = as.character(x), function(x) {
rcrossref::cr_works(x)[["data"]]
})
res
}
109 changes: 109 additions & 0 deletions man/cr_works2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_cr_md.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/pretest.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/testthat/test-import.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test_that("Crossref metadata can be read in", {
dois <- tu_dois()[2:5]
res <- cr_works2(dois)
expect_equal(nrow(res), length(dois))
# testthat does not seem to know about vctrs equality
# https://github.com/r-lib/testthat/issues/1349
expect_true(all(biblids::as_doi(res$doi) == biblids::as_doi(dois)))
})

0 comments on commit d0bf62c

Please sign in to comment.