<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shalini Battoo</title>
    <description>The latest articles on DEV Community by Shalini Battoo (@shalinibattoo).</description>
    <link>https://dev.to/shalinibattoo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F477908%2Fb1e6b787-a2fc-4a14-90fb-888331313f07.png</url>
      <title>DEV Community: Shalini Battoo</title>
      <link>https://dev.to/shalinibattoo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shalinibattoo"/>
    <language>en</language>
    <item>
      <title>Calling Python from R</title>
      <dc:creator>Shalini Battoo</dc:creator>
      <pubDate>Mon, 12 Oct 2020 15:41:08 +0000</pubDate>
      <link>https://dev.to/shalinibattoo/calling-python-from-r-e6f</link>
      <guid>https://dev.to/shalinibattoo/calling-python-from-r-e6f</guid>
      <description>&lt;p&gt;There is a constant debate regarding the best tool for data science and machine learning between R and Python. I feel both of them have their pros and cons and it really depends on the task at hand, the requirement from a client in case of a project or just personal likeness for a developer/coder.&lt;/p&gt;

&lt;p&gt;We will not get into a debate about the best tool in the market. Rather what I want to discuss is about using both of them together. &lt;br&gt;
Why use one, when we can get &lt;em&gt;Best of Both the worlds&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The library used in R to connect to Python is &lt;strong&gt;reticulate&lt;/strong&gt;.&lt;br&gt;
In case you have never worked with reticulate earlier, you will not have in the package library of R. It needs to be installed. This can be done by writing&lt;br&gt;
&lt;code&gt;install.packages(reticulate)&lt;/code&gt;&lt;br&gt;
The library can be loaded by using the function given below once it is successfully installed.&lt;br&gt;
&lt;code&gt;library(reticulate)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In order to run any script of python from R we will use the functions &lt;code&gt;source_python()&lt;/code&gt; and &lt;code&gt;py_run_file()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The first function makes the objects created available in the R environment. The second function creates a &lt;em&gt;py&lt;/em&gt; object which allows to access the other objects created by calling the python script. It creates a dictionary (type of a variable in python) associated with code execution.&lt;/p&gt;

&lt;p&gt;For example if we have a script &lt;em&gt;abc.py&lt;/em&gt;, then this can be run by using the function &lt;code&gt;source_python('abc.py')&lt;/code&gt;. In case the script consists of some function &lt;em&gt;xyz(p,q)&lt;/em&gt;, where p and q are the arguments being passed to the function xyz. After the script is sourced this function can be directly called in R.&lt;/p&gt;

&lt;p&gt;This package is very powerful and has other functions for making the integration between Python and R easier. In case you want to know about the other functions available in the library, refer to the &lt;a href="https://cran.r-project.org/web/packages/reticulate/reticulate.pdf"&gt;Link&lt;/a&gt; &lt;br&gt;
I hope this proves helpful in case you are trying to call Python scripts from R and take advantage of the strengths of Python from within R.&lt;/p&gt;

</description>
      <category>python</category>
      <category>rprogramming</category>
      <category>datascience</category>
      <category>machinelearning</category>
    </item>
  </channel>
</rss>
