Skip to content

Commit

Permalink
Merge pull request #190 from ropensci/skip-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
massimoaria authored Nov 11, 2023
2 parents 32855b6 + 1a8ed2c commit ccb6c29
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 35 deletions.
48 changes: 25 additions & 23 deletions R/oa2df.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ oa2df <- function(data, entity, options = NULL, count_only = FALSE, group_by = N
#'
#' @param abstract Logical. If TRUE, the function returns also the abstract of each item.
#' Defaults to TRUE.
#' @param pb Progress bar object. If verbose, computed from `oa_progress`.
#' NULL otherwise.
#' @inheritParams oa2df
#'
#' @return a data.frame.
Expand Down Expand Up @@ -131,7 +133,8 @@ oa2df <- function(data, entity, options = NULL, count_only = FALSE, group_by = N
#'
#' @export
#'
works2df <- function(data, abstract = TRUE, verbose = TRUE) {
works2df <- function(data, abstract = TRUE, verbose = TRUE,
pb = if (verbose) oa_progress(length(data)) else NULL) {

col_order <- c(
"id", "display_name", "author", "ab", "publication_date", "relevance_score",
Expand Down Expand Up @@ -181,7 +184,6 @@ works2df <- function(data, abstract = TRUE, verbose = TRUE) {
empty_inst <- empty_list(inst_cols)

n <- length(data)
pb <- oa_progress(n)
list_df <- vector(mode = "list", length = n)

for (i in seq.int(n)) {
Expand Down Expand Up @@ -271,7 +273,7 @@ abstract_build <- function(ab) {
#' It converts bibliographic collection of authors' records gathered from OpenAlex database \href{https://openalex.org/}{https://openalex.org/} into data frame.
#' The function converts a list of authors' records obtained using \code{oa_request} into a data frame/tibble.
#'
#' @inheritParams oa2df
#' @inheritParams works2df
#'
#' @return a data.frame.
#'
Expand Down Expand Up @@ -306,9 +308,9 @@ abstract_build <- function(ab) {
#' }
#'
#' @export
authors2df <- function(data, verbose = TRUE) {
authors2df <- function(data, verbose = TRUE,
pb = if (verbose) oa_progress(length(data)) else NULL) {
n <- length(data)
pb <- oa_progress(n)
list_df <- vector(mode = "list", length = n)

inst_cols <- c("id", "display_name", "ror", "country_code", "type", "lineage")
Expand Down Expand Up @@ -375,7 +377,7 @@ authors2df <- function(data, verbose = TRUE) {
#' It converts bibliographic collection of institutions' records gathered from OpenAlex database \href{https://openalex.org/}{https://openalex.org/} into data frame.
#' The function converts a list of institutions' records obtained using \code{oa_request} into a data frame/tibble.
#'
#' @inheritParams oa2df
#' @inheritParams works2df
#'
#' @return a data.frame.
#'
Expand Down Expand Up @@ -403,9 +405,9 @@ authors2df <- function(data, verbose = TRUE) {
#' }
#'
#' @export
institutions2df <- function(data, verbose = TRUE) {
institutions2df <- function(data, verbose = TRUE,
pb = if (verbose) oa_progress(length(data)) else NULL) {
n <- length(data)
pb <- oa_progress(n)
list_df <- vector(mode = "list", length = n)

institution_process <- tibble::tribble(
Expand Down Expand Up @@ -476,7 +478,7 @@ institutions2df <- function(data, verbose = TRUE) {
#' It converts bibliographic collection of venues' records gathered from OpenAlex database \href{https://openalex.org/}{https://openalex.org/} into data frame.
#' The function converts a list of venues' records obtained using \code{oa_request} into a data frame/tibble.
#'
#' @inheritParams oa2df
#' @inheritParams works2df
#'
#' @return a data.frame.
#'
Expand Down Expand Up @@ -506,10 +508,10 @@ institutions2df <- function(data, verbose = TRUE) {
#' }
#'
#' @export
venues2df <- function(data, verbose = TRUE) {
venues2df <- function(data, verbose = TRUE,
pb = if (verbose) oa_progress(length(data)) else NULL) {

n <- length(data)
pb <- oa_progress(n)
list_df <- vector(mode = "list", length = n)
venue_process <- tibble::tribble(
~type, ~field,
Expand Down Expand Up @@ -562,7 +564,7 @@ venues2df <- function(data, verbose = TRUE) {
#' It converts bibliographic collection of concepts' records gathered from OpenAlex database \href{https://openalex.org/}{https://openalex.org/} into data frame.
#' The function converts a list of concepts' records obtained using \code{oa_request} into a data frame/tibble.
#'
#' @inheritParams oa2df
#' @inheritParams works2df
#'
#' @return a data.frame.
#'
Expand Down Expand Up @@ -592,7 +594,8 @@ venues2df <- function(data, verbose = TRUE) {
#' }
#'
#' @export
concepts2df <- function(data, verbose = TRUE) {
concepts2df <- function(data, verbose = TRUE,
pb = if (verbose) oa_progress(length(data)) else NULL) {

concept_process <- tibble::tribble(
~type, ~field,
Expand All @@ -614,7 +617,6 @@ concepts2df <- function(data, verbose = TRUE) {
)

n <- length(data)
pb <- oa_progress(n)
list_df <- vector(mode = "list", length = n)

for (i in seq.int(n)) {
Expand Down Expand Up @@ -661,7 +663,7 @@ concepts2df <- function(data, verbose = TRUE) {
#' It converts bibliographic collection of funders' records gathered from OpenAlex database \href{https://openalex.org/}{https://openalex.org/} into data frame.
#' The function converts a list of funders' records obtained using \code{oa_request} into a data frame/tibble.
#'
#' @inheritParams oa2df
#' @inheritParams works2df
#'
#' @return a data.frame.
#'
Expand All @@ -683,7 +685,8 @@ concepts2df <- function(data, verbose = TRUE) {
#' }
#'
#' @export
funders2df <- function(data, verbose = TRUE) {
funders2df <- function(data, verbose = TRUE,
pb = if (verbose) oa_progress(length(data)) else NULL) {

funder_process <- tibble::tribble(
~type, ~field,
Expand All @@ -707,7 +710,6 @@ funders2df <- function(data, verbose = TRUE) {
)

n <- length(data)
pb <- oa_progress(n)
list_df <- vector(mode = "list", length = n)

for (i in seq.int(n)) {
Expand Down Expand Up @@ -735,7 +737,7 @@ funders2df <- function(data, verbose = TRUE) {
#' It converts bibliographic collection of sources' records gathered from OpenAlex database \href{https://openalex.org/}{https://openalex.org/} into data frame.
#' The function converts a list of sources' records obtained using \code{oa_request} into a data frame/tibble.
#'
#' @inheritParams oa2df
#' @inheritParams works2df
#'
#' @return a data.frame.
#'
Expand All @@ -757,7 +759,8 @@ funders2df <- function(data, verbose = TRUE) {
#' }
#'
#' @export
sources2df <- function(data, verbose = TRUE) {
sources2df <- function(data, verbose = TRUE,
pb = if (verbose) oa_progress(length(data)) else NULL) {

source_process <- tibble::tribble(
~type, ~field,
Expand Down Expand Up @@ -791,7 +794,6 @@ sources2df <- function(data, verbose = TRUE) {
)

n <- length(data)
pb <- oa_progress(n)
list_df <- vector(mode = "list", length = n)

for (i in seq.int(n)) {
Expand Down Expand Up @@ -819,7 +821,7 @@ sources2df <- function(data, verbose = TRUE) {
#' It converts bibliographic collection of publishers' records gathered from OpenAlex database \href{https://openalex.org/}{https://openalex.org/} into data frame.
#' The function converts a list of publishers' records obtained using \code{oa_request} into a data frame/tibble.
#'
#' @inheritParams oa2df
#' @inheritParams works2df
#'
#' @return a data.frame.
#'
Expand All @@ -841,7 +843,8 @@ sources2df <- function(data, verbose = TRUE) {
#' }
#'
#' @export
publishers2df <- function(data, verbose = TRUE) {
publishers2df <- function(data, verbose = TRUE,
pb = if (verbose) oa_progress(length(data)) else NULL) {

publisher_process <- tibble::tribble(
~type, ~field,
Expand All @@ -867,7 +870,6 @@ publishers2df <- function(data, verbose = TRUE) {
)

n <- length(data)
pb <- oa_progress(n)
list_df <- vector(mode = "list", length = n)

for (i in seq.int(n)) {
Expand Down
3 changes: 1 addition & 2 deletions R/oa_fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,9 @@ oa_request <- function(query_url,
"Getting ", n_pages, pg_plural, " of results",
" with a total of ", n_items, " records..."
)
pb <- oa_progress(n = n_pages, text = "OpenAlex downloading")
}

pb <- oa_progress(n = n_pages, text = "OpenAlex downloading")

# Setting items per page
query_ls[["per-page"]] <- per_page

Expand Down
9 changes: 7 additions & 2 deletions R/oa_ngrams.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ oa_ngrams <- function(works_identifier, ...,
n <- length(query_urls)

#ngrams_failed_template <- data.frame(id = NA, doi = NA, count = NA, ngrams = I(list(NULL)))
pb <- oa_progress(n)
if (verbose) {
pb <- oa_progress(n)
}

# Fetch
if (utils::packageVersion("curl") >= "5") {
Expand All @@ -91,7 +93,10 @@ oa_ngrams <- function(works_identifier, ...,
options("oa_ngrams.message.curlv5" = FALSE)
}
# Serial fetch
pb_dl <- oa_progress(n, "OpenAlex downloading")
if (verbose) {
pb_dl <- oa_progress(n, "OpenAlex downloading")
}

ngrams_list <- vector("list", n)
for (i in seq_len(n)) {
if (verbose) pb_dl$tick()
Expand Down
9 changes: 8 additions & 1 deletion man/authors2df.Rd

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

9 changes: 8 additions & 1 deletion man/concepts2df.Rd

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

9 changes: 8 additions & 1 deletion man/funders2df.Rd

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

9 changes: 8 additions & 1 deletion man/institutions2df.Rd

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

9 changes: 8 additions & 1 deletion man/publishers2df.Rd

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

9 changes: 8 additions & 1 deletion man/sources2df.Rd

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

9 changes: 8 additions & 1 deletion man/venues2df.Rd

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

Loading

0 comments on commit ccb6c29

Please sign in to comment.