Skip to content

Commit 13fb542

Browse files
committed
Adapt to openalexR v2.0.0
1 parent 2963b73 commit 13fb542

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

joss-submission-analytics.Rmd

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,19 @@ source_track <- c(source_track,
141141
## Helper function to extract countries from affiliations. Note that this
142142
## information is not available for all papers.
143143
.get_countries <- function(df, wh = "first") {
144-
if (length(df) == 1 && is.na(df)) {
144+
if ((length(df) == 1 && is.na(df)) || is.null(df$affiliations)) {
145145
""
146146
} else {
147147
if (wh == "first") {
148148
## Only first affiliation for each author
149-
tmp <- df |>
150-
dplyr::filter(!duplicated(au_id) & !is.na(institution_country_code)) |>
151-
pull(institution_country_code)
149+
tmp <- unnest(df, cols = c(affiliations), names_sep = "_") |>
150+
dplyr::filter(!duplicated(id) & !is.na(affiliations_country_code)) |>
151+
pull(affiliations_country_code)
152152
} else {
153153
## All affiliations
154-
tmp <- df |>
155-
dplyr::filter(!is.na(institution_country_code)) |>
156-
pull(institution_country_code)
154+
tmp <- unnest(df, cols = c(affiliations), names_sep = "_") |>
155+
dplyr::filter(!is.na(affiliations_country_code)) |>
156+
pull(affiliations_country_code)
157157
}
158158
if (length(tmp) > 0) {
159159
tmp |>
@@ -167,8 +167,8 @@ source_track <- c(source_track,
167167
168168
oa <- oa_fetch(entity = "works",
169169
primary_location.source.id = "s4210214273") |>
170-
mutate(affil_countries_all = vapply(author, .get_countries, "", wh = "all"),
171-
affil_countries_first = vapply(author, .get_countries, "", wh = "first"))
170+
mutate(affil_countries_all = vapply(authorships, .get_countries, "", wh = "all"),
171+
affil_countries_first = vapply(authorships, .get_countries, "", wh = "first"))
172172
dim(oa)
173173
length(unique(oa$doi))
174174

0 commit comments

Comments
 (0)