I have developed an R function to download the "organism" name of the numerous NCBI accession numbers which are already saved in an object. The function:

get_organism_names <- function(accession_numbers) {
  organism_names <- sapply(accession_numbers, function(accession) {
    record <- entrez_summary(db = "nucleotide", id = accession)
  names(organism_names) <- accession_numbers

Although it works for some accession numbers, for others it encounters an error stating for example:

Warning: Esummary includes error message: Invalid uid KU253616.1 at position= 0Error: No esummary records found in file

How can I either solve this error or ask R to skip the problematic accession and keep downloading the rest?

  • $\begingroup$ Have you tried running it in a loop with a single accession each time instead of giving it all of them? $\endgroup$
    – terdon
    Commented Oct 25, 2023 at 12:53
  • $\begingroup$ Also, please give us all of the code. Presumably, you are loading some libraries, which ones? We need example code that we can use to reproduce the problem. See stackoverflow.com/help/minimal-reproducible-example. We need example input, and then code that we can run locally that reproduces the error. $\endgroup$
    – terdon
    Commented Oct 25, 2023 at 12:56

1 Answer 1


You could use the tryCatch function to handle inputs that throw an error. A good example on how to write them can be found here. Though the message indicates it's a warning, so does the function stop running when you get this message?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.