From 955e21da22d6a9f1b11362d855505f37265e0b01 Mon Sep 17 00:00:00 2001 From: let20 Date: Fri, 22 Mar 2024 10:56:15 -0400 Subject: [PATCH] remove venues --- NAMESPACE | 1 - NEWS.md | 1 + R/oa2df.R | 90 +--------------------------------- R/oa_fetch.R | 7 +-- R/utils.R | 5 +- man/oa2df.Rd | 5 +- man/oa_fetch.Rd | 5 +- man/oa_query.Rd | 5 +- man/oa_random.Rd | 3 +- man/venues2df.Rd | 54 -------------------- tests/testthat/test-oa2df.R | 2 +- tests/testthat/test-oa_fetch.R | 4 +- 12 files changed, 23 insertions(+), 159 deletions(-) delete mode 100644 man/venues2df.Rd diff --git a/NAMESPACE b/NAMESPACE index 0d58d65..088ad05 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,6 +21,5 @@ export(show_authors) export(show_works) export(snowball2df) export(sources2df) -export(venues2df) export(works2df) importFrom(stats,setNames) diff --git a/NEWS.md b/NEWS.md index 8d17634..9bb60a3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/oa2df.R b/R/oa2df.R index 9cd6b1b..ef47312 100644 --- a/R/oa2df.R +++ b/R/oa2df.R @@ -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. @@ -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), @@ -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: -#' -#' -#' @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. diff --git a/R/oa_fetch.R b/R/oa_fetch.R index e259a1d..d9c3c11 100644 --- a/R/oa_fetch.R +++ b/R/oa_fetch.R @@ -6,7 +6,7 @@ #' oa_entities() oa_entities <- function() { c( - "works", "authors", "venues", "institutions", "concepts", + "works", "authors", "institutions", "concepts", "funders", "sources", "publishers" ) } @@ -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 . #' @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: #' @@ -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 . #' #' - `sample` Integer. Number of (random) records to return. diff --git a/R/utils.R b/R/utils.R index e235d54..dc266a5 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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) { @@ -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", diff --git a/man/oa2df.Rd b/man/oa2df.Rd index 17c288c..c2c9504 100644 --- a/man/oa2df.Rd +++ b/man/oa2df.Rd @@ -18,7 +18,8 @@ oa2df( \item{data}{List. Output of \code{oa_request}.} \item{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").} \item{options}{List. Additional parameters to add in the query. For example: @@ -27,7 +28,7 @@ Defaults to NULL, which returns all fields. 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 . - `sample` Integer. Number of (random) records to return. diff --git a/man/oa_fetch.Rd b/man/oa_fetch.Rd index 90eec67..3948ba3 100644 --- a/man/oa_fetch.Rd +++ b/man/oa_fetch.Rd @@ -26,7 +26,8 @@ oa_fetch( } \arguments{ \item{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`.} \item{identifier}{Character. OpenAlex ID(s) as item identifier(s). @@ -41,7 +42,7 @@ Defaults to NULL, which returns all fields. 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 . - `sample` Integer. Number of (random) records to return. diff --git a/man/oa_query.Rd b/man/oa_query.Rd index ea45789..8fada0e 100644 --- a/man/oa_query.Rd +++ b/man/oa_query.Rd @@ -34,7 +34,8 @@ or `to_publication_date = "2021-12-31"`.} See more at .} \item{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`.} \item{options}{List. Additional parameters to add in the query. For example: @@ -44,7 +45,7 @@ Defaults to NULL, which returns all fields. 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 . - `sample` Integer. Number of (random) records to return. diff --git a/man/oa_random.Rd b/man/oa_random.Rd index b369896..8073005 100644 --- a/man/oa_random.Rd +++ b/man/oa_random.Rd @@ -12,7 +12,8 @@ oa_random( } \arguments{ \item{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`.} \item{output}{Character. Type of output, either a list or a tibble/data.frame.} diff --git a/man/venues2df.Rd b/man/venues2df.Rd deleted file mode 100644 index 77d4c6c..0000000 --- a/man/venues2df.Rd +++ /dev/null @@ -1,54 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/oa2df.R -\name{venues2df} -\alias{venues2df} -\title{Convert OpenAlex collection of venues' records from list format to data frame} -\usage{ -venues2df( - data, - verbose = TRUE, - pb = if (verbose) oa_progress(length(data)) else NULL -) -} -\arguments{ -\item{data}{List. Output of \code{oa_request}.} - -\item{verbose}{Logical. -If TRUE, print information about the dataframe conversion process. -Defaults to TRUE.} - -\item{pb}{Progress bar object. If verbose, computed from `oa_progress`. -NULL otherwise.} -} -\value{ -a data.frame. - -For more extensive information about OpenAlex API, please visit: -} -\description{ -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. -} -\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 -} - -} diff --git a/tests/testthat/test-oa2df.R b/tests/testthat/test-oa2df.R index 528d6f0..a8f2b9a 100644 --- a/tests/testthat/test-oa2df.R +++ b/tests/testthat/test-oa2df.R @@ -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") diff --git a/tests/testthat/test-oa_fetch.R b/tests/testthat/test-oa_fetch.R index 06f1a7c..e369160 100644 --- a/tests/testthat/test-oa_fetch.R +++ b/tests/testthat/test-oa_fetch.R @@ -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) })