Step 10. Build
The last step in our process will cover how you build a package. You have two options here. You can build for CRAN or you can just do a locale build for yourself and other windows users. I will cover the build for CRAN as that is more detailed and then show you how to build for your local machine. Its not a huge difference. When you build for CRAN you build and check. This is to insure that you pass all the CRAN tests. The output when you are done is a ”tar.gz” file which you upload to CRAN. Then the build process is repeated and your source is used to build a OSX binary and a windows binary. The windows binaries are in zip files. My work flow goes like this. I build EVRYTHING as if I am building for CRAN. That means I write all documents and I pass all checks. Then I build again for windows and produce a ‘zip’ binary. In short I do the following
1. R CMD build mypkg ( generates tar.gz for cran)
2. R CMD check mypkg_1.o.tar.gz
3 R CMD INSTALL –build mypkg ( gets me a local windows binary zip file )
But lets walk through that step by step.
PART ONE: Building for CRAN.
If you followed all the steps you should have all the files you need in a “mypkg” directory below TestPackage. Issue the following command
C:\Users\steve\Documents\TestPackage> R CMD build mypkg
You should see the following:
The build command has created a file called mypkg_1.0.tar.gz. That is the file we would upload to CRAN. They would use that file to create the binaries for windows and OSX.
Before we submit to CRAN however we have to ”check” the package. At the prompt enter ” R CMD check mypkg_1.0.tar.gz
When you do that you will see the following:
Look carefully and you will see that I have generated one “NOTE”. When you run check you can generate NOTES, warnings, and errors. You should fix these before submitting to CRAN. In fact you have to fix all warnings and errors and most Notes. The note I generated here can be fixed easily by editing the Rd files ( the package description and description file so that we use GPL-2 as opposed to GPL 2).
Now, there is one last detail. The “check” command has various flags. If you want to see the flags type R CMD check –help. If you do that you will see that we should run “check” with the following flag: R CMD check –as-cran mypkg. This check will look at one very important thing. Check out the screen
If you read through that you will see that ”check” has gone out and looked at CRAN to see if my package is a new package or not. And its generated a NOTE telling me that I am a new submission. That’s important because of the rules you have to follow when you submit: Those rules are found here. PLEASE REVIEW THEM. Pay careful attention to the submission guidelines, for example “For a new submission, confirm in your email that you have read and agree to these policies. (This includes new versions of previously archived packages, and the first submission as the new maintainer for a package.)” If you submit a new package without this email ( AS I have ) you WILL get a WELL DESERVED nastygram telling you to follow submission policies. Also, don’t do boneheaded things like submitting multiple versions before the first gets posted. In my excitement I once posted version 1.4, then a few hours later had another version, 1.5 and then a third 1.6. CRAN doesn’t like that and you will be informed.
For part two lets suppose that you want to build the windows binary or the “zip” file and then you want to install it on your machine. For this you can just issue the following command: ”R CMD INSTALL –binary mypkg
Do that and you will have a ”zip” version. Then you switch to R Studio, select ”Packages”. Then select ‘install packages’. Then install from local zip archive. Load the library library(mypkg) and you are good to go.
So shutdown R, restart and load the package library. Then you can enter ?f to get help on the “f” function
And you are done. There are a lot more details covered in the documentation. But this should help you get started making packages, simple packages, on Windows.
You can explore various options with the R commands by doing R CMD INSTALL –help. this works for any of the commands
Finally before you submit your package to CRAN read the policies. When you submit a package for the first time there are some steps you have to take in your submission email to CRAN.