Creating zip file from folders in R

前端 未结 5 1333
故里飘歌
故里飘歌 2021-02-13 12:12

Try to create a zip file from one folder using R.

It mentioned \"Rcompression\" package here: Creating zip file from folders

But I didn\'t find where I can downl

5条回答
  •  悲&欢浪女
    2021-02-13 12:33

    For avoiding (a) an issue with relative paths (i.e., the zip file itself containing a folder structure with the full folder path to be zipped) and (b) for loops (well, style), you may use

    my_wd<-getwd() # save your current working directory path
    dest_path<-"C:/.../folder_with_files_to_be_zipped" 
    setwd(dest_path)
    files<-list.files(dest_path)
    named<-paste0(files,".zip")
    mapply(zip,zipfile=named,files=files)
    setwd(my_wd) # reset working directory path
    

    Unlike R´s build-in unzip function, zip requires a zip-program like 7-zip (Windows) or the one being part of Rtools to be present in your system path.

提交回复
热议问题