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

Run Multiple Windows System Commands Interactively From Within R

$
0
0

I am trying to build an R package for Windows 10 that will allow me to use the Secure File Transfer Protocol (SFTP) client of PuTTY, PSFTP from within the R console to transfer files back and forth to an SFTP server (yes, I realize there are other packages out there that can do do SFTP transfers, but I really want to develop this to work specifically with PSFTP). I think I can get this working if I can simply overcome one obstacle that I don't know how to implement in R. Is there a way I can call the windows system command and start it as a session of sorts so I can continue to work with it interactively from within R? I essentially just want to take commands from the R console and pass them into the same windows command line window having one command execute following the previous commands.

A simple toy example will help me explain what I'm trying to do. Let's say I have to execute multiple Windows system commands in R, line-by-line, like using cd .. to change the directory back one level and then list the contents with dir. I could try this:

system("cmd.exe", input="cd ..")
system("cmd.exe", input="dir")

Obviously this won't work the way I want it to because the there is no "memory" of the first line of code having been executed on the windows system, when I execute the second line. What I'd like is to have some way, within R to create code like that above so that it would be equivalent to my running a command prompt from a single cmd window and typing the following commands one by one:

cd ..
dir

In the end, I want to be able to create a Windows Session of sorts—sort of like the way the rvest package works. In rvest, users can create a session and then then sequentially send commands to the session and each subsequent command picks up where the last command left off in the session:

library(rvest)
session <- html_session("http://hadley.nz")
jump_to(session, "hadley-wickham.jpg")  #this continues with the session via first argument

I basically want to implement the same concept as this, where my subsequent lines continue from the previous ones. Is this possible? How would I go about doing this with the "cd ..", "dir" example above? If I can figure that out, I think I'm off to the races.

Thanks.


Viewing all articles
Browse latest Browse all 201839

Trending Articles