Paul Roebuck wrote:

I have the following contrived code in package format.
On Solaris and Mac OS X, code runs just fine. On Windows,
it crashes the R environment with the "Send Bug Report"
dialog. I tried R 1.8.1 (Win2K) and R 1.9 (WinXP) binaries
with the same result. PCs otherwise appear properly
configured for creating R packages. Anything blatantly
wrong? Suggestions?


Works for me (R-1.9.1, WinNT4.0), even with gctorture(TRUE).
Did you use the recommended compiler and tools?

Uwe Ligges


TIA



Relevant files from package (getdim):


R/getdim.R ---------- getdim <- function(x) .Call("getdim", as.matrix(x), PACKAGE="getdim");


R/zzz.R ------- .First.lib <- function(libname, pkgname) { if (version$major == 1 && version$minor < 8.1) { stop("Requires R 1.8.1 or later") } library.dynam("getdim", pkgname, libname) }


src/getdim.c ------------ #include <R.h> #include <Rdefines.h> #include <R_ext/PrtUtil.h>

int GetMatrixDimen(SEXP vntX, int *nrow, int *ncol)
{
    SEXP vntXdim;
    int nX;

#ifdef DEBUG_GETDIM
    REprintf("In GetMatrixDimen()...\n");
#endif

/**** Code crashes here on Windoze ******/
    PROTECT(vntXdim = GET_DIM(vntX));
#ifdef DEBUG_GETDIM
    REprintf("\tgot dimension object\n");
#endif

    nX = GET_LENGTH(vntXdim);
#ifdef DEBUG_GETDIM
    REprintf("\tgot length from dimension object\n");
#endif

    if (nX == 2)
    {
        int *piXdim = INTEGER_POINTER(vntXdim);

        *nrow = piXdim[0];
        *ncol = piXdim[1];
    }
    else
    {
        *nrow = -1;
        *ncol = -1;
    }
    UNPROTECT(1);

    return nX;
}


SEXP getdim(SEXP vntX) { SEXP vntOut; int m, n;

#ifdef DEBUG_GETDIM
    REprintf("In getdim(x)...\n");
#endif

    if (GetMatrixDimen(vntX, &m, &n) != 2)
    {
        error("'x' is not a two dimensional matrix");
        /*NOTREACHED*/
    }

#ifdef DEBUG_GETDIM
    REprintf("\tm = %d\n", m);
    REprintf("\tn = %d\n", n);
#endif

    PROTECT(vntOut = NEW_INTEGER(2));
    INTEGER(vntOut)[0] = m;
    INTEGER(vntOut)[1] = n;
    UNPROTECT(1);

    return vntOut;
}


tests/getdim.R -------------- library(getdim)

test.getdim <- function(input, expected) {
    result <- getdim(input);
    identical(all.equal(result, expected), TRUE);
}

mat <- matrix(1:6, 3, 2)
mat.expected <- c(3, 2)
test.getdim(mat, mat.expected)

vec <- 1:6
vec.expected <- c(6, 1)
test.getdim(vec, vec.expected)

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to