title: How to Call Python from R in a Windows OS?
body: <p>I'm looking for a way to call python within R on a Windows operating system. Since there appears to be no readily available R package for this (at least no package that's been updated recently), I'm looking for leads on how to write a set of commands in an R script that can then be sent in batch mode to python. </p>
  
  <p>In short, how can I call python from R in a Windows OS?</p>
  
  <p>Edit: To clarify, I am <strong>not</strong> asking about calling R from python; rather I am asking about calling python from R. </p>
  
  <p>Update: Based on what I've gathered so far, here's a basic set of commands on running python from R in a Windows OS:</p>
  
  <pre><code># (1) basic python commands called from R
  system('python -c "a = 2 + 2; print a"') 
  system('python -c "a = \'hello world\' ; print a; import pandas"')
  
  # (2) if you have a python file you've already created (which I've referred to as "my.py"), then you can run it in R as follows:
  system("python C:\\Users\\Name\\Desktop\\my.py")
  
  # or alternatively:
  system('python -c "import sys; sys.path.append(\'C:\\Users\\Name\\Desktop\'); import my;"')
  </code></pre>
  
  <p>Neither of these approaches is at the level of interactivity needed for fluid data analysis using python in R on a Windows OS. The most straightforward solution might be to write a simple R function that (1) exports a specified R data frame to python, (2) parses python syntax written in R (using <code>stringr</code> and <code>system('python -c')</code>), and then (3) optionally exports the data back to R. It'd be a pseudo-interactivity in R based on updating a temporary python file through the R console.</p>