(is.na(sub_affiliation[[1]])) { : the condition has length > 1 Error
Dear OpenalexR support team, Please could you advise on improving this R script using openalexR which was working last week but is now reporting an error. I have reinstalled the openalexR package today.
I have a dataframe called UoA_researchers imported from a csv file containing Openalex IDs.
# create a dataframe the size of the number of researchers in the input file
data <- numeric(length(UoA_researchers$OpenalexID))
# populate the dataframe with the results of our Openalex searches
for(i in seq_along(UoA_researchers))
{
# For Loop to run repeated searches of Openalex
data <- oa_fetch(
identifier = UoA_researchers$OpenalexID,
entity = "authors",
mailto = "[email protected]", # politeness, please use your own email address
verbose = FALSE
)
}
# let's have a look at the retrieved data
head(data)
# add some context to each line
data <- data |>
select(display_name, id, orcid) |>
mutate(uoa = "20", unit = "Social Work and Social Policy")
# and write the results to a file. Change the filename to reflect the UoA.
write_csv(data, "openalex_researchers_UoA20.csv")
=====
However, I am getting an error message:
Error in if (is.na(sub_affiliation[[1]])) { :
the condition has length > 1
5.
authors2df(data, verbose)
4.
FUN(X[[i]], ...)
3.
lapply(final_res, oa2df, entity = entity, options = options,
abstract = abstract, count_only = count_only, group_by = group_by,
verbose = verbose)
2.
do.call(rbind, lapply(final_res, oa2df, entity = entity, options = options,
abstract = abstract, count_only = count_only, group_by = group_by,
verbose = verbose))
1.
oa_fetch(identifier = UoA_researchers$OpenalexID, entity = "authors",
mailto = "[email protected]", verbose = FALSE)
Thank you for reporting @Fulup! Unfortunately, without the actually OpenalexID, I can't reproduce the issue. Could you give us at least one id that gives you this error? Thanks!
Hi, Thanks for your interest in this issue. Please try this OpenalexID: A5049085191
Regards
Philip Adams (Pronouns: He/Him/His) Senior Assistant Librarian: Content Delivery, Library and Student Services
DE MONTFORT UNIVERSITY Leicester LE1 9BH E: @.*** W: dmu.ac.uk Chat with me: @.***
Interim UNISON Environmental Officer at DMU Join Unison: http://bit.ly/t1nUsqhttps://webmail.dmu.ac.uk/owa/redir.aspx?C=tVhbzbOQRkaL1QrPemjKNZ8rpTHwgNEIiZZLb34d1IWvdR2mBGJpoUyVYJGaY0Q4H5zpBf3IQR4.&URL=http%3a%2f%2fbit.ly%2ft1nUsq
[cid:afbe47e0-9330-4178-ad8f-f9cd27a33467]
From: Trang Le @.> Sent: 29 April 2024 20:56 To: ropensci/openalexR @.> Cc: Phil Adams @.>; Mention @.> Subject: Re: [ropensci/openalexR] (is.na(sub_affiliation[[1]])) { : the condition has length > 1 Error (Issue #237)
This message was sent from outside of DMU. Please do not click links or open attachments unless you recognise the source of this email and know the content is safe.
Thank you for reporting @Fuluphttps://ddec1-0-en-ctp.trendmicro.com:443/wis/clicktime/v1/query?url=https%3a%2f%2fgithub.com%2fFulup&umid=e67e6208-cbd1-48e2-97f9-6315f49c9a07&auth=06e76e57000ea428f34b63fea08893688229b6ce-6809120ecab7fb947115d780eccd87baa7af351a! Unfortunately, without the actually OpenalexID, I can't reproduce the issue. Could you give us at least one id that gives you this error? Thanks!
— Reply to this email directly, view it on GitHubhttps://ddec1-0-en-ctp.trendmicro.com:443/wis/clicktime/v1/query?url=https%3a%2f%2fgithub.com%2fropensci%2fopenalexR%2fissues%2f237%23issuecomment%2d2083547879&umid=e67e6208-cbd1-48e2-97f9-6315f49c9a07&auth=06e76e57000ea428f34b63fea08893688229b6ce-0439edf842248285e548d7f5dd4ac5b207727c58, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAHAA4L5DOB4FF5WY3KJXSDY72QVDAVCNFSM6AAAAABG6KX6FKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBTGU2DOOBXHE. You are receiving this because you were mentioned.Message ID: @.***>
Here are the full files I am trying to work with. I hope that help give a better context.
Regards
Philip Adams (Pronouns: He/Him/His) Senior Assistant Librarian: Content Delivery, Library and Student Services
DE MONTFORT UNIVERSITY Leicester LE1 9BH E: @.*** W: dmu.ac.uk Chat with me: @.***
Interim UNISON Environmental Officer at DMU Join Unison: http://bit.ly/t1nUsqhttps://webmail.dmu.ac.uk/owa/redir.aspx?C=tVhbzbOQRkaL1QrPemjKNZ8rpTHwgNEIiZZLb34d1IWvdR2mBGJpoUyVYJGaY0Q4H5zpBf3IQR4.&URL=http%3a%2f%2fbit.ly%2ft1nUsq
[cid:729fe920-0f9e-4e04-a454-10dba71f9856]
From: Trang Le @.> Sent: 29 April 2024 20:56 To: ropensci/openalexR @.> Cc: Phil Adams @.>; Mention @.> Subject: Re: [ropensci/openalexR] (is.na(sub_affiliation[[1]])) { : the condition has length > 1 Error (Issue #237)
This message was sent from outside of DMU. Please do not click links or open attachments unless you recognise the source of this email and know the content is safe.
Thank you for reporting @Fuluphttps://ddec1-0-en-ctp.trendmicro.com:443/wis/clicktime/v1/query?url=https%3a%2f%2fgithub.com%2fFulup&umid=e67e6208-cbd1-48e2-97f9-6315f49c9a07&auth=06e76e57000ea428f34b63fea08893688229b6ce-6809120ecab7fb947115d780eccd87baa7af351a! Unfortunately, without the actually OpenalexID, I can't reproduce the issue. Could you give us at least one id that gives you this error? Thanks!
— Reply to this email directly, view it on GitHubhttps://ddec1-0-en-ctp.trendmicro.com:443/wis/clicktime/v1/query?url=https%3a%2f%2fgithub.com%2fropensci%2fopenalexR%2fissues%2f237%23issuecomment%2d2083547879&umid=e67e6208-cbd1-48e2-97f9-6315f49c9a07&auth=06e76e57000ea428f34b63fea08893688229b6ce-0439edf842248285e548d7f5dd4ac5b207727c58, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAHAA4L5DOB4FF5WY3KJXSDY72QVDAVCNFSM6AAAAABG6KX6FKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBTGU2DOOBXHE. You are receiving this because you were mentioned.Message ID: @.***>
@Fulup I don't think you can share the full file via email to show on GitHub. I tried your example openalex id and it's working for me:
library(openalexR)
author <- oa_fetch(
identifier = "A5049085191",
verbose = TRUE
)
#> Requesting url: https://api.openalex.org/authors/A5049085191
author
#> # A tibble: 1 × 17
#> id display_name display_name_alterna…¹ ids orcid works_count
#> <chr> <chr> <list> <lis> <chr> <int>
#> 1 https://openalex.… Richard Hall <chr [14]> <chr> http… 407
#> # ℹ abbreviated name: ¹display_name_alternatives
#> # ℹ 11 more variables: cited_by_count <int>, counts_by_year <list>,
#> # affiliation_display_name <chr>, affiliation_id <chr>,
#> # affiliation_ror <chr>, affiliation_country_code <chr>,
#> # affiliation_type <chr>, affiliation_lineage <chr>,
#> # affiliations_other <list>, x_concepts <list>, works_api_url <chr>
Created on 2024-05-01 with reprex v2.0.2
Hi all,
I am just running into the same issue. Weirdly enough, it happens when I try to reproduce my old code that worked before. For the sake of reproducibility, I am loading openalexR like this:
library(groundhog)
groundhog.library("openalexR", date = "2023-12-01")
The error persists even when just loading using library(openalexR).
Here is what I am doing:
oa_fetch(entity = "author", search = "John Smith")
It returns this:
Error in if (is.na(sub_affiliation[[1]])) { : the condition has length > 1
The problem is obviously in the conversion to dataframe, since this works:
oa_fetch(entity = "author", search = "John Smith", output = "list")
But this does not:
oa_fetch(entity = "author", search = "John Smith", output = "dataframe")
Do you have any advice on how to tackle this? Thanks!
Hi @amacanovic could you try re-installing openalexR, please?
Maybe this deserves a separate discussion, but IMO it doesn't make much sense (at least on account of reproducibility) to version lock {openalexR} if you're not also version controlling the OpenAlex API and their database snapshot.
To @trangdata 's point, I think {openalexR} should simply be kept updated to the most recent version whenever it is used for real-time queries to the OpenAlex API. I can also confirm that the oa_fetch() code works on the dev version of the package :)
@yjunechoe I agree - that should be a separate discussion. Especially, as there is the same (or very similar) point in https://github.com/ropensci/openalexR/issues/253#issuecomment-2156087336 . Would it be possible to have a discussion, as this not really belonged in the Issues? I will be happy to chime in when there is one starting point for the discussion, as I think this touches many points, going from expectations, over different usage pattern, to directions the revision if openalexR could take.
Hi all,
Reinstalling indeed solves this. Thanks for pointing this all out; I will add a note on this in my code repo.