git » homepage.git » master » tree

[master] / md / TechWorks / authored / wondr / posts / package-development-windows.html

<html>
  <head>
    <title>R Package Development on Windows - wondr</title>
    <link rel="stylesheet" href="../style.css"/>
    <link rel="stylesheet" href="../code_highlight.css"/>
    <link rel="alternate" type="application/atom+xml" href="../atom.xml"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  </head>
  <body class="page">
    <div class="site">
      <header id="header" class="header-container">
        <div class="site-header">
          <nav id="navmenu" aria-label="Main Menu">
            <ul class="main-menu">
              <li>
                <a href=".." aria-current="page">Index</a>
              </li>
            </ul>
          </nav>
          <div class="site-info">
            <h1 class="site-title title">Wondr</h1>
            <p class="site-description">Wondering about R</p>
          </div>
        </div>
      </header>
      <main class="main">
        <article lang="en" class="entry">
          <header class="entry-header">
            <div class="entry-info">
              <h1 class="entry-title title">R Package Development on Windows</h1>
            </div>
            <div class="meta">
              <span class="posted-on">
                <svg class="icon" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" aria-hidden="true">
                  <rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect>
                  <line x1="16" y1="2" x2="16" y2="6"></line>
                  <line x1="8" y1="2" x2="8" y2="6"></line>
                  <line x1="3" y1="10" x2="21" y2="10"></line>
                </svg>
                <span class="screen-reader">Posted on </span>
                <time class="date" datetime="2018-12-18T00:00:00Z">2018-12-18</time>
              </span>
              <span class="reading-time">
                <svg class="icon" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" aria-hidden="true">
                  <circle cx="12" cy="12" r="10"></circle>
                  <polyline points="12 6 12 12 15 15"></polyline>
                </svg>
                3 minute read
              </span>
            </div>
          </header>
          <div class="entry-content">
<p>Windows 10 is a totally capable platform for developing R applications and packages and collaborating with others on <a href="https://github.com/">Github</a>. You just need to install and configure the right tools.</p>
<h1 id="r">R</h1>
<p>First (duh!) you need to install R. Download an installer from <a href="https://cran.r-project.org/bin/windows/base/">the Windows downloads page</a>. If you’ve already installed R but are not on the latest released version, it’s not a bad idea to uninstall what you have and install the latest.</p>
<h1 id="rtools">RTools</h1>
<p>Download the version of <a href="https://cran.r-project.org/bin/windows/Rtools/">RTools</a> corresponding to the version of R you just installed and run the installer.</p>
<p>The default selections are all fine, except one: <strong>make sure the checkbox labeled “Add rtools to system PATH” is checked when you see it.</strong></p>
<p>If you don’t select this option, you will have problems building R packages in RStudio later.</p>
<h1 id="rstudio">RStudio</h1>
<p>The RStudio IDE works nicely on Windows and can be <a href="https://www.rstudio.com/products/rstudio/download/">downoloaded for free</a>.</p>
<h1 id="chocolatey">Chocolatey</h1>
<p><a href="https://chocolatey.org/">Chocolatey</a> is a package manager for Windows that facilitates installing and upgrading free software like <code>git</code> and <code>ssh</code>, which are two tools I suggest installing.</p>
<p>To install it, just <a href="https://chocolatey.org/install">follow the instructions</a>.</p>
<h1 id="git"><code>git</code></h1>
<p>Now that you’ve installed Chocolatey, installing <code>git</code> is a cinch. In an <em>Administrative</em> PowerShell window, run the following commands:</p>
<pre><code>choco install git</code></pre>
<h1 id="ssh-optional"><code>ssh</code> (optional)</h1>
<p>On Github, you have the option of cloning repositories using either <a href="https://help.github.com/articles/which-remote-url-should-i-use/">HTTPS or SSH</a>. I personally prefer SSH, because I clone repos all the time and I don’t like to be constantly prompted for my username and password.</p>
<p>If you’re new to <code>git</code> and Github, I suggest skipping this step. Otherwise, you can install <code>ssh</code> with <code>choco install openssh</code>.</p>
<h1 id="configure-git">Configure <code>git</code></h1>
<p>Windows uses a different character than Mac or Linux to represent the end of a line — the character inserted when you press <em>Enter</em> — which can make it difficult to collaborate on text files with users on a different platform.</p>
<p>For those on Windows, <code>git</code> can be configured to automatically to handle this difference by running the following command in a (non-Administrator) PowerShell:</p>
<pre><code>git config --global core.autocrlf true</code></pre>
<p>For details on this setting, check out the <a href="https://help.github.com/articles/dealing-with-line-endings/">Github documentation on the subject</a>.</p>
<h1 id="configure-rstudio-to-use-git">Configure RStudio to use <code>git</code></h1>
<p>Now that <code>git</code> is installed and configured, you can configure RStudio to use it. This will allow you to drive <code>git</code> from RStudio, without necessarily using the command line.</p>
<ol type="1">
<li>Open RStudio</li>
<li>Under the <strong>Tools</strong> menu, select <strong>Global Options</strong></li>
<li>Click on <strong>Git/SVN</strong> in the resulting Options window</li>
<li>Select <strong>Enable version control interface for RStudio projects</strong></li>
<li>Next to <strong>Git executable</strong> click <strong>Browse</strong></li>
<li>Navigate to <code>C:\Program Files\Git\bin\git.exe</code> and click <strong>Open</strong>. This is where Chocolatey installed <code>git</code>.</li>
<li>Click the <strong>Apply</strong> button and restart RStudio</li>
</ol>
<p>Now in RStudio, you should see a tab called <code>Git</code> in the top right quadrant of the window. This tab is the entrypoint for staging, diffing, committing, and pushing to Github.</p>
<p>Additionally, you can now use RStudio to clone projects from Github:</p>
<ol type="1">
<li>Under the <strong>File</strong> menu select <strong>New Project</strong></li>
<li>On the resulting window select <strong>Version Control</strong></li>
<li>On the window after that, select <strong>Git</strong>, and paste in the clone URL from the project’s Github page</li>
</ol>
<h1 id="conclusion">Conclusion</h1>
<p>Congrats! You’re all set up to develop R applications, develop R packages, and interact with Github with the best of’em. From here, you can install standard R tools like the <code>devtools</code> and <code>usethis</code> packages.</p>
<p>For an introduction to R package development, RStudio’s <a href="https://support.rstudio.com/hc/en-us/articles/200486488-Developing-Packages-with-RStudio">Developing Packages with RStudio</a> is a good introduction.</p>
<p>Thanks for reading, I hope you have fun writing and sharing code!</p>
          </div>
        </article>
        <article data-sblg-article="1" class="entry-content"></article>
      </main>
      <footer id="footer" class="footer-container">



        <div class="footer">

<div class="social">
  <nav aria-label="Social Menu">
    <ul class="social-menu"><li>
      <a href="mailto:alan@tailrecursion.com" >
          <span class="screen-reader">Send E-mail</span>
          <svg class="icon" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" aria-hidden="true">
  
  <path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"></path>
  <polyline points="22,6 12,13 2,6"></polyline>
  
</svg>

        </a>
      </li><li>
        <a href="https://github.com/alandipert/wondr-blog" >
          <span class="screen-reader">Open Github account</span>
          <svg class="icon" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" aria-hidden="true">
  
  <path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22"></path>
  
</svg>

        </a>
      </li>

<li>
        <a href='https://twitter.com/alandipert' target='_blank' rel='noopener'>
          <span class='screen-reader'>Open Twitter account in new tab</span><svg class='icon' viewbox='0 0 24 24' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' aria-hidden='true'>
  
  <path d="M23 3a10.9 10.9 0 0 1-3.14 1.53 4.48 4.48 0 0 0-7.86 3v1A10.66 10.66 0 0 1 3 4s-4 9 5 13a11.64 11.64 0 0 1-7 2c9 5 20 0 20-11.5a4.5 4.5 0 0 0-.08-.83A7.72 7.72 0 0 0 23 3z"/>
  
</svg>
</a>
      </li>
    </ul>
  </nav>
</div>
        </div>
      </footer>
    </div>
  </body>
</html>