Recently I was trying to make a package in R. As always I searched on internet. I realised that many people have discussed the technique of package making. But there are lot of complexities involved in the procedure, probably that is why I was stuck for too long. I went through many different manuals, but somehow, they were too much for my level. I wanted some very simple steps, very basic ones. Since I was a starter, so I wanted to get one in working condition and then refine it further. I found Rob J Hyndman's discussion quite useful. I am presenting here a further simplified version (which worked for me) of his steps:
Step.1- Install R tools (available on the web).
Step.2 - Goto Control Panel -> System -> Advanced System Settings-> Environment Variables -> System Variables
Edit the variable with name Path as follows:
Add C:\Program Files\R\R-2.15.1\bin\i386;c:\Rtools\bin; c:\Rtools\MinGW; c:\Perl\bin; (where first directory should be the one which contains R-executable) to already existing C:\Program Files\MiKTeX 2.7\miktex\bin; %SystemRoot%\system32; %SystemRoot%; %SystemRoot%\System32\Wbem; %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\; C:\Program Files\MATLAB\R2008a\bin; C:\Program Files\MATLAB\R2008a\bin\win32
etc.
Step.3 - Goto DOS prompt and type the following
- PATH
Add C:\Program Files\R\R-2.15.1\bin\i386;c:\Rtools\bin; c:\Rtools\MinGW; c:\Perl\bin; (where first directory should be the one which contains R-executable) to already existing C:\Program Files\MiKTeX 2.7\miktex\bin; %SystemRoot%\system32; %SystemRoot%; %SystemRoot%\System32\Wbem; %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\; C:\Program Files\MATLAB\R2008a\bin; C:\Program Files\MATLAB\R2008a\bin\win32
etc.
Step.3 - Goto DOS prompt and type the following
- PATH
- R.exe (R should boot up from any directory if above step is correct)
Step.6 - For compiling goto DOS prompt in the directory containing your package and type
Rcmd INSTALL --build basicpack
Step.7 - To check that the package satisfies the requirements for a CRAN package, use
Rcmd check basicpack
The checks are quite strict. A package will often work ok even if it doesn’t pass these tests. But it is good practice to build packages that do satisfy these tests as it may save problems later.
Step.4 - Create an R workspace containing all the relevant functions and data sets that you want to include in the package. Delete anything from the workspace that you do not want to include in the package.
Set the current directory to where ever you want create the package.
Step.5 - To create a package called basicpack, use the R command
package.skeleton(name="basicpack")
This will generate a directory fred and several sub-directories in the required structure. A package consists of a directory containing a file ‘DESCRIPTION’ and usually has the subdirectories R, data and man.The package.skeleton command above will have created the required files and directories. You now need to edit them so they contain the right information. To start with one may not edit all of them. There is only one field which is compulsory to edit, without which you cannot proceed. Goto the directory where you have created the skeleton of the package, you will see a folder with package name i.e. basicpack -> man
You will see some R files. Each of which will have a \title{ } field, which will be empty. To install your package, you need make this field non-empty in each R-file.
Step.6 - For compiling goto DOS prompt in the directory containing your package and type
Rcmd INSTALL --build basicpack
Step.7 - To check that the package satisfies the requirements for a CRAN package, use
Rcmd check basicpack
The checks are quite strict. A package will often work ok even if it doesn’t pass these tests. But it is good practice to build packages that do satisfy these tests as it may save problems later.
With this you have a package in working condition, which you can install from local zip file and it will be available in the list of Packages in your R window. The steps I have discussed, will only help you make a very basic and raw package. Offcourse there is lot more to package making. Like one needs to add descriptions, examples, add namespaces, datasets, bring dependency on other packages, help file, and much more. I think lot of information about these steps is available on internet. I have not explored any of these yet. Its like I was unable to stand, and people were giving me a mixed guide on how to stand, walk and run :(