Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

How can I extract files directly from a RAR archive in SFTP to .rda?

$
0
0

I need to read files from a RAR archive located in a STFP directly to R and there's no need to know the file names inside. Is that possible?

My code is this (I omit declaration of variables):

# Ruta SFTP - archivo rar
url_import_rar <- paste0(server,folder_in,rar_name)
#url_import <- paste0(server,folder_in,rar_name,folder,filename)

#Se importa el fichero desde el sftp
data_ftp <- getBinaryURL(url_import_rar, userpwd=userpwd)

#Se crea un fichero temporal con la misma extensión del fichero a guardar
temp <- tempfile(fileext = ".rar")
save(data_ftp, file = temp)

Until this point, a temporal rar file is created in a temporal directory. So, can I list files and extract the folder/s or files which are packed in the rar archive?

I tried this: con1 <- unz(temp, filename="uno.dat", open = "r") and it gets me:

Error in unz(temp, filename = "uno.dat", open = "r") : cannot open the connection In addition: Warning message: In unz(temp, filename = "uno.dat", open = "r") : cannot open zip file <'temp_path'>

and this: con2 <- unzip(temp) #, list = TRUE) gets me:

Warning message: In unzip(temp) : error 1 in extracting from zip file

and this: data <- read.table(unz(temp, "uno.dat")) gets me:

Error in open.connection(file, "rt") : cannot open the connection In addition: Warning message: In open.connection(file, "rt") : cannot open zip file <'temp_path'>

and this: td <- tempdir(); unzip(temp, exdir = td) gets me:

Warning message: In unzip(temp, exdir = td) : error 1 in extracting from zip file

And I'm kind of desperate. I've found many related posts, but I don't find exactly what I want to do, and what I find doesn't work, so can anybody help me or tell me if it's not possible?

Thank you!


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>