Karoline
Karoline

Reputation: 27

Read multiple .bib files and Add filename as new column in R

I have more than 200 .bib files from WoS that I would like to analize with bibliometrix package. But each file refers to a different specific place that I'm working about. I would like to read those multiple files, adding the filename (which is the places' name) as a new column for identification while joining all the files into a unique object (with the column with filename identifying them). I've been trying some alternatives, but cannot succeed.

This is what I've been trying:

library(RefManageR)
library(bibliometrix)

    # List of .bib files
files <- list.files(path = "C:/Users/drive/OneDrive/Documentos/cienciometria parques africanos", pattern = "\\.bib$", full.names = TRUE)

# Function to read a single .bib file and add the column with the file name
read_bib <- function(file) {
  bib <- ReadBib(file)
  bib$file_source <- basename(file)  # Add column with file name
  return(bib)
}

# Read all .bib files and add the column with the file name
bib_list <- lapply(files, read_bib)

# Combine all BibEntry objects into a single one
combined_bib <- do.call("c", bib_list)

But when I run tha lapply I get this error:

Error in seq.default(1, guess_eoentry) : 'to' must be a finite number
Additionally: There were 50 or more warnings (use warnings() to see the first 50)

Upvotes: 0

Views: 47

Answers (0)

Related Questions