@@ -141,19 +141,19 @@ source_track <- c(source_track,
141
141
## Helper function to extract countries from affiliations. Note that this
142
142
## information is not available for all papers.
143
143
.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 )) {
145
145
""
146
146
} else {
147
147
if (wh == "first") {
148
148
## 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 )
152
152
} else {
153
153
## 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 )
157
157
}
158
158
if (length(tmp) > 0) {
159
159
tmp |>
@@ -167,8 +167,8 @@ source_track <- c(source_track,
167
167
168
168
oa <- oa_fetch(entity = "works",
169
169
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"))
172
172
dim(oa)
173
173
length(unique(oa$doi))
174
174
0 commit comments