Indeed, you run into the same problem when trying to use PrintValue in a package (say, for debugging purposes). I just have an implementation that uses GlobalEnv instead of BaseEnv though I'm not sure that it's necessarily the correct choice (though it has yet to do something I don't want).
On 4/8/07, Simon Urbanek <[EMAIL PROTECTED]> wrote: > Deepayan, > > don't mind my last mail - one shouldn't write e-mails before the > first cup of coffee in the morning ;).. "methods" used to be excluded > from the embedded startup (AFAIR), but that's no longer the case, so > it must be something else. Sorry for the noise (I'm off to get the > coffee :P). > > Cheers, > Simon > > On Apr 8, 2007, at 8:31 AM, Simon Urbanek wrote: > > > Deepayan, > > > > you fail to load the methods package, so you cannot use S4. Eval > > "library(methods)" first then everything is fine. > > > > Cheers, > > Simon > > > > On Apr 7, 2007, at 7:33 PM, 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@r-project.org mailing list > >> https://stat.ethz.ch/mailman/listinfo/r-devel > >> > >> > > > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > -- Byron Ellis ([EMAIL PROTECTED]) "Oook" -- The Librarian ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel