Sam Zipper
Sam Zipper

Reputation: 652

Running Plink from within R

I'm trying to use a Windows computer to SSH into a Mac server, run a program, and transfer the output data back to my Windows. I've been able to successfully do this manually using Putty.

Now, I'm attempting to automate the process using Plink. I've added Plink to my Windows Path, so if I open cmd and type in a command, I can successfully log in and pass commands to the server: Works manually!

However, I'd like to automate this using R, to streamline the data analysis process. Based on some searching, the internet seems to think that the shell command is best suited to this task. Unfortunately, it doesn't seem to find Plink, though passing commands through shell to the terminal is working:

Plink not recognized

If I try the same thing but manually setting the path to Plink using shell, no output is returned, but the commands do not seem to run (e.g. TESTFOLDER is not created):

enter image description here

Does anyone have any ideas for why Plink is unavailable when I try to call it from R? Alternately, if there are other ideas for how this could be accomplished in R, that would also be appreciated.

Thanks in advance, -sam

Upvotes: 0

Views: 6082

Answers (2)

Sam Zipper
Sam Zipper

Reputation: 652

Just saw Caitlin's response and it reminded me I hadn't ever updated with my solution. My approach was kind of a workaround, rather than solving my specific problem, but it may be useful to others.

After adding Plink to my PATH, I created a batch script in Windows which contained all my Plink commands, then called the batch script from R using the command shell:

So, in R:

shell('BatchScript.bat')

The batch script contained all my commands that I wanted to use in Plink:

:: transfer file to phosphorus
pscp C:\Users\Sam\...\file zipper@144.**.**.208:/home/zipper/

:: open connection to Dolphin using plink
plink -ssh zipper@144.**.**.208 Batch_Script_With_Remote_Machine_Commands.bat

:: transfer output back to local machine
pscp zipper@144.**.**.208:/home/zipper/output/ C:\Users\Sam\..\output\

Hope that helps someone!

Upvotes: 0

Caitlin Collins
Caitlin Collins

Reputation: 49

I came here looking for an answer to this question, so I only have so much to offer, but I think I managed to get PLINK's initial steps to work in R using the shell function...

This is what worked for me:

NOT in R:

Then, in R:

## Set your working directory as the path to the PLINK program files: ##
setwd("C:/Program Files/plink-1.07-dos")

##  Use shell to check that you are now in the right directory: ##
shell("cd")

## At this point, the command "plink" should be at least be recognized
# (though you may get a different error)
shell("plink")

## Open the PLINK example files ##
# FYI mine are in "C:/PLINK/", so replace that accordingly...
shell("plink --file C:\\PLINK\\hapmap1") 

## Make a binary PED file ##
# (provide the full path, not just the file name)
shell("plink --file C:\\PLINK\\hapmap1 --make-bed --out C:\\PLINK\\hapmap1")

... and so on.

That's all I've done so far. But with any luck, mirroring the structure and general format of those lines of code should allow you to do what you like with PLINK from within R.

Hope that helps!

PS. The PLINK output should just print in your R console when you run the lines above.

All the best,
- CC.

Upvotes: 2

Related Questions