ropensci / europepmc

R Interface to Europe PMC RESTful Web Service
https://docs.ropensci.org/europepmc
27 stars 8 forks source link

Error in epmc_annotations_by_id() when article has pubmed ID, but lacks PMCID (europepmc 0.4.1) #45

Closed pavelVPo closed 2 years ago

pavelVPo commented 2 years ago

First of all, thank you for your work. Using europepmc I found out that there are articles, which lack PMCID and still have some annotations though. Unfortunately, it is impossible to retrive them because (europepmc 0.4.1):

epmc_annotations_by_id("MED:10566658") No encoding supplied: defaulting to UTF-8. Ошибка: Internal error in df_slice(): Columns must match the data frame size. Run rlang::last_error() to see where the error occurred.

rlang::last_error() <error/rlang_error> Internal error in df_slice(): Columns must match the data frame size. Backtrace:

  1. europepmc::epmc_annotations_by_id("MED:10566658")
  2. purrr::map_df(ids, epmc_annotations_byid, .pb = pb)
  3. purrr::map(.x, .f, ...)
  4. europepmc:::.f(.x[[i]], ...)
  5. tidyr:::unnest.data.frame(out, .data$annotations)
  6. tidyr::unchop(data, any_of(cols), keep_empty = keep_empty, ptype = ptype)
  7. vctrs::vec_slice(data, slice_loc) Run rlang::last_trace() to see the full context.

I guess that the problem is in annotations_by_id.R, epmc_annotations_byid, line 63: pmcid = req[["pmcid"]], I think it could be changed to pmcid = if_else(is.null(req[["pmcid"]]), NAcharacter, req[["pmcid"]]),

Regards.

njahn82 commented 2 years ago

Thank you for your report. I implemented your fix and it works as expected 🎉 Please re-install the dev version from GitHub.

pavelVPo commented 2 years ago

Sorry for the late reply and thank you, dev-version is installed and there is no issue with the articles lacking PMCID.