Skip to content

Commit

Permalink
start refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
maxheld83 committed Dec 18, 2020
1 parent a72f1ee commit c3a39b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
21 changes: 0 additions & 21 deletions R/cr_md_fetch.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
#' Get Crossref metadata from API
#'
#' @param dois character vector with DOIs
#' @param .progress show progress bar, use "none" if no progress should be
#' displayed
#'
#' @importFrom rcrossref cr_works
#'
#' @export
get_cr_md <- function(dois, .progress = "text") {
checkmate::assert_character(dois, any.missing = FALSE, unique = TRUE)
tt <- rcrossref::cr_works(dois = dois, .progress = .progress)[["data"]]
if (!is.null(tt)) {
out <- tt %>%
mutate(issued = lubridate::parse_date_time(issued, c("y", "ymd", "ym"))) %>%
mutate(issued_year = lubridate::year(issued))
} else {
out <- NULL
}
out
}
#' License checker
#'
#' Retrieves records from Crossref metadata where
Expand Down
23 changes: 23 additions & 0 deletions R/import.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#' Get Crossref metadata from API
#'
#' @param dois character vector with DOIs
#' @param .progress show progress bar, use "none" if no progress should be
#' displayed
#'
#' @family ETL import
#' @export
get_cr_md <- function(dois, .progress = "text") {
# TODO this can be replaced by class validation
# TODO not sure where the best place for the unique assertion is
checkmate::assert_character(dois, any.missing = FALSE, unique = TRUE)

tt <- rcrossref::cr_works(dois = dois, .progress = .progress)[["data"]]
if (!is.null(tt)) {
out <- tt %>%
mutate(issued = lubridate::parse_date_time(issued, c("y", "ymd", "ym"))) %>%
mutate(issued_year = lubridate::year(issued))
} else {
out <- NULL
}
out
}

0 comments on commit c3a39b9

Please sign in to comment.