Q:

Why is my list empty after execution?

I managed to fill my doi_list but it does not work if I encapsulate the code into a function. From a tutorial I've seen I assume that this should be possible but doi_list is empty after get_doi_from_category() finishes.
library(aRxiv)

get_doi_from_category <- function(category, doi_list) {

  arxiv_rec <- arxiv_search(category)
  arxiv_doi_list <- arxiv_rec[13]

  by(arxiv_doi_list, 1:nrow(arxiv_doi_list), 
     function(row) { 
       if(nchar(row) > 0) {
         doi_list <<- c(doi_list, row)
       }
     })
}

doi_list <- list()

get_doi_from_category('cat:stat.ML', doi_list)

for(doi in doi_list) 
{
  print(doi)
} 

get_doi_from_category('cat:stat.CO', doi_list)
get_doi_from_category('cat:stat.ME', doi_list)
get_doi_from_category('cat:stat.TH', doi_list)

PS: First day with R.

A:

Here's a better way to do what you want in R:
categ <- c(CO = "cat:stat.CO", #I'm naming these elements so
           ME = "cat:stat.ME", #  that the corresponding elements
           TH = "cat:stat.TH", #  in the list are named as well.
           ML = "cat:stat.ML") #  Could also just set 'names(doi_list)' to 'categ'.

doi_list <- 
  lapply(categ, function(ctg)
    (doi <- arxiv_search(ctg)$doi)[nchar(doi) > 0])

I sort of threw you in the deep end on the last line with in-line assignment of doi; a more step-by-step approach would be:
lapply(categ, function(ctg){
  arxiv.df <- arxiv_search(ctg)
  doi <- arxiv.df$doi
  doi[nchar(doi) > 0]})

