[Rd] Rf_PrintValue problem with methods::show

Deepayan Sarkar deepayan.sarkar at gmail.com
Sun Apr 8 01:33:49 CEST 2007


I think this is a bug (even though I can't find documentation
explicitly saying that it should work). Basically, Rf_PrintValue(obj)
fails when 'obj' is an S4 object that should be printed using show()
rather than print(). From the error message I'm guessing that the need
to use show is detected correctly but then show is not found.

"cbind2" in the code below is just a representative object, the same
holds for the few other S4 objects I have tried.

The following uses r-devel on i686-pc-linux-gnu, but the results are
same with R 2.4.1 (with suitable changes to the R_ParseVector call).
On powerpc Linux I get a segfault.

$ RPROG=R-devel
$ ${RPROG} --version | head -1
R version 2.6.0 Under development (unstable) (2007-04-06 r41080)
$ cat parseEvalS4.c

#include <Rinternals.h>
#include <Rembedded.h>
#include <R_ext/Parse.h>

int main(int argc, char *argv[])
    SEXP e, val;
    int i, errorOccurred;
    ParseStatus status;
    char *cmds[] = { "show(5)", "show(cbind2)", "cbind2" };

    argv[0] = "R";
    Rf_initEmbeddedR(argc, argv);

    for (i = 0; i < 3; i++) {
        printf("** I **: Executing command: %s\n", cmds[i]);
        PROTECT(e = R_ParseVector(mkString(cmds[i]), -1, &status, R_NilValue));
        val = eval(VECTOR_ELT(e, 0), R_GlobalEnv);
        printf("** I **: Evaluation succeeded, now printing using

    return 0;

$ gcc -o parseEvalS4 \
>        `${RPROG} CMD config --cppflags` \
>        `${RPROG} CMD config --ldflags` parseEvalS4.c
$ ${RPROG} CMD ./parseEvalS4 --vanilla --silent
** I **: Executing command: show(5)
[1] 5
** I **: Evaluation succeeded, now printing using Rf_PrintValue:
[1] 5
** I **: Executing command: show(cbind2)
standardGeneric for "cbind2" defined from package "methods"

function (x, y)
<environment: 0x8b34ef8>
Methods may be defined for arguments: x, y

** I **: Evaluation succeeded, now printing using Rf_PrintValue:
** I **: Executing command: cbind2
** I **: Evaluation succeeded, now printing using Rf_PrintValue:
Error: could not find function "show"
Error: unprotect(): only 0 protected items


More information about the R-devel mailing list