Skip to content

Commit

Permalink
Merge pull request #222 from ropensci/remove-venues
Browse files Browse the repository at this point in the history
Remove venues
  • Loading branch information
trangdata authored Mar 24, 2024
2 parents 558581c + 955e21d commit 71adc6d
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 159 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ export(show_authors)
export(show_works)
export(snowball2df)
export(sources2df)
export(venues2df)
export(works2df)
importFrom(stats,setNames)
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and returns one record at a time.
`oa_fetch` or `oa_request`.
* Improve `oa_snowball` performance.
* Allowed the use of `options$sample` with `search`.
* "venues"" is no longer a valid value for `entity`. Use "sources" instead.

# openalexR 1.2.2
* solved issue with CRAN test
Expand Down
90 changes: 2 additions & 88 deletions R/oa2df.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#'
#' @param data List. Output of \code{oa_request}.
#' @param entity Character. Scholarly entity of the search.
#' The argument can be one of c("works", "authors", "venues", "institutions", "concepts").
#' The argument can be one of
#' c("works", "authors", "institutions", "concepts", "funders", "sources", "publishers").
#' @param abstract Logical. If TRUE, the function returns also the abstract of each item.
#' Ignored if entity is different from "works". Defaults to TRUE.
#' @param verbose Logical.
Expand Down Expand Up @@ -70,7 +71,6 @@ oa2df <- function(data, entity, options = NULL, count_only = FALSE, group_by = N
works = works2df(data, abstract, verbose),
authors = authors2df(data, verbose),
institutions = institutions2df(data, verbose),
venues = venues2df(data, verbose),
concepts = concepts2df(data, verbose),
funders = funders2df(data, verbose),
sources = sources2df(data, verbose),
Expand Down Expand Up @@ -507,92 +507,6 @@ institutions2df <- function(data, verbose = TRUE,
}


#' Convert OpenAlex collection of venues' records from list format to data frame
#'
#' 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 works2df
#'
#' @return a data.frame.
#'
#' For more extensive information about OpenAlex API, please visit: <https://docs.openalex.org>
#'
#'
#' @examples
#' \dontrun{
#'
#' # Query to search information about the Journal of Informetrics (OA id:V205292342)
#'
#'
#' query_inst <- oa_query(
#' identifier = "V205292342",
#' entity = "venues"
#' )
#'
#' res <- oa_request(
#' query_url = query_inst,
#' count_only = FALSE,
#' verbose = FALSE
#' )
#'
#' df <- oa2df(res, entity = "venues")
#'
#' df
#' }
#'
#' @export
venues2df <- function(data, verbose = TRUE,
pb = if (verbose) oa_progress(length(data)) else NULL) {

n <- length(data)
list_df <- vector(mode = "list", length = n)
venue_process <- tibble::tribble(
~type, ~field,
"identical", "id",
"identical", "display_name",
"identical", "host_organization_name",
"identical", "works_count",
"identical", "cited_by_count",
"identical", "is_oa",
"identical", "is_in_doaj",
"identical", "homepage_url",
"identical", "works_api_url",
"identical", "type",
"identical", "relevance_score",
"flat", "issn_l",
"flat", "issn",
"rbind_df", "counts_by_year",
"rbind_df", "x_concepts",
"flat", "ids"
)

for (i in seq.int(n)) {
if (verbose) pb$tick()

item <- data[[i]]

fields <- venue_process[venue_process$field %in% names(item), ]
sim_fields <- mapply(
function(x, y) subs_na(item[[x]], type = y),
fields$field,
fields$type,
SIMPLIFY = FALSE
)
list_df[[i]] <- sim_fields
}

col_order <- c(
"id", "display_name", "host_organization_name", "issn", "issn_l", "is_oa", "is_in_doaj",
"ids", "homepage_url", "relevance_score", "works_count", "cited_by_count",
"counts_by_year", "x_concepts", "works_api_url", "type"
)

out_df <- rbind_oa_ls(list_df)
out_df[, intersect(col_order, names(out_df))]
}


#' Convert OpenAlex collection of concepts' records from list format to data frame
#'
#' It converts bibliographic collection of concepts' records gathered from OpenAlex database \href{https://openalex.org/}{https://openalex.org/} into data frame.
Expand Down
7 changes: 4 additions & 3 deletions R/oa_fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' oa_entities()
oa_entities <- function() {
c(
"works", "authors", "venues", "institutions", "concepts",
"works", "authors", "institutions", "concepts",
"funders", "sources", "publishers"
)
}
Expand Down Expand Up @@ -426,7 +426,8 @@ get_next_page <- function(paging, i, res = NULL) {
#' @param identifier Character. OpenAlex ID(s) as item identifier(s).
#' See more at <https://docs.openalex.org/how-to-use-the-api/get-single-entities#the-openalex-id>.
#' @param entity Character. Scholarly entity of the search.
#' The argument can be one of c("works", "authors", "venues", "institutions", "concepts").
#' The argument can be one of
#' c("works", "authors", "institutions", "concepts", "funders", "sources", "publishers").
#' If not provided, `entity` is guessed from `identifier`.
#' @param options List. Additional parameters to add in the query. For example:
#'
Expand All @@ -435,7 +436,7 @@ get_next_page <- function(paging, i, res = NULL) {
#' https://docs.openalex.org/how-to-use-the-api/get-single-entities/select-fields
#'
#' - `sort` Character. Attribute to sort by.
#' For example: "display_name" for venues or "cited_by_count:desc" for works.
#' For example: "display_name" for sources or "cited_by_count:desc" for works.
#' See more at <https://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/sort-entity-lists>.
#'
#' - `sample` Integer. Number of (random) records to return.
Expand Down
5 changes: 2 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

`%||%` <- function(x, y) if (is.null(x)) y else x

replace_w_na <- function(x){
lapply(x, `%||%`, y = NA)
replace_w_na <- function(x, y = NA){
lapply(x, `%||%`, y = y)
}

subs_na <- function(x, type, prefix = NULL) {
Expand Down Expand Up @@ -53,7 +53,6 @@ id_type <- function(identifier) {
switch(toupper(substr(identifier, 1, 1)),
W = "works",
A = "authors",
V = "venues",
I = "institutions",
C = "concepts",
S = "sources",
Expand Down
5 changes: 3 additions & 2 deletions man/oa2df.Rd

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

5 changes: 3 additions & 2 deletions man/oa_fetch.Rd

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

5 changes: 3 additions & 2 deletions man/oa_query.Rd

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

3 changes: 2 additions & 1 deletion man/oa_random.Rd

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

54 changes: 0 additions & 54 deletions man/venues2df.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion tests/testthat/test-oa2df.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test_that("oa2df works", {
expect_true(grepl("Naples", naples$display_name))
expect_equal(naples$country_code, "IT")

nejm <- oa_fetch(identifier = "V62468778")
nejm <- oa_fetch(identifier = "S62468778")
expect_equal(nejm$display_name, "The New England Journal of Medicine")
expect_s3_class(nejm, "data.frame")
expect_s3_class(nejm, "tbl")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-oa_fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ test_that("oa_fetch other entities works", {
skip_on_cran()

random_authors <- oa_fetch(entity = "authors", options = list(sample = 20))
random_venues <- oa_fetch(entity = "venues", options = list(sample = 20))
random_sources <- oa_fetch(entity = "sources", options = list(sample = 20))
random_concepts <- oa_fetch(entity = "concepts", options = list(sample = 20))
random_institutions <- oa_fetch(entity = "institutions", options = list(sample = 20))

expect_equal(nrow(random_authors), 20)
expect_equal(nrow(random_venues), 20)
expect_equal(nrow(random_sources), 20)
expect_equal(nrow(random_concepts), 20)
expect_equal(nrow(random_institutions), 20)
})
Expand Down

0 comments on commit 71adc6d

Please sign in to comment.