Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create zip with no extension

Tags:

r

zip

I want to create a zip file called "out" not "out.zip". When I run this line:

zip("out", zippedfiles)

where zippedfiles is a list of files, I get out.zip. I am doing this in a Windows environment.

Thanks.

like image 208
James Avatar asked Jan 19 '23 08:01

James


1 Answers

Several people have mentioned that this is the behaviour of zip, but not why this is the cause of what you are seeing. If you look at the source for zip() or even the help ?zip, it should be immediately clear that the behaviour you are seeing comes from the system zip function and nothing to do with R itself. All R does is call the system function for zipping, which by default is zip:

R> zip
function (zipfile, files, flags = "-r9X", extras = "", zip = Sys.getenv("R_ZIPCMD", 
    "zip")) 
{
    if (missing(flags) && (!is.character(files) || !length(files))) 
        stop("'files' must a character vector specifying one or more filepaths")
    args <- c(flags, shQuote(path.expand(zipfile)), shQuote(files), 
        extras)
    invisible(system2(zip, args, invisible = TRUE)) ## simply calling system command
}
<bytecode: 0x27faf30>
<environment: namespace:utils>

If you are annoyed by the extension, just issue a file.rename() call after the call to zip():

file.rename("out.zip", "out")
like image 70
Gavin Simpson Avatar answered Jan 28 '23 20:01

Gavin Simpson