In R, use fread on a pipe shh connection

2

I have a virtual machine with many TXT files. I usually use an ssh and pipe connection to be able to read the files. When I use the read.csv function there is no problem at the time of reading the files. Already when I use the fread function, the business does not work. First show the case that works!

 # my directory with the plink intallation (plink.exe)
 dir<- "C/Tools/Terminal/"
 setwd(dir)

 user <- 'XXXXXX'
 password <- 'XXXX'
 dir_file_machine <- '/media/projects/'
 name_file <- 'XXXXXX.TXT'
 capture_file <- pipe(paste0('plink -ssh ', 
                              user, 
                              '@123.45.678.901 -P 12 -pw ', #fictice 
                              password, 
                              ' "cat ', 
                              dir_file_machine, 
                              name_file))

 a <- read.csv(capture_file, sep = ";")

Now when I use the fread function the following error occurs ...

 capture_file <- pipe(paste0('plink -ssh ', 
                              user, 
                              '@123.45.678.901 -P 12 -pw ', #fictional 
                              password, 
                              ' "cat ', 
                              dir_file_machine, 
                              name_file))

 a <- fread(capture_file, sep = ";")
 Error in fread(capture_file) : 
'input' must be a single character string containing a file name, a command, full path to a file, a URL starting 'http[s]://', 'ftp[s]://' or 'file://', or the input data itself

Any ideas?

    
asked by anonymous 29.07.2016 / 17:04

1 answer

2

Actually, to do this, just remove the pipe , since the fread itself already does the piping command:

capture_file <- paste0('plink -ssh ', 
                       user, 
                       '@123.45.678.901 -P 12 -pw ', #fictional 
                       password, 
                       ' "cat ', 
                       dir_file_machine, 
                       name_file)
a <- fread(capture_file, sep = ";")

Note that this is in documentation of fread :

  

input

     

Either the file name to read (containing no \ n character), a shell command that preprocesses the file (eg fread ("grep blah filename") or the input itself as a string at least one \ n), see examples. I

Font .

    
09.08.2016 / 05:15