I currently have some code in an R package that unzips and reads in a CSV file. Reproducible example here:
url <- paste0("http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/F-F_Momentum_Factor_CSV.zip")
temp <- tempfile()
download.file(url,temp,quiet=TRUE,mode="wb")
data <- data.table::fread(unzip(file.path(temp)),fill=TRUE,skip=13)
This leaves a CSV file in my working directory. What is the best practice way to do this without leaving a CSV in the users directory? I've tried unzipping to a temp file but fread doesn't seem to like reading that in.
Thanks for the reply. My code does get rid of the zip file but I am still left with the unzipped CSV file (F-F_Momentum_Factor.CSV) in my working directory. I am trying to find a solution to stop the unzipped file from going to the working directory and ideally without having to know the name of the file in advance as I could obviously just use file.remove on the unzipped file if I know the name in advance.
Here, I unzip to a temp folder and a temp file without ever having to know the name of the file itself. You can see in the temp folder/file assigned to the variables in case you would like to double check.