---
title: "consolidatePacks"
author: Barry Zeeberg [aut, cre]
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{consolidatePacks}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

<style>
body {
text-align: justify;
font-size: 16pt;
font-family: Times;}
</style>

<p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif;
color:red'>consolidatePacks<o:p></o:p></span></b></p>

<p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'><o:p>&nbsp;</o:p></span></b></p>

<p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'><o:p>&nbsp;</o:p></span></b></p>

<p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>Barry
Zeeberg<o:p></o:p></span></b></p>

<p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>barryz2013@gmail.com<o:p></o:p></span></b></p><br>

<p class=MsoNormal style='text-align:justify'><span style='font-size:16.0pt;
font-family:"Times New Roman",serif'></p><br>

<p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>Motivation<o:p></o:p></span></b></p>

The purpose of this package is to remove the '@import' dependence of your package
  by consolidating the functions into your package. This may be necessary when the imported
  package is decommissioned by CRAN, and you do not want your dependent package to also
  be decommissioned.
  
  <br>
  <p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>Methods<o:p></o:p></span></b></p>
  
The functions in this package recursively retrieve dependencies in your package, and
copy the retrieved functions to the .R file. They also perform other needed
bookkeeping, such as retrieving .Rd files in the man subdirectory.

  <p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:
normal'><span style='font-size:16.0pt;font-family:"Times New Roman",serif'>Results<o:p></o:p></span></b></p>

This package was developed when my package *foodwebWrapper* faced being decommissioned from CRAN because an imported package *mvbutils* was going to be decommissioned. I decided to retrieve foodweb(), which is the one function from *mvbutils* that *foodwebWrapper* needs. Of course the foodweb() dependencies also needed to be retrieved recursively.

Before invoking drDriver(), you need to make sure that both your package and the package containing the dependencies are loaded in the search() path. If the package containing the dependencies contains any functions that are not exported, then the functions must be copied and pasted into the Console in which the driver will be invoked.

Some consistency checking and other tasks are automatically performed when the driver is invoked, including making a working copy of your package directory.

The driver was invoked by

```
drDriver(f="foodwebWrapper",r="/Users/barryzeeberg/personal/
mvbutil_download/mvbutils/",pack2Copy="/Users/barryzeeberg/
personal/hearts/hearts_card_game_bayesian_inference/packages/
foodwebWrapper",verbose=2)
```
Here are some annotated snippets of the transaction log:

<br>
**Partial Trace of the Recursion . . .**

```
[1] _________________________________________
[1] Recursion Level = 1
[1] foodwebWrapper
[1] 
[1] Function Number = 1 Function = foodwebWrapper
[1] functions list:
[1] foodweb
[1] _________________________________________
[1] Recursion Level = 2
[1] foodweb
[1] 
[1] Function Number = 1 Function = foodweb
[1] functions list:
[1] find.funs            %is.a%               extract.named        %matching%           find.web             organize.web.display
[1] _________________________________________
[1] Recursion Level = 3
[1] find.funs            %is.a%               extract.named        %matching%           find.web             organize.web.display
[1] 
[1] Function Number = 1 Function = find.funs
[1] functions list:
[1] named    lsall    %except% mcachees pos      as.env  
[1] _________________________________________
```
<br>
**Partial Transaction Log for Copying Files . . .**
```
[1] addMan copying: 
[1] from /Users/barryzeeberg/personal/mvbutil_download/mvbutils//foodweb.Rd 
[1] to /var/folders/3g/1drmqz0j5dq0xv88h3cg2k080000gn/T//RtmpC0Fwy1/foodwebWrapper/man/foodweb.Rd
[1] addMan copying: 
[1] from /Users/barryzeeberg/personal/mvbutil_download/mvbutils//find.funs.Rd 
[1] to /var/folders/3g/1drmqz0j5dq0xv88h3cg2k080000gn/T//RtmpC0Fwy1/foodwebWrapper/man/find.funs.Rd
[1] addMan copying: 
[1] from /Users/barryzeeberg/personal/mvbutil_download/mvbutils//%is.a%.Rd 
[1] to /var/folders/3g/1drmqz0j5dq0xv88h3cg2k080000gn/T//RtmpC0Fwy1/foodwebWrapper/man/%is.a%.Rd
```
<br>
**Might Need a Small Amount of Manual Tuning before Importing into RStudio . . .**
```
The driver provides the option implement check() at the end of the processing stream. This allows you to catch glitches that you might need to correct by hand before importing into RStudio. In my case, I ran into some missing globals definitions, etc.
```

<br>
**Reminders for Wrapping up . . .**
<br>
Note that the working version of the package is located in a path name that (at least on mac computer) is "private," and it is difficult to figure out how to get your hands on it. So I provide a brief instruction for how to do so.

Also, if you are happy with the enhanced working package, it is safest to make a copy of it because the driver may inadvertently overwrite this version.
```
[1] "Remember to update version number and date in the DESCRIPTION file"
[1] "To open the package in RStudio, Finder > Open Project in New Session . . ."
[1] "For mac, press Command + Shift + G to open the 'Go to the folder' window"
[1] "Then copy and paste e.g. /var/folders/3g/1drmqz0j5dq0xv88h3cg2k080000gn/T//RtmpC0Fwy1 into the 'Go to the folder' window"
```
