Skip to content

Commit

Permalink
Add apc information (#212)
Browse files Browse the repository at this point in the history
* add apc column

* handle NULL

* initialize apc as null

* update test

---------

Co-authored-by: Trang Le <[email protected]>
Co-authored-by: let20 <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2024
1 parent 00e56bf commit 6beed9b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
20 changes: 14 additions & 6 deletions R/oa2df.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
)

Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 2 additions & 5 deletions tests/testthat/test-oa2bibliometrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
4 changes: 2 additions & 2 deletions tests/testthat/test-oa_fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit 6beed9b

Please sign in to comment.