Jon Olav Skoien
2008-Oct-30 19:08 UTC
[Rd] Small modification of zip.file.extract in utils?
Dear list, I needed to extract a zip-archive, and found zip.file.extract in utils. My only problem was the use of tempdir(), since I wanted to permanently extract the archive at a fixed location for later use. My own fix was simple, adding an extra parameter zipdir (without default), and within the function change tmpd <- tempdir() to tmpd = ifelse(missing(zipdir),tempdir(),zipdir) This modification could maybe be useful also for other users, unless there are some problems I am not aware of? Cheers, Jon
Duncan Murdoch
2008-Oct-30 20:07 UTC
[Rd] Small modification of zip.file.extract in utils?
On 10/30/2008 3:08 PM, Jon Olav Skoien wrote:> Dear list, > > I needed to extract a zip-archive, and found zip.file.extract in utils. > My only problem was the use of tempdir(), since I wanted to permanently > extract the archive at a fixed location for later use. My own fix was > simple, adding an extra parameter zipdir (without default), and within > the function change > tmpd <- tempdir() > to > tmpd = ifelse(missing(zipdir),tempdir(),zipdir) > > This modification could maybe be useful also for other users, unless > there are some problems I am not aware of?I won't comment on the value of the extra parameter, but the implementation would be simpler if you set the default for zipdir to tempdir(), and then just used zipdir in place of tmpd throughout. Duncan Murdoch
On Thursday 30 October 2008 (20:08:27), Jon Olav Skoien wrote:> Dear list, > > I needed to extract a zip-archive, and found zip.file.extract in utils. > My only problem was the use of tempdir(), since I wanted to permanently > extract the archive at a fixed location for later use. My own fix was > simple, adding an extra parameter zipdir (without default), and within > the function change > tmpd <- tempdir() > to > tmpd = ifelse(missing(zipdir),tempdir(),zipdir) > > This modification could maybe be useful also for other users, unless > there are some problems I am not aware of?I had similar problems with 'zip.file.extract' and implemented a function 'unzip' in my package 'memisc', which also works in a way that is probably more comprehensible for end-users like me: unzip package:memisc R Documentation Extract Files from Zip Files Description: 'unzip' extracts a file from a zip archive and puts them into a directory specified by the user or into the temporary directory of the current session. Usage: unzip(zipfile,item, dir=tempdir(),package=NULL) Arguments: zipfile: a character string, the path to the zip file. item: a character string, full path (from the root of the zip file) to the file to extract. dir: path to the directory were to place the extracted file. package: optional package name, if given, the path to the zipfile starts in the package's root directory. Examples: # Extract American National Election Study of 1948 # It is item "NES1948.POR" in zip file "anes/NES1948.ZIP" # where this path is relative to the packages' # root directory. nes1948.por <- unzip("anes/NES1948.ZIP","NES1948.POR", package="memisc") nes1948.por All the best, Martin