[Rd] Rf_PrintValue problem with methods::show
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sun Apr 8 09:14:00 CEST 2007
Look at the definition of PrintValue:
void PrintValue(SEXP s)
{
PrintValueEnv(s, R_BaseEnv);
}
That's not going to find show from R_BaseEnv. We need to get it from the
methods namespace.
On Sat, 7 Apr 2007, Deepayan Sarkar wrote:
> Hi,
>
> 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)
> $ export LD_LIBRARY_PATH=`${RPROG} RHOME`/lib
> $ 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
> Rf_PrintValue:\n");
> Rf_PrintValue(val);
> UNPROTECT(1);
> }
>
> Rf_endEmbeddedR(0);
> 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)
> standardGeneric("cbind2")
> <environment: 0x8b34ef8>
> Methods may be defined for arguments: x, y
>
> ** I **: Evaluation succeeded, now printing using Rf_PrintValue:
> NULL
> ** I **: Executing command: cbind2
> ** I **: Evaluation succeeded, now printing using Rf_PrintValue:
> Error: could not find function "show"
> Error: unprotect(): only 0 protected items
> $
>
> -Deepayan
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel
mailing list