如何在 RStudio 中自动执行解压缩步骤

How to automate the process of unzip steps in RStudio

我已经下载了运输历史数据。每年的数据包含相同数量且名称完全相同的文件。每年的数据都压缩在一个文件中。我正在尝试自动执行解压缩过程。
例如:我有三个名为 (2014.zip、2013.zip、2012.zip) 的 zip 文件,每个 zip 文件包含三个文件 (car.csv、truck.csv、train.csv).我想要的是将这些文件解压缩到将动态创建的相应文件夹中。如何在 RStudio 中自动执行此过程?谢谢。

lapply(filenames, function(x)){
foldername<-substr(filename, 1, nchar(filename)-4)

if (file.exists(x)==FALSE){
    download.file(url, x)
}

if (file.exists(foldername)==FALSE){
    dir.create(foldername)
}

unzip(x)

for (file in list.files(pattern="*.dbf")){
    file.copy(file,foldername)

    file.remove(file)
}}