title: Maintaining a local repository for both Windows and Linux
body: <p>I have some R code that I'd like to share with other people in my office, and also run periodically on our servers. We all have Windows 7 desktops, and the servers run Red Hat Enterprise Linux. </p>
  
  <p>I've been through the docs, and I'm stuck. None of the following have all the necessary steps, detail the correct folder structure, or tell me how to build a Linux package, or build a Windows package on Linux. </p>
  
  <ul>
  <li><a href="http://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf" rel="nofollow noreferrer">http://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf</a></li>
  <li><a href="http://cran.r-project.org/doc/manuals/R-admin.html#Setting-up-a-package-repository" rel="nofollow noreferrer">http://cran.r-project.org/doc/manuals/R-admin.html#Setting-up-a-package-repository</a> </li>
  <li><a href="https://stackoverflow.com/questions/2905650/creating-a-local-r-package-repository">Creating a local R package repository</a></li>
  </ul>
  
  <p>So I have my code in git.</p>
  
  <pre><code>$ mkdir ~/daveStuff
  $ cd ~/daveStuff
  $ git init
  $ git remote add origin git@davez0r.co:/opt/git/daveStuff.git
  $ git pull origin master
  </code></pre>
  
  <p>Now in my home directory I have this folder structure:</p>
  
  <pre><code>daveStuff
  |-- DESCRIPTION
  |-- R
      |-- stuff.R
  |-- exec
      |-- script.R
  </code></pre>
  
  <p>My description file looks like this:</p>
  
  <pre><code>Package: daveStuff
  Type: Package
  Title: What the package does (short line)
  Version: 1.0
  Date: 2014-02-03
  Author: Who wrote it
  Maintainer: Who to complain to &lt;yourfault@somewhere.net&gt;
  Description: More about what it does (maybe more than one line)
  License: What license is it under?
  </code></pre>
  
  <p>I'm running apache on one of my servers. So I added this:</p>
  
  <pre><code>/var/www/html/R/src/contrib/3.0/
  </code></pre>
  
  <p>This correctly maps to the following, where I read any files I put there:</p>
  
  <pre><code>http://davez0r.co/R/src/contrib/3.0/
  </code></pre>
  
  <p>What I'd like to be able to do is the following, from either Windows or Linux:</p>
  
  <pre><code>&gt; install.packages("daveStuff", repos="http://davez0r.co/R", type="source")
  &gt; library(daveStuff)
  </code></pre>
  
  <p>So first step is that I need to turn my library into a package.</p>
  
  <pre><code>$ cd ~   # one under the "daveStuff" directory
  $ R CMD build daveStuff
  </code></pre>
  
  <p>This creates a zip file:</p>
  
  <pre><code>~/daveStuff_1.0.tar.gz
  </code></pre>
  
  <p>Now I copy that file to my repository location:</p>
  
  <pre><code>$ cp ~/daveStuff_1.0.tar.gz /var/www/html/R/src/contrib/3.0/
  </code></pre>
  
  <p>Now if I go like this:</p>
  
  <pre><code>&gt; install.packages("daveStuff", repos="http://davez0r.co/R", type="source")
  
   Warning in install.packages :
     unable to access index for repository http://davez0r.co/R/src/contrib
  </code></pre>
  
  <p>It gives me that error message saying that it can't find the package. So I create a package manifest:</p>
  
  <pre><code>$ cd /var/www/html/R/src/contrib # one under where I put the archive
  $ Rscript -e 'tools::write_PACKAGES(".", type="source", subdirs=TRUE)'
  </code></pre>
  
  <p>This gives me a <code>PACKAGES</code> file:</p>
  
  <pre><code> Package: daveStuff
   Version: 1.0
   MD5sum: 817bbfedeb218ce0331dd7108408c5e6
   NeedsCompilation: no
   Path: ./3.0
  </code></pre>
  
  <p>Now it works when I try to load it:</p>
  
  <pre><code>&gt; install.packages("daveStuff", repos="http://davez0r.co/R", type="source")
  </code></pre>
  
  <p>Unresolved issues:</p>
  
  <ul>
  <li>I've lost the scripts that were in the <code>exec</code> directory.
  
  <ul>
  <li>Should I wrap these in functions and include them in the library? </li>
  </ul></li>
  <li>Should I stick with <code>source</code> packages? 
  
  <ul>
  <li>How do I make Windows binary packages on Linux?</li>
  </ul></li>
  </ul>