R-在函数内部访问变量“名称”

具有2个或更多文件路径(如下面的每个文件路径)将作为单独的数据帧读取

file1 = ".data/abc_123.txt"
file2 = ".data/def_324.txt"

To enable batch reading, storing these filenames in to a vector filesVector = c(file1, file2)

Inside the function used to batch read files, need to access the variable names that are in filesVector

csvToDF = function(filesVector){
  for(file in filesVector){ 
    # is there a way to extract variable names `file1` & `file2` inside here so as to create a dataframe with name of file as part of the variable for variable
    # in the above example data, it should create two data frames stored as variables `df_file1` and `df_file2`
    variable_name = read.csv(file)
  }
}
评论