Skip to content

Commit

Permalink
Refactoring (#294)
Browse files Browse the repository at this point in the history
* deprecating oa2bibliometrix

* update tests

* refactor

* update news

* update docs
  • Loading branch information
trangdata authored Nov 13, 2024
1 parent 6beed9b commit a9c91d6
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 173 deletions.
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# openalexR 2.0.0
* Breaking changes in column names in the output of `oa_fetch`:
* `so` is now `source_display_name`
* `so_id` is now `source_id`
* `ab` is now `abstract`
* `url` is now `landing_page_url`
* the nested columns under `authors` no longer have the `au` prefix

* Deprecated `oa2bibliometrix()`. Use `bibliometrix::convert2df()`
(from the **bibliometrix** R package) instead.

# openalexR 1.4.0
* "topics" are now a valid entity in oa_fetch
* The column "topics" replaces concepts in most entities' returned dataframes
Expand Down
30 changes: 14 additions & 16 deletions R/oa2bibliometrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#'
#' @param df is bibliographic collection of works donwloaded from OpenALex.
#' @return a data.frame with class "bibliometrix".
#'
#' @details Use \code{bibliometrix::convert2df()} (bibliometrix R package) instead.
#'
#' @examples
#' \dontrun{
Expand All @@ -22,13 +22,10 @@
#' # Results have to be sorted by relevance score in a descending order.
#'
#' query <- oa_query(
#' identifier = NULL,
#' entity = "works",
#' cites = "W2755950973",
#' from_publication_date = "2021-01-01",
#' to_publication_date = "2021-12-31",
#' search = NULL,
#' endpoint = "https://api.openalex.org"
#' from_publication_date = "2021-10-01",
#' to_publication_date = "2021-12-31"
#' )
#'
#' res <- oa_request(
Expand All @@ -45,6 +42,8 @@
#' @export
#'
oa2bibliometrix <- function(df) {
.Deprecated(msg = "oa2bibliometrix() is deprecated. Please use bibliometrix::convert2df() instead.")

df$id_oa <- shorten_oaid(df$id)
names(df)[names(df) == "id"] <- "id_url"

Expand All @@ -57,18 +56,17 @@ oa2bibliometrix <- function(df) {
countrycode$Country <- as.character(countrycode$Country)

# Authors
AU_info <- lapply(df$author, function(l) {
AU_info <- lapply(df$author[7], function(l) {
if (length(l) == 0 || (length(l) == 1 && is.na(l))){
return(empty_list(
c("AU", "RP", "C1", "AU_UN", "AU_CO")
))
} else {
l$institution_country_code[is.na(l$institution_country_code)] <- "Not available"
AU <- au_collapse(l$au_display_name)
C1 <- au_collapse(l$au_affiliation_raw)
RP <- au_collapse(l$au_affiliation_raw[1])
AU_UN <- au_collapse(l$institution_display_name)
AU_CO <- au_collapse(countrycode[l$institution_country_code, 1])
AU <- au_collapse(l$display_name)
C1 <- au_collapse(l$affiliation_raw)
RP <- au_collapse(l$affiliation_raw[1])
AU_UN <- au_collapse(lapply(l$affiliations, function(x) x$display_name))
AU_CO <- au_collapse(countrycode[unlist(lapply(l$affiliations, function(x) x$country_code)), 1])
list(AU = AU, RP = RP, C1 = C1, AU_UN = AU_UN, AU_CO = AU_CO)
}
})
Expand All @@ -91,11 +89,11 @@ oa2bibliometrix <- function(df) {
df <- cbind(AU_info, ID, df)

df$TI <- toupper(df$display_name)
df$AB <- toupper(df$ab)
df$SO <- toupper(df$so)
df$AB <- toupper(df$abstract)
df$SO <- toupper(df$source_display_name)
df$DT <- toupper(df$type)
df$DB <- "OPENALEX"
df$JI <- shorten_oaid(df$so_id)
df$JI <- shorten_oaid(df$source_id)
df$J9 <- df$JI
df$PY <- df$publication_year
df$TC <- df$cited_by_count
Expand Down
Loading

0 comments on commit a9c91d6

Please sign in to comment.