I would not recommend using the function get()
as this can have bad consequences. I'd suggest using a more structured approach by mean of a list containing all you csv files. I don't have any data here so I will build upon your code.
# Loading files
filenames <- gsub("\\.csv$", "", list.files(pattern = "\\.csv$"))
# create a list with NULL
file_list = vector("list", length(filenames))
# name each element according to filenames
names(file_list) = filenames
# Loop over the list
# Please note that the iterator "i" now loops over the elements
# and does not take the real values in filenames
for (i in seq_along(file_list)) {
current_file = read.csv(paste0(i, ".csv"))
file_list[[ i ]] = current_file
}
Now you can access each element either with the standard indexing ([[
) or via the names with the $
operator.
UPDATE
For an example about why you should avoid get()
, please refer to this SO post.