- Reference
1. For the detail, read the web page The R Manuals and
the PDF document Writing R Extensions (Chapter 1, 2, 3) in The R Manuals
(my mirror here).
2.
Making R Packages Under Windows: A Tutorial.
By P. Rossi.
(my mirror here).
3.
Creating FORTRAN 77 DLLs for R on a Windows PC.
By Jane L. Harvill and H. Joseph Newton.
(my mirror
here).
- Create
- This is the simplest example and mininize requirement to create a package.
- Create a directory "mypkg" as the following or obtain from
mypkg_0.1-1.tar.gz.
```
./mypkg
|-- COPYING
|-- DESCRIPTION
|-- INDEX
|-- R/
| |-- call_c.r
| |-- call_f.r
| `-- zzz.r
|-- README
|-- demo/
| |-- 00Index
| |-- RcallC.R
| `-- RcallF.R
|-- man/
| |-- test.c.Rd
| `-- test.f.Rd
`-- src/
|-- call_c.c
`-- call_f.f
4 directories, 14 files
```
- Download
- Linux: The complete package is mypkg_0.1-1.tar.gz.
- Windows: The complete package is mypkg_0.1-1.zip.
---
- The 'COPYING' file
Optional.
- The 'DESCRIPTION' file
Contains basic information about the package,
the fields 'Package', 'Version', 'License' 'Description', 'Title', 'Author', and 'Maintainer'
are mandatory. And the fields 'Depends' and 'Suggests' are
1. The necessary to successfully load must be listed in 'Depends'.
2. To successfully run R CMD check must be listed either in 'Depends' or 'Suggests'.
- The 'INDEX' file
- Optional.
- Automatically generated from Rdindex() from package tools.
- The 'R' subdirectory
- Contains R code files.
- The extension '.R' or '.r'.
- The 'call_c.r' and 'call_f.r' have created in
R_Call page and modify to suit the package.
- The 'zzz.r' for load the package.
- Put your R code in this subdirectory.
- The 'README' file
- Optional.
- Summary this package. Here, it record the process to build a package.
- The 'demo' subdirectory
- Optional.
- It will running via demo().
- The '00Index' contains the summarize for all demo function.
- The 'RcallC.R' and 'RcallF.R' are the part of 'cal_c.r' and 'call_f.r' have created in
R_Call page and modify to suit the package.
- The 'man' subdirectory
- Contains documentation files for the objects in the package in R document (Rd) format.
- The extension '.Rd'.
- The 'test.c.Rd' and 'test.f.Rd' are the document for function 'test.c' and 'test.f' which described in the
'call_c.r' and 'call_f.r' belong the 'R' subdirectory.
- The 'src' subdirectory
- Optional.
- Contains C, C++, FORTRAN source files and optionally file 'Makevars' or 'Makefile'.
- The 'call_c.c' and 'call_f.f' have created in
R_Call page and modify to suit the package.
- Put your source code (.c, .f, .cc) in this subdirectory.
---
- Compile & Build & Check
- Linux:
```
SHELL> R CMD build --force ./mypkg
SHELL> R CMD check ./mypkg
SHELL> R CMD build ./mypkg
```
1. 'build' will automatically create the 'INDEX' file if not exist.
2. 'check' will create a subdirectory "mypkg.Rcheck" and simulate the install process and test all function could work.
3. 'build' will create a tar.gz file, the package 'mypkg'.
And the process message may be like this "message.linux.txt".
- Windows:
Require some additional tools for build package or install from source code.
1. See the page Building R for Windows.
2. See also the Windows page to construction the environment for Windows.
After the environment ready, the build process as follow,
1. Download mypkg_0.1-1.tar.gz.
2. Unzip mypkg_0.1-1.tar.gz to C:\WINDOWS\DESKTOP
3. Open MS-DOS command mode.
```
C:\> COPY C:\WINDOWS\DESKTOP\MYPKG C:\PROGRA~1\R\RW1071\SRC\LIBRARY
C:\> C:\PROGRA~1\R\SET_BUILD
> CD C:\PROGRA~1\R\SRC\GNUWIN32
> make pkg-mypkg
```
4. "SET_BUILD.BAT" will set the building environment.
5. "make pkg-mypkg" will build all package and install to R library path.
The process message may be like this "message.windows.txt".
The complete package will be at "C:\PROGRA~1\R\RW1071\LIBRARY\MYPKG", you can zip the whole directory to
mypkg_0.1-1.zip.
- Install
- See Install page.
---