Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(is.na(sub_affiliation[[1]])) { : the condition has length > 1 Error #237

Open
Fulup opened this issue Apr 29, 2024 · 4 comments
Open

(is.na(sub_affiliation[[1]])) { : the condition has length > 1 Error #237

Fulup opened this issue Apr 29, 2024 · 4 comments

Comments

@Fulup
Copy link

Fulup commented Apr 29, 2024

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     = "my_email@example.com", # 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 = "pka@dmu.ac.uk", verbose = FALSE)
@trangdata
Copy link
Collaborator

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!

@Fulup
Copy link
Author

Fulup commented Apr 30, 2024 via email

@Fulup
Copy link
Author

Fulup commented Apr 30, 2024 via email

@trangdata
Copy link
Collaborator

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants