[R] Illustrating use of R package

Duncan Murdoch murdoch.duncan at gmail.com
Sun May 17 15:27:21 CEST 2015

Lots of questions.  I'm only answering some of them, inline.

On 15/05/2015 9:04 PM, Glenn Schultz wrote:
> I have an R package Bond Lab which actually supports a book Investing in MBS using R and Open Source Computing.  The Bond Lab beta is stable.  I have also created a package companion to investing in MBS.  Both are on my Github site
> https://github.com/glennmschultz/
> I wrote the companion as functions for each chapter calling source code.  I really don't like the way it works presentation wise but the user could see the code used.  Further, the user must create a directory and copy the source into the directory.  Further the source runs all examples at once which seems a little confusion.  However, to illustrate a function for chapter example I think I have to make a function to call a function which does not make sense.
> My first question, any suggestions on illustrating function call aside from the strategy I am using.  I am not a fan of what I am doing.
> My second question regards on.load() vs. on.attach() Bond Lab needs to create the BondLab directory which installs in the BondLab library to the ~/users directory, the same for the companion.  
> I think I should use on.load(), correct?

Almost certainly.  Only use on.attach() if the action depends on whether
the package functions are visible to the user (as opposed to being only
visible to some other package that is using it).  If you want the same
actions regardless of visibility, use on.load().

> I am not sure how to do this and will the same function work for both Windows and MAC?  

dir.create() will, but you need to be careful how you specify paths.  If
you use system.file() to construct the path you should be okay.

> Do I need different copy from path for Windows and MAC or can it be generic since the copy happens at load.
> I would like to get Bond Lab on CRAN.  I read CRAN rules require a yes/no from the user to write a directory.  So, I need to write an on.load() function for both Bond Lab and the Companion.  Also, CRAN requires that a package works on at least two systems so I need to figure out the Windows build.  This leads to another question.
> Can I somehow make a windows binary on a MAC?

Yes, you can use VirtualBox or some other VM or emulator to run Windows
on a Mac.  (Theoretically there are other ways that stay purely within
Mac OS, but they are not supported.)

> If not, can I emulate Windows on a MAC and make a binary?  Seems like this may not be 100%.
> Will I actually have to buy a windows machine to build the windows binary for CRAN?

You don't need to make a Windows binary at all, except for local
testing.  You only need to make the tarball, and CRAN will build the binary.

However, testing is important.  You should use
win-builder.r-project.org to build and test for Windows if you're doing
OS-specific things.

Duncan Murdoch

> Glenn  
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list