如何从路径中提取名称并将它们添加为 lapply 中列表元素的名称

How do I extract name from path and add them as names of elements of list inside lapply

如何从路径中提取名称并将它们添加为 lapply 中列表元素的名称。

我希望 tbl_list 中的元素名称为 [["Employees"]] 和 [["Performances"]] 即在 last _ till 之后提取 csv_files 的名称在 .csv.

之前
library(tidyverse)

# list of path of files
csv_files <- c("C:/Dropbox (UFL)/Projects/Datasets/Company_A_-_Employees.csv",
               "C:/Dropbox (UFL)/Projects/Datasets/Company_A_-_Performances.csv")


# read all files using lapply
tbl_list <- lapply(X = csv_files, FUN = read_csv)


tbl_list has two elements [[1]] and [[2]] corresponding to each csv_files.

names(tbl_list) <- gsub(".*_(.*)\.csv$", "\1", csv_files)