| 1 |
Writing packages for R
|
1 |
Writing packages for R
|
| 2 |
======================
|
2 |
======================
|
| 3 |
|
3 |
|
| 4 |
See the Writing R Extensions manual for a full description of how
|
4 |
See the Writing R Extensions manual for a full description of how
|
| 5 |
to write a package.
|
5 |
to write a package.
|
| 6 |
|
6 |
|
| 7 |
|
7 |
|
| 8 |
Building from a source-code library under Windows
|
8 |
Building from a source-code library under Windows
|
| 9 |
=================================================
|
9 |
=================================================
|
| 10 |
|
10 |
|
| 11 |
[If you are reading this file as part of the full R source distribution,
|
11 |
[If you are reading this file as part of the full R source distribution,
|
| 12 |
you need to build R first: see file INSTALL.]
|
12 |
you need to build R first: see file INSTALL.]
|
| 13 |
|
13 |
|
| 14 |
|
14 |
|
| 15 |
*** This file contains a lot of prescriptive comments. They are
|
15 |
*** This file contains a lot of prescriptive comments. They are
|
| 16 |
here as a result of bitter experience. Please do not report problems
|
16 |
here as a result of bitter experience. Please do not report problems
|
| 17 |
to R-help unless you have followed all the prescriptions. ***
|
17 |
to R-help unless you have followed all the prescriptions. ***
|
| 18 |
|
18 |
|
| 19 |
|
19 |
|
| 20 |
If your package has no C nor Fortran nor C++ sources, see `Simple ports'
|
20 |
If your package has no C nor Fortran nor C++ sources, see `Simple ports'
|
| 21 |
near the bottom of this file.
|
21 |
near the bottom of this file.
|
| 22 |
|
22 |
|
| 23 |
First collect the tools that you need. There is a `portal' with
|
23 |
First collect the tools that you need. There is a `portal' with
|
| 24 |
current links at http://www.stats.ox.ac.uk/pub/Rtools/.
|
24 |
current links at http://www.stats.ox.ac.uk/pub/Rtools/.
|
| 25 |
|
25 |
|
| 26 |
|
26 |
|
| 27 |
You will need suitable versions of at least make, sh, cat, cp, diff,
|
27 |
You will need suitable versions of at least make, sh, cat, cp, diff,
|
| 28 |
echo, mkdir, mv, rm, sed; we have packaged a set at
|
28 |
echo, mkdir, mv, rm, sed; we have packaged a set at
|
| 29 |
http://www.stats.ox.ac.uk/pub/Rtools/tools.zip extracted from the
|
29 |
http://www.stats.ox.ac.uk/pub/Rtools/tools.zip extracted from the
|
| 30 |
cygwin distribution (http://www.cygwin.com/mirrors.html) or (gzip)
|
30 |
cygwin distribution (http://www.cygwin.com/mirrors.html) or (gzip)
|
| 31 |
compiled from the sources.
|
31 |
compiled from the sources.
|
| 32 |
|
32 |
|
| 33 |
|
33 |
|
| 34 |
BEWARE: `Native' ports of make are _not_ suitable (including that at
|
34 |
BEWARE: `Native' ports of make are _not_ suitable (including that at
|
| 35 |
the mingw site). There were also problems with several earlier
|
35 |
the mingw site). There were also problems with several earlier
|
| 36 |
versions of the cygwin tools and dll. To avoid frustration, please
|
36 |
versions of the cygwin tools and dll. To avoid frustration, please
|
| 37 |
use our tool set, and make sure it is at the front of your path.
|
37 |
use our tool set, and make sure it is at the front of your path.
|
| 38 |
|
38 |
|
| 39 |
You need a recent version of the Mingw port of gcc from
|
39 |
You need a recent version of the Mingw port of gcc from
|
| 40 |
http://sourceforge.net/projects/mingw/. There will be a distribution
|
40 |
http://sourceforge.net/projects/mingw/. There will be a distribution
|
| 41 |
called something like MinGW-3.0.0-1.exe. Earlier versions may work,
|
41 |
called something like MinGW-3.0.0-1.exe. Earlier versions may work,
|
| 42 |
but mingw-runtime >= 2.0 and w32api >= 2.0 are essential. The release
|
42 |
but mingw-runtime >= 2.0 and w32api >= 2.0 are essential. The release
|
| 43 |
candidates of gcc-3.3.1 have also been tested.
|
43 |
candidates of gcc-3.3.1 have also been tested.
|
| 44 |
|
44 |
|
| 45 |
No earlier Mingw compiler has been tested and support for using the
|
45 |
No earlier Mingw compiler has been tested and support for using the
|
| 46 |
Cygwin compiler has been withdrawn. If you see errors about `-shared'
|
46 |
Cygwin compiler has been withdrawn. If you see errors about `-shared'
|
| 47 |
not being understood or `__imp_foo' missing, you are not using the
|
47 |
not being understood or `__imp_foo' missing, you are not using the
|
| 48 |
recommended compiler.
|
48 |
recommended compiler.
|
| 49 |
|
49 |
|
| 50 |
|
50 |
|
| 51 |
The Windows port of perl5, available via
|
51 |
The Windows port of perl5, available via
|
| 52 |
http://www.activestate.com/Products/ActivePerl/.
|
52 |
http://www.activestate.com/Products/ActivePerl/.
|
| 53 |
BEWARE: you do need the *Windows* port and not the Cygwin one.
|
53 |
BEWARE: you do need the *Windows* port and not the Cygwin one.
|
| 54 |
|
54 |
|
| 55 |
|
55 |
|
| 56 |
If you want to make compiled html (.chm) files you will need the
|
56 |
If you want to make compiled html (.chm) files you will need the
|
| 57 |
Microsoft HTML Help Workshop, currently available for download at
|
57 |
Microsoft HTML Help Workshop, currently available for download at
|
| 58 |
http://msdn.microsoft.com/library/en-us/htmlhelp/html/hwmicrosofthtmlhelpdownloads.asp
|
58 |
http://msdn.microsoft.com/library/en-us/htmlhelp/html/hwmicrosofthtmlhelpdownloads.asp
|
| 59 |
and http://www.microsoft.com/office/ork/xp/appndx/appa06.htm
|
59 |
and http://www.microsoft.com/office/ork/xp/appndx/appa06.htm
|
| 60 |
|
60 |
|
| 61 |
You may need this on the same drive as the other tools. (Although we
|
61 |
You may need this on the same drive as the other tools. (Although we
|
| 62 |
have successfully used it elsewhere, others have reported problems).
|
62 |
have successfully used it elsewhere, others have reported problems).
|
| 63 |
|
63 |
|
| 64 |
|
64 |
|
| 65 |
For large packages it is helpful to make zipped help and/or data
|
65 |
For large packages it is helpful to make zipped help and/or data
|
| 66 |
files: for that you need zip and unzip from the Info-ZIP project
|
66 |
files: for that you need zip and unzip from the Info-ZIP project
|
| 67 |
(www.info-zip.org and mirrors, and included in our tools.zip).
|
67 |
(www.info-zip.org and mirrors, and included in our tools.zip).
|
| 68 |
|
68 |
|
| 69 |
|
69 |
|
| 70 |
All of these need to be installed and in your path, and the
|
70 |
All of these need to be installed and in your path, and the
|
| 71 |
appropriate environment variables set.
|
71 |
appropriate environment variables set.
|
| 72 |
Edit MkRules to set the appropriate paths as needed.
|
72 |
Edit MkRules to set the appropriate paths as needed.
|
| 73 |
BEWARE: MkRules contains tabs and some editors (e.g. WinEdt) silently
|
73 |
BEWARE: MkRules contains tabs and some editors (e.g. WinEdt) silently
|
| 74 |
remove them.
|
74 |
remove them.
|
| 75 |
|
75 |
|
| 76 |
Do not use paths with spaces in: you can always use the short forms.
|
76 |
Do not use filepaths with spaces in: you can always use the short forms
|
| - |
|
77 |
(found by dir /x at the Windows command line).
|
| 77 |
Do not use unnecessary quotes in your PATH variable.
|
78 |
Do not use unnecessary quotes in your PATH variable.
|
| 78 |
Do not have our toolset and any other version of cygwin1.dll in your path.
|
79 |
Do not have our toolset and any other version of cygwin1.dll in your path.
|
| 79 |
|
80 |
|
| 80 |
|
81 |
|
| 81 |
BEWARE: if you have Norton Anti-Virus you may need to disable it.
|
82 |
BEWARE: if you have Norton Anti-Virus you may need to disable it.
|
| 82 |
Some versions lock up the machine when windres is run. (Norton
|
83 |
Some versions lock up the machine when windres is run. (Norton
|
| 83 |
Anti-Virus 2002 causes no problems.)
|
84 |
Anti-Virus 2002 causes no problems.)
|
| 84 |
|
85 |
|
| 85 |
BEWARE: Don't expect this to work if the path to R_HOME contains spaces.
|
86 |
BEWARE: Don't expect this to work if the path to R_HOME contains spaces.
|
| 86 |
It may work, but we don't recommend it.
|
87 |
It may work, but we don't recommend it.
|
| 87 |
|
88 |
|
| 88 |
Then
|
89 |
Then
|
| 89 |
|
90 |
|
| 90 |
cd R_HOME\src\gnuwin32
|
91 |
cd R_HOME\src\gnuwin32
|
| 91 |
make libR.a libRblas.a
|
92 |
make libR.a libRblas.a
|
| 92 |
|
93 |
|
| 93 |
which might take up to a minute. This only needs to be done once for
|
94 |
which might take up to a minute. This only needs to be done once for
|
| 94 |
each R release, and will be done automatically when needed if
|
95 |
each R release, and will be done automatically when needed if
|
| 95 |
omitted at this point.
|
96 |
omitted at this point.
|
| 96 |
|
97 |
|
| 97 |
|
98 |
|
| 98 |
At this point there are two approaches:
|
99 |
At this point there are two approaches:
|
| 99 |
|
100 |
|
| 100 |
1) Streamlined way
|
101 |
1) Streamlined way
|
| 101 |
|
102 |
|
| 102 |
Assuming that ...\rw1050\bin is in your path, use
|
103 |
Assuming that ...\rw10xx\bin is in your path, use
|
| 103 |
|
104 |
|
| 104 |
Rcmd INSTALL package
|
105 |
Rcmd INSTALL package
|
| 105 |
|
106 |
|
| 106 |
where `package' can be a directory or a .tar.gz file. See
|
107 |
where `package' can be a directory or a .tar.gz file. See
|
| 107 |
Rcmd INSTALL --help for a full list of options, which include
|
108 |
Rcmd INSTALL --help for a full list of options, which include
|
| 108 |
|
109 |
|
| 109 |
-l, --library=LIB install packages to library tree LIB
|
110 |
-l, --library=LIB install packages to library tree LIB
|
| 110 |
--docs=TYPE type(s) of documentation to build and install
|
111 |
--docs=TYPE type(s) of documentation to build and install
|
| 111 |
--use-zip-data collect data files in zip archive
|
112 |
--use-zip-data collect data files in zip archive
|
| 112 |
--use-zip-help collect help and examples into zip archives
|
113 |
--use-zip-help collect help and examples into zip archives
|
| 113 |
--use-zip combine `--use-zip-data' and `--use-zip-help'
|
114 |
--use-zip combine `--use-zip-data' and `--use-zip-help'
|
| 114 |
|
115 |
|
| 115 |
TYPE can be "none" or "normal" or "chm" (the default) or "winhlp" or "all"
|
116 |
TYPE can be "none" or "normal" or "chm" (the default) or "all"
|
| 116 |
|
117 |
|
| 117 |
|
118 |
|
| 118 |
2) Manual `full-control'
|
119 |
2) Manual `full-control'
|
| 119 |
|
120 |
|
| 120 |
For each package you want to install, unpack it to a directory, say
|
121 |
For each package you want to install, unpack it to a directory, say
|
| 121 |
mypkg, in R_HOME\src\library, and run
|
122 |
mypkg, in R_HOME\src\library, and run
|
| 122 |
|
123 |
|
| 123 |
cd R_HOME\src\gnuwin32
|
124 |
cd R_HOME\src\gnuwin32
|
| 124 |
make pkg-mypkg
|
125 |
make pkg-mypkg
|
| 125 |
|
126 |
|
| 126 |
|
127 |
|
| 127 |
Customising compilation
|
128 |
Customising compilation
|
| 128 |
=======================
|
129 |
=======================
|
| 129 |
|
130 |
|
| 130 |
The Makefiles can be customized: in particular the name of the DLL can
|
131 |
The Makefiles can be customized: in particular the name of the DLL can
|
| 131 |
be set (for example we once needed integrate-DLLNM=adapt), the compile
|
132 |
be set (for example we once needed integrate-DLLNM=adapt), the compile
|
| 132 |
flags can be set (see the examples in MakeDll) and the types of help
|
133 |
flags can be set (see the examples in MakeDll) and the types of help
|
| 133 |
(if any) to be generated can be chosen (variables HELP and WINHELP).
|
134 |
(if any) to be generated can be chosen (variables HELP and WINHELP).
|
| 134 |
The simplest way to customize the compilation steps is to set variables in
|
135 |
The simplest way to customize the compilation steps is to set variables in
|
| 135 |
a file src\Makevars.win, which will automatically be included by MakeDLL.
|
136 |
a file src\Makevars.win, which will automatically be included by MakeDLL.
|
| 136 |
For example, for RODBC src\Makevars.win could include the line
|
137 |
For example, for RODBC src\Makevars.win could include the line
|
| 137 |
|
138 |
|
| 138 |
DLLLIBS+=-lodbc32
|
139 |
DLLLIBS+=-lodbc32
|
| 139 |
|
140 |
|
| 140 |
or, equivalently,
|
141 |
or, equivalently,
|
| 141 |
|
142 |
|
| 142 |
RODBC-DLLLIBS=-lodbc32
|
143 |
RODBC-DLLLIBS=-lodbc32
|
| 143 |
|
144 |
|
| 144 |
If you have a file src\Makefile.win, that will be used as the makefile
|
145 |
If you have a file src\Makefile.win, that will be used as the makefile
|
| 145 |
for source compilation in place of our makefile MakeDll.
|
146 |
for source compilation in place of our makefile MakeDll.
|
| 146 |
|
147 |
|
| 147 |
BEWARE: files src\Makefile or src\Makevars will be used if they exist
|
148 |
BEWARE: files src\Makefile or src\Makevars will be used if they exist
|
| 148 |
and the .win equivalents do not. Such files included in package
|
149 |
and the .win equivalents do not. Such files included in package
|
| 149 |
sources are usually designed for use under Unix and are best removed.
|
150 |
sources are usually designed for use under Unix and are best removed.
|
| 150 |
|
151 |
|
| 151 |
BEWARE: references to variables in R.dll are converted to the
|
152 |
BEWARE: references to variables in R.dll are converted to the
|
| 152 |
right form by using the header files. You must include them.
|
153 |
right form by using the header files. You must include them.
|
| 153 |
|
154 |
|
| 154 |
|
155 |
|
| 155 |
Using zipped help files
|
156 |
Using zipped help files
|
| 156 |
=======================
|
157 |
=======================
|
| 157 |
|
158 |
|
| 158 |
You will need zip installed, of course. Just run
|
159 |
You will need zip installed, of course. Just run
|
| 159 |
|
160 |
|
| 160 |
make ziponly-mypkg
|
161 |
make ziponly-mypkg
|
| 161 |
|
162 |
|
| 162 |
after building mypkg. Target `ziphelp-mypkg' will make the zip files
|
163 |
after building mypkg. Target `ziphelp-mypkg' will make the zip files
|
| 163 |
but not remove the separate files: this can be used for testing.
|
164 |
but not remove the separate files: this can be used for testing.
|
| 164 |
|
165 |
|
| 165 |
This is an option to Rcmd INSTALL.
|
166 |
This is an option to Rcmd INSTALL.
|
| 166 |
|
167 |
|
| 167 |
|
168 |
|
| 168 |
Using zipped data files
|
169 |
Using zipped data files
|
| 169 |
=======================
|
170 |
=======================
|
| 170 |
|
171 |
|
| 171 |
You will need zip installed. Just run
|
172 |
You will need zip installed. Just run
|
| 172 |
|
173 |
|
| 173 |
make zipdata-mypkg
|
174 |
make zipdata-mypkg
|
| 174 |
|
175 |
|
| 175 |
after building mypkg. This is recommended if you have either many small
|
176 |
after building mypkg. This is recommended if you have either many small
|
| 176 |
data files (as in package Devore5) or a few large data files.
|
177 |
data files (as in package Devore5) or a few large data files.
|
| 177 |
|
178 |
|
| 178 |
This is an option to Rcmd INSTALL.
|
179 |
This is an option to Rcmd INSTALL.
|
| 179 |
|
180 |
|
| 180 |
|
181 |
|
| 181 |
Checking and building packages
|
182 |
Checking and building packages
|
| 182 |
==============================
|
183 |
==============================
|
| 183 |
|
184 |
|
| 184 |
The equivalent of `R CMD check mypkg' on Unix is
|
185 |
The equivalent of `R CMD check mypkg' on Unix is
|
| 185 |
|
186 |
|
| 186 |
Rcmd check mypkg
|
187 |
Rcmd check mypkg
|
| 187 |
|
188 |
|
| 188 |
Use `Rcmd check --help' for full details. There is an analogous call for
|
189 |
Use `Rcmd check --help' for full details. There is an analogous call for
|
| 189 |
build.
|
190 |
build.
|
| 190 |
|
191 |
|
| 191 |
You may need to set TMPDIR to (the absolute path to) a suitable
|
192 |
You may need to set TMPDIR to (the absolute path to) a suitable
|
| 192 |
temporary directory: the default is c:/TEMP. (Use forward slashes,
|
193 |
temporary directory: the default is c:/TEMP. (Use forward slashes,
|
| 193 |
although the code will try to convert backslashes as from 1.7.0.)
|
194 |
although the code will try to convert backslashes as from 1.7.0. Do
|
| - |
|
195 |
not have spaces in the filepath, although from 1.9.0 we attempt to
|
| - |
|
196 |
work around this.)
|
| 194 |
|
197 |
|
| 195 |
These have been used successfully under NT/2000/XP. We have seen
|
198 |
These have been used successfully under NT/2000/XP. We have seen
|
| 196 |
problems with some Perl versions on Win 95/98/ME, but believe these
|
199 |
problems with some Perl versions on Win 95/98/ME, but believe these
|
| 197 |
are now resolved. make pkgcheck-mypkg will perform the tests of the
|
200 |
are now resolved. make pkgcheck-mypkg will perform the tests of the
|
| 198 |
examples and tests directory, as far as we know on all versions of Windows.
|
201 |
examples and tests directory, as far as we know on all versions of Windows.
|
| 199 |
|
202 |
|
| 200 |
|
203 |
|
| 201 |
Building the package reference manual
|
204 |
Building the package reference manual
|
| 202 |
=====================================
|
205 |
=====================================
|
| 203 |
|
206 |
|
| 204 |
See the Writing R Extensions manual for full instructions on converting
|
207 |
See the Writing R Extensions manual for full instructions on converting
|
| 205 |
package help files to DVI or PDF format. If you have the necessary tools
|
208 |
package help files to DVI or PDF format. If you have the necessary tools
|
| 206 |
installed,
|
209 |
installed,
|
| 207 |
|
210 |
|
| 208 |
Rcmd rd2dvi.sh --pdf mypkg
|
211 |
Rcmd rd2dvi.sh --pdf mypkg
|
| 209 |
|
212 |
|
| 210 |
will use LaTeX to build a PDF version of the reference manual.
|
213 |
will use LaTeX to build a PDF version of the reference manual.
|
| 211 |
|
214 |
|
| 212 |
|
215 |
|
| 213 |
Debugging
|
216 |
Debugging
|
| 214 |
=========
|
217 |
=========
|
| 215 |
|
218 |
|
| 216 |
See the rw-FAQ.
|
219 |
See the rw-FAQ.
|
| 217 |
|
220 |
|
| 218 |
|
221 |
|
| 219 |
Using Visual C++
|
222 |
Using Visual C++
|
| 220 |
================
|
223 |
================
|
| 221 |
|
224 |
|
| 222 |
You may if you prefer use Visual C++ to make the DLLs (unless they use
|
225 |
You may if you prefer use Visual C++ to make the DLLs (unless they use
|
| 223 |
Fortran source!). First build the import library R.lib by
|
226 |
Fortran source!). First build the import library R.lib by
|
| 224 |
|
227 |
|
| 225 |
lib /def:R.exp /out:Rdll.lib
|
228 |
lib /def:R.exp /out:Rdll.lib
|
| 226 |
|
229 |
|
| 227 |
Then you can compile the objects and build the DLL by
|
230 |
Then you can compile the objects and build the DLL by
|
| 228 |
|
231 |
|
| 229 |
cl /MT /Ox /D "WIN32" /c *.c
|
232 |
cl /MT /Ox /D "WIN32" /c *.c
|
| 230 |
link /dll /def:mypkg.def /out:mypkg.dll *.obj Rdll.lib
|
233 |
link /dll /def:mypkg.def /out:mypkg.dll *.obj Rdll.lib
|
| 231 |
|
234 |
|
| 232 |
where you will need to create the .def file by hand listing the entry
|
235 |
where you will need to create the .def file by hand listing the entry
|
| 233 |
points to be exported. (If there are just a few you can use /export
|
236 |
points to be exported. (If there are just a few you can use /export
|
| 234 |
flags instead.) If the C sources use R header files you will need to
|
237 |
flags instead.) If the C sources use R header files you will need to
|
| 235 |
arrange for these to be searched, perhaps by including in the cl line
|
238 |
arrange for these to be searched, perhaps by including in the cl line
|
| 236 |
|
239 |
|
| 237 |
/I ..\..\..\include
|
240 |
/I ..\..\..\include
|
| 238 |
|
241 |
|
| 239 |
If you build a debug version of the DLL in the development
|
242 |
If you build a debug version of the DLL in the development
|
| 240 |
environment, you can debug the DLL code there just by setting the
|
243 |
environment, you can debug the DLL code there just by setting the
|
| 241 |
executable to be debugged as the full path to the R front-end.
|
244 |
executable to be debugged as the full path to the R front-end.
|
| 242 |
|
245 |
|
| 243 |
Extra care is needed when referencing variables (rather than
|
246 |
Extra care is needed when referencing variables (rather than
|
| 244 |
functions) exported from R.dll. These must be declared
|
247 |
functions) exported from R.dll. These must be declared
|
| 245 |
__declspec(dllimport) (as in R's own header files). A list of the
|
248 |
__declspec(dllimport) (as in R's own header files). A list of the
|
| 246 |
relevant variables is in the file `exported-vars'.
|
249 |
relevant variables is in the file `exported-vars'.
|
| 247 |
|
250 |
|
| 248 |
|
251 |
|
| 249 |
Using Borland C++
|
252 |
Using Borland C++
|
| 250 |
=================
|
253 |
=================
|
| 251 |
|
254 |
|
| 252 |
Borland C++5.5 is available as a free download from
|
255 |
Borland C++5.5 is available as a free download from
|
| 253 |
http://www.borland.com/bcppbuilder/freecompiler/ and as part of C++
|
256 |
http://www.borland.com/bcppbuilder/freecompiler/ and as part of C++
|
| 254 |
Builder 5. The following will make convolve.dll from convolve.c (flag
|
257 |
Builder 5. The following will make convolve.dll from convolve.c (flag
|
| 255 |
-6 optimizes for a Pentium Pro/II/III/4, and -u- removes extra underscores)
|
258 |
-6 optimizes for a Pentium Pro/II/III/4, and -u- removes extra underscores)
|
| 256 |
|
259 |
|
| 257 |
bcc32 -u- -6 -O2 -WDE convolve.c
|
260 |
bcc32 -u- -6 -O2 -WDE convolve.c
|
| 258 |
|
261 |
|
| 259 |
You can build an import library for R.dll by copying R.exp to R.def and
|
262 |
You can build an import library for R.dll by copying R.exp to R.def and
|
| 260 |
using
|
263 |
using
|
| 261 |
|
264 |
|
| 262 |
implib R.lib R.def
|
265 |
implib R.lib R.def
|
| 263 |
|
266 |
|
| 264 |
and then add R.lib to the bcc32 command line, for example (from
|
267 |
and then add R.lib to the bcc32 command line, for example (from
|
| 265 |
Venables & Ripley's `S Programming')
|
268 |
Venables & Ripley's `S Programming')
|
| 266 |
|
269 |
|
| 267 |
bcc32 -u- -6 -O2 -WDE -I\R\rw1050\src\include VCrndR.c R.lib
|
270 |
bcc32 -u- -6 -O2 -WDE -I\R\rw1050\src\include VCrndR.c R.lib
|
| 268 |
|
271 |
|
| 269 |
We believe that when referencing variables (rather than functions)
|
272 |
We believe that when referencing variables (rather than functions)
|
| 270 |
exported from R.dll these must be declared __declspec(dllimport) just
|
273 |
exported from R.dll these must be declared __declspec(dllimport) just
|
| 271 |
as for VC++.
|
274 |
as for VC++.
|
| 272 |
|
275 |
|
| 273 |
|
276 |
|
| 274 |
Using other compilers and languages
|
277 |
Using other compilers and languages
|
| 275 |
===================================
|
278 |
===================================
|
| 276 |
|
279 |
|
| 277 |
To use C++ see the section in the R for Windows FAQ. You can include
|
280 |
To use C++ see the section in the R for Windows FAQ. You can include
|
| 278 |
C++ code in packages and the supplied Makefiles will compile with g++
|
281 |
C++ code in packages and the supplied Makefiles will compile with g++
|
| 279 |
and link the DLL using g++ (and hence link against libstc++.a). Use
|
282 |
and link the DLL using g++ (and hence link against libstc++.a). Use
|
| 280 |
of C++ I/O may or may not work, and has been seen to crash R.
|
283 |
of C++ I/O may or may not work, and has been seen to crash R.
|
| 281 |
|
284 |
|
| 282 |
For other compilers you will need to arrange to produce a DLL with
|
285 |
For other compilers you will need to arrange to produce a DLL with
|
| 283 |
cdecl (also known as _cdecl or __cdecl) linkage. The mingw port (and
|
286 |
cdecl (also known as _cdecl or __cdecl) linkage. The mingw port (and
|
| 284 |
VC++) uses no `name mangling' at all, so that if for example your
|
287 |
VC++) uses no `name mangling' at all, so that if for example your
|
| 285 |
compiler adds leading or trailing underscores you will need to use the
|
288 |
compiler adds leading or trailing underscores you will need to use the
|
| 286 |
transformed symbol in the call to .C in your R code. Many compilers
|
289 |
transformed symbol in the call to .C in your R code. Many compilers
|
| 287 |
can produce cdecl DLLs by a suitable choice of flags, but if yours
|
290 |
can produce cdecl DLLs by a suitable choice of flags, but if yours
|
| 288 |
cannot you may need to write some `glue' code in C to interface to the
|
291 |
cannot you may need to write some `glue' code in C to interface to the
|
| 289 |
DLL.
|
292 |
DLL.
|
| 290 |
|
293 |
|
| 291 |
If you use .Fortran this appends an underscore and does no case
|
294 |
If you use .Fortran this appends an underscore and does no case
|
| 292 |
conversion at all to the symbol name. It is normally best to use
|
295 |
conversion at all to the symbol name. It is normally best to use
|
| 293 |
.C with compilers other than g77 and map the name manually if necessary.
|
296 |
.C with compilers other than g77 and map the name manually if necessary.
|
| 294 |
|
297 |
|
| 295 |
Care is needed in passing character strings to and from a DLL by .C:
|
298 |
Care is needed in passing character strings to and from a DLL by .C:
|
| 296 |
they must be equivalent to the C type char** and null-terminated. Not
|
299 |
they must be equivalent to the C type char** and null-terminated. Not
|
| 297 |
even the mingw g77 Fortran uses null-terminated strings.
|
300 |
even the mingw g77 Fortran uses null-terminated strings.
|
| 298 |
|
301 |
|
| 299 |
WARNING: DLLs made with some compilers reset the FPU in their startup
|
302 |
WARNING: DLLs made with some compilers reset the FPU in their startup
|
| 300 |
code (Delphi has been one), and this will cause operations such as
|
303 |
code (Delphi has been one), and this will cause operations such as
|
| 301 |
0./0. to crash R. You can re-set the FPU to the correct values by a
|
304 |
0./0. to crash R. You can re-set the FPU to the correct values by a
|
| 302 |
call to the C entry point Rwin_fpset().
|
305 |
call to the C entry point Rwin_fpset().
|
| 303 |
|
306 |
|
| 304 |
|
307 |
|
| 305 |
Simple Ports
|
308 |
Simple Ports
|
| 306 |
============
|
309 |
============
|
| 307 |
|
310 |
|
| 308 |
If your package has no C nor Fortran nor C++ sources, several steps
|
311 |
If your package has no C nor Fortran nor C++ sources, several steps
|
| 309 |
can be omitted.
|
312 |
can be omitted.
|
| 310 |
|
313 |
|
| 311 |
You will need
|
314 |
You will need
|
| 312 |
|
315 |
|
| 313 |
suitable versions of Unix tools including make, sh, rm, sed, awk,
|
316 |
suitable versions of Unix tools including make, sh, rm, sed, awk,
|
| 314 |
mkdir, echo, cp and cat; we have packaged a set at
|
317 |
mkdir, echo, cp and cat; we have packaged a set at
|
| 315 |
http://www.stats.ox.ac.uk/pub/Rtools/tools.zip.
|
318 |
http://www.stats.ox.ac.uk/pub/Rtools/tools.zip.
|
| 316 |
|
319 |
|
| 317 |
perl5, available via http://www.activestate.com/Products/ActivePerl/
|
320 |
perl5, available via http://www.activestate.com/Products/ActivePerl/
|
| 318 |
|
321 |
|
| 319 |
All of these need to be installed and in your path, and the
|
322 |
All of these need to be installed and in your path, and the
|
| 320 |
appropriate environment variables set.
|
323 |
appropriate environment variables set.
|
| 321 |
|
324 |
|
| 322 |
For each package you want to install, unpack it to a directory, say
|
325 |
For each package you want to install, unpack it to a directory, say
|
| 323 |
mypkg, in RHOME\src\library, and run
|
326 |
mypkg, in RHOME\src\library, and run
|
| 324 |
|
327 |
|
| 325 |
cd RHOME\src\gnuwin32
|
328 |
cd RHOME\src\gnuwin32
|
| 326 |
make pkg-mypkg
|
329 |
make pkg-mypkg
|
| 327 |
|
330 |
|
| 328 |
|
331 |
|
| 329 |
Non-standard locations
|
332 |
Non-standard locations
|
| 330 |
======================
|
333 |
======================
|
| 331 |
|
334 |
|
| 332 |
You can specify the location of the package source by PKGDIR and the
|
335 |
You can specify the location of the package source by PKGDIR and the
|
| 333 |
library in which to install the package by RLIB, as in
|
336 |
library in which to install the package by RLIB, as in
|
| 334 |
|
337 |
|
| 335 |
make PKGDIR=/mysources RLIB=/R/library pkg-mypkg
|
338 |
make PKGDIR=/mysources RLIB=/R/library pkg-mypkg
|
| 336 |
|
339 |
|
| 337 |
which installs the package in \mysources\mypkg as \R\library\mypkg.
|
340 |
which installs the package in \mysources\mypkg as \R\library\mypkg.
|
| 338 |
|
341 |
|
| 339 |
It may well be simpler to use
|
342 |
It may well be simpler to use
|
| 340 |
|
343 |
|
| 341 |
Rcmd INSTALL -l /R/library /mysources/mypkg
|
344 |
Rcmd INSTALL -l /R/library /mysources/mypkg
|
| 342 |
|
345 |
|
| - |
|
346 |
Once again, if the paths contain spaces use the short forms, although
|
| - |
|
347 |
Rcmd INSTALL will attempt to convert the paths if needed (but they
|
| - |
|
348 |
will need to be quoted on the command line).
|
| - |
|
349 |
|
| 343 |
|
350 |
|
| 344 |
Cross-building packages on Linux
|
351 |
Cross-building packages on Linux
|
| 345 |
================================
|
352 |
================================
|
| 346 |
|
353 |
|
| 347 |
It is straightforward to build a package on a ix86-linux system,
|
354 |
It is straightforward to build a package on a ix86-linux system,
|
| 348 |
although it is not possible (and we have tried, including using WINE)
|
355 |
although it is not possible (and we have tried, including using WINE)
|
| 349 |
to cross-build .chm files. You will need an installation of R for
|
356 |
to cross-build .chm files. You will need an installation of R for
|
| 350 |
Windows, either copied from a Windows system or cross-compiled.
|
357 |
Windows, either copied from a Windows system or cross-compiled.
|
| 351 |
|
358 |
|
| 352 |
First you need to set up the cross-compilers and tools (see file
|
359 |
First you need to set up the cross-compilers and tools (see file
|
| 353 |
src/gnuwin32/INSTALL in the full source distribution) and have them
|
360 |
src/gnuwin32/INSTALL in the full source distribution) and have them
|
| 354 |
in your path. We will assume that your Linux installation has Perl5,
|
361 |
in your path. We will assume that your Linux installation has Perl5,
|
| 355 |
unzip and zip.
|
362 |
unzip and zip.
|
| 356 |
|
363 |
|
| 357 |
Edit MkRules to set BUILD=CROSS and the appropriate paths (including
|
364 |
Edit MkRules to set BUILD=CROSS and the appropriate paths (including
|
| 358 |
HEADER) as needed.
|
365 |
HEADER) as needed.
|
| 359 |
|
366 |
|
| 360 |
Then packages can be made as natively, for example by
|
367 |
Then packages can be made as natively, for example by
|
| 361 |
|
368 |
|
| 362 |
cd .../src/gnuwin32
|
369 |
cd .../src/gnuwin32
|
| 363 |
make PKGDIR=/mysources RLIB=/R/win/library pkg-mypkg
|
370 |
make PKGDIR=/mysources RLIB=/R/win/library pkg-mypkg
|
| 364 |
make PKGDIR=/mysources RLIB=/R/win/library pkgcheck-mypkg
|
371 |
make PKGDIR=/mysources RLIB=/R/win/library pkgcheck-mypkg
|
| 365 |
cd /R/win/library
|
372 |
cd /R/win/library
|
| 366 |
zip -r9X /dest/mypkg.zip mypkg
|
373 |
zip -r9X /dest/mypkg.zip mypkg
|
| 367 |
|
374 |
|
| 368 |
(Rcmd is a Windows executable, so cannot be used.)
|
375 |
(Rcmd is a Windows executable, so cannot be used.)
|
| 369 |
|
376 |
|
| 370 |
|
377 |
|
| 371 |
Feedback
|
378 |
Feedback
|
| 372 |
========
|
379 |
========
|
| 373 |
|
380 |
|
| 374 |
Please send comments and bug reports to
|
381 |
Please send comments and bug reports to
|
| 375 |
|
382 |
|
| 376 |
R-windows@r-project.org
|
383 |
R-windows@r-project.org
|
| 377 |
|
384 |
|