Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I too had a problem with RPy2, and I never actually got it to work - after days and days of trying all different sorts of solutions. I encourage you to try all of the great ideas people are telling you, and I'm interested to see if any of them work!</p> <p>If you fail as I did, you may be able to use a workaround in the following way depending on your purposes:</p> <ol> <li><p>Write R code with all of the functions you would like to use which also calls the libraries you want to use. Put all of these functions and library calls into one file (temp.r). For example, maybe my file looks like<br> <pre><code> CurrentYear &lt;- function(birth.year,age) { year &lt;- birth.year + age return(year) } </pre></code></p></li> <li><p>Use python to prompt for user input to do function calls. I did this with a GUI, you can probably just do it with script in the terminal.</p></li> <li><p>Use python to create a string with the R function calls. For example, we might have <pre><code> stuff = '\nCurrentYear("%(birth.year)d", "%(age)d")\n' %vars() </pre></code> where <code>birth.year</code> and <code>age</code> have been input by the user in the python program. </p></li> <li><p>Add <code>stuff</code> to the end of <code>temp.r</code> using python: <pre><code> <code># Creates a copy of temp.r, so as not to disturb its contents for future use.</code> tocall = copyfile("C:\My Documents\temp.r", "C:\My Documents\tocall.r") <code># Open the copy with the intent to append it (hence the "a")</code> inp = open("C:\tocall.r", "a") <code># Adds the function call to the R script</code> inp.write(stuff) inp.close() <code># Navigate to the correct directory, use "Rscript" to</code> <code># run the code in the shell</code> dostuff = call('cd C:\My Documents &amp;Rscript temp.r', shell = True) </pre></code></p></li> <li>Profit</li> </ol> <p>I'm not sure what the disadvantages of this method are, but it works for me. Hope this helps if you fail with the whole RPy2 thing!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload