'Creating password protected zip file in R

I have tried following code to generate a password protected zip file in R, but it didn't work and didn't give any error either.

zip('file.zip', 
files = 'file.pdf',
flags = paste("--password", 'pwd123'))

Can anyone say what's wrong in this code or how to make it work?



Solution 1:[1]

It looks like you were close, but need to add your commands to the extras argument as a list:

pdf("file.pdf")
  plot(1)
dev.off()

zip('file.zip', 
  files = 'file.pdf',
  extras = list(paste("--password", 'pwd123'))
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marc in the box