diff --git a/R/oa2df.R b/R/oa2df.R index 41d0968..86a4d45 100644 --- a/R/oa2df.R +++ b/R/oa2df.R @@ -144,7 +144,7 @@ works2df <- function(data, abstract = TRUE, verbose = TRUE, "language", "grants", "cited_by_count", "counts_by_year", "publication_year", "cited_by_api_url", "ids", "doi", "type", "referenced_works", "related_works", "is_paratext", "is_retracted", - "concepts", "topics" + "concepts", "topics", "apc" ) works_process <- tibble::tribble( ~type, ~field, @@ -166,6 +166,8 @@ works2df <- function(data, abstract = TRUE, verbose = TRUE, "flat", "related_works", "rbind_df", "counts_by_year", "rbind_df", "concepts", + "flat", "apc_list", + "flat", "apc_paid", "flat", "ids" ) @@ -204,7 +206,7 @@ works2df <- function(data, abstract = TRUE, verbose = TRUE, sim_fields$publication_date <- as.Date(sim_fields$publication_date) } - author <- venue <- ab <- NULL + author <- venue <- ab <- apc <- NULL if (!is.null(paper$primary_location)) { so_info <- paper$primary_location["source"] @@ -257,11 +259,17 @@ works2df <- function(data, abstract = TRUE, verbose = TRUE, names(open_access)[[1]] <- "is_oa_anywhere" } + # Process APC + if (any(lengths(paper[c("apc_list", "apc_paid")]) > 0)) { + apc_fields <- list(value = NA, currency = NA, value_usd = NA, provenance = NA) + apc <- list(rbind.data.frame( + c(type = "list", modifyList(apc_fields, as.list(paper$apc_list))), + c(type = "paid", modifyList(apc_fields, as.list(paper$apc_paid))) + )) + } topics <- process_topics(paper, "score") - out_ls <- c( - sim_fields, venue, open_access, paper_biblio, - list(author = author, ab = ab), topics - ) + out_ls <- c(sim_fields, venue, open_access, paper_biblio, + list(author = author, ab = ab, apc = apc), topics) out_ls[sapply(out_ls, is.null)] <- NULL list_df[[i]] <- out_ls } diff --git a/tests/testthat/test-oa2bibliometrix.R b/tests/testthat/test-oa2bibliometrix.R index e7e6de9..2b36896 100644 --- a/tests/testthat/test-oa2bibliometrix.R +++ b/tests/testthat/test-oa2bibliometrix.R @@ -8,10 +8,7 @@ test_that("oa2bibliometrix works", { to_publication_date = "2021-01-31" ) - empty_au <- oa_fetch(entity="works", id="W3125831892") - w <- rbind(aria_citations, empty_au) - - aria_bibli <- oa2bibliometrix(w) + aria_bibli <- oa2bibliometrix(aria_citations) expect_s3_class(aria_bibli, "data.frame") - expect_equal(nrow(w), nrow(aria_bibli)) + expect_equal(nrow(aria_citations), nrow(aria_bibli)) }) diff --git a/tests/testthat/test-oa_fetch.R b/tests/testthat/test-oa_fetch.R index dba04e3..347ec44 100644 --- a/tests/testthat/test-oa_fetch.R +++ b/tests/testthat/test-oa_fetch.R @@ -356,7 +356,7 @@ test_that("oa_fetch works for publishers", { test_that("oa_fetch works with 1 identifier", { skip_on_cran() - w <- oa_fetch(identifier = "W3046863325") # Work + w <- oa_fetch(identifier = "W3127908559") # Work a <- oa_fetch(identifier = "A5023888391") # Author i <- oa_fetch(identifier = "I4200000001") # Institution f <- oa_fetch(identifier = "F4320332161") # Funder @@ -372,7 +372,7 @@ test_that("oa_fetch works with 1 identifier", { expect_s3_class(s, "data.frame") expect_s3_class(co, "data.frame") - expect_equal(dim(w), c(1, 38)) + expect_equal(dim(w), c(1, 39)) expect_equal(dim(a), c(1, 17)) expect_equal(dim(i), c(1, 21)) expect_equal(dim(f), c(1, 17))