Commit graph

7 commits

Author SHA1 Message Date
Richard Beare
1a6d952094 runtime test for tricky enumerations and support for out of source testing via args option to R 2015-08-12 18:33:53 +01:00
Joseph C Wang
834a93f449 Revert "Merge pull request #494 from richardbeare/enumR2015B"
This reverts commit cb8973f313, reversing
changes made to ac3284f78c.
2015-08-11 09:57:57 +08:00
Richard Beare
da1c6c60d3 This is a modification to support use of tricky enumerations in R. It
includes the addition of a _runme for an existing test - preproc_constants
that was previously not run. That tests includes a preprocessor based
setting of an enumeration which is ignored by the existing r enumeration
infrastructure. The new version correctly reports the enumeration value
as 4 - previous versions set it to 0. Traditional enumerations are unchanged.

The approach used to deal with these enumerations is similar to that of
other languages, and requires a call to a C function at runtime to return
the enumeration value. The previous approach figured out the values statically
and this is still used where possible. The need for a runtime call leads to
changes in when swig code is used in packages - see below.

One test that previously passed now fails - namely the R sourcing of
preproc_constants.R, as the enumeration code requires the shared library,
which isn't loaded by that script.

There is also a modification to the way the R _runme.R files are used.
The call to R CMD BATCH now includes a --args option that indicates
the source folder for the unittest.R file, and the first couple
of lines of the _runme.R files deal with correctly locating this.
Out of source tests now run correctly.

This work was motivated by problems generating the SimpleITK binding,
specifically with some of the more complex enumerations.

This approach does have some issues wrt to code in packages, but I can't
see an alternative. The problem with packages is that the R code setting
up the enumeration structures requires the shared library so that the C
functions returning enumeration values can be called. The enumeration
setup code thus needs to be moved to the package initialisation section.
For SimpleITK I do this using an R script, which I think is an acceptable
solution. The core part of the process is the following function. I dump
all the enumeration stuff into a .onload function. This is only necessary
if some of the enumerations are tricky.

splitSwigFile <- function(filename, onloadfile, mainfile)
{
p1 <- parse(file=filename)

getdefineEnum <- function(X)
{
return (is.call(X) & (X[[1]]=="defineEnumeration"))
}

dd <- sapply(p1, getdefineEnum)

enums <- p1[dd]
enums <- unlist(lapply(enums, deparse))

enums <- c(".onLoad <- function(libname, pkgname) {", enums, "}")

everythingelse <- p1[!dd]
everythingelse <- unlist(lapply(everythingelse, deparse))
writeLines(everythingelse, mainfile)
writeLines(enums, onloadfile)

}
2015-08-10 09:37:04 +10:00
William S Fulton
083efd15ca Rename dll/shared object name to be the same as the module name for R - _wrap is no longer postfixed to the name
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10130 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2007-11-14 22:34:10 +00:00
Joseph Wang
cd9c301b48 Remove _wrap from .R files
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10105 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2007-11-11 03:08:10 +00:00
William S Fulton
6e9058cbeb Make examples cross platform
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10091 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2007-11-08 21:40:24 +00:00
Joseph Wang
0218fdeb27 add missing files from initial check in
change camel case to match SWIG conventions


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9182 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2006-06-30 05:48:54 +00:00
Renamed from Examples/test-suite/r/simpleArray_runme.R (Browse further)