Re: [Rd] Rf_PrintValue problem with methods::show

2007-04-08 Thread Byron Ellis
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 
> >> #include 
> >> #include 
> >>
> >> 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")
> >> 
> >> 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


Re: [Rd] R CMD install on R 2.5.0 alpha

2007-04-08 Thread Henrik Bengtsson
On 4/7/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote:
> The file is src/gnuwin32/fixed/bin/INSTALL.
>
> You do not want --vanilla: the point is to run R under normal conditions
> to pick up the value it uses.   There is a workaround on the Unix side, nd
> I will add a similar one to the Windows code.

Ah, you're right, that was the purpose of adding it the first place.

>
> There will be the usual delays in this getting into an alpha Windows
> binary, so please try
>
> https://svn.r-project.org/R/trunk/src/gnuwin32/fixed/bin/INSTALL
>
> (save it and drop it into the R_HOME/bin directory).

Done. Tested. Works. Thanks!

/Henrik

>
> On Sat, 7 Apr 2007, Henrik Bengtsson wrote:
>
> > I located the problem to INSTALL.  If no the library path is not
> > passed explicitly, that is no -l option is use, the following code in
> > called:
> >
> > 132:my @out = R_runR("cat(.libPaths()[1])", "--slave");
> > 133:$library = @out[0];
> > 134:$library = Win32::GetShortPathName($library) if $library =~ / /;
> > 135:print "installing to '$library'\n";
> >
> > In my .Rprofile I write a message "$HOME2/.Rprofile ...done" to
> > stdout.  This is what is picked up in @out[0] above, and then I guess
> > the code on line 134 turns this into an empty string (somehow).  By
> > adding option --vanilla to the R call, this problem goes away.
> >
> > Here is a patch to $R_HOME/bin/INSTALL.
> >
> > C:\Program Files\R\R-2.5.0alpha\bin>diff INSTALL INSTALL.new
> > 132c132
> > < my @out = R_runR("cat(.libPaths()[1])", "--slave");
> > ---
> >> my @out = R_runR("cat(.libPaths()[1])", "--vanilla --slave");
> >
> >
> > I'm not sure if that INSTALL is in the source.  The only thing I can
> > find in the SVN is INSTALL.in
> > (https://svn.r-project.org/R/trunk/src/scripts/INSTALL.in), but that
> > contains no such line of code?!?
> >
> > /Henrik
> >
> >
> > On 4/7/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote:
> >> On Sat, 7 Apr 2007, Henrik Bengtsson wrote:
> >>
> >> > Hi.
> >> >
> >> > On 4/7/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote:
> >> >> Nothing has changed here for three months, AFAICS.  However, I noticed
> >> you
> >> >> have installed R into a directory with a space in the path, despite the
> >> >> advice not to.  OTOH, I have just tested installing where you did, and
> >> >> was able to install R.oo:
> >> >>
> >> >> [c:/Program Files/R/R-2.5.0alpha/bin]% ./Rcmd INSTALL
> >> >> d:/R/packages/contrib/R.oo_1.2.3.tar.gz
> >> >> installing to 'c:/PROGRA~1/R/R-25~1.0AL/library'
> >> >> ...
> >> >
> >> > Thank you for this confirmation.  It is odd though, because so have
> >> > also I done successfully for years.
> >> >
> >> >>
> >> >> On Windows, INSTALL is a Perl script.  Please debug it to see what is
> >> >> going wrong on your setup (it is working for many others).
> >> >
> >> > I will debug INSTALL to see what might go wrong.  I'll see if I can
> >> > locate an earlier version of R 2.5.0 alpha to see if the error really
> >> > is there or not.
> >> >
> >> >>
> >> >> You can of course specify -l to workaround this.
> >> >>
> >> >> On Sat, 7 Apr 2007, Henrik Bengtsson wrote:
> >> >>
> >> >> > Hi,
> >> >> >
> >> >> > I've just downloaded the latest R v2.5.0 alpha (2007-04-04 r41043) for
> >> >>
> >> >> That is not the latest binary build I am offered, let alone the latest
> >> >> sources.
> >> >
> >> > Got it from the UC Davis CRAN mirror about an one hour before my message.
> >>
> >> There is not much point in getting alpha/betas from mirrors: they can
> >> introduce another 24-hour delay.
> >>
> >> >
> >> > Thanks
> >> >
> >> > Henrik
> >> >
> >> >>
> >> >> > WinXP.  When I try to
> >> >> > install a package R tries to install it to a no-name (empty name)
> >> >> > directory (causing error downstream):
> >> >> >
> >> >> > RCMD INSTALL R.oo
> >> >> > installing to ''
> >> >> >
> >> >> > FYI: Package install perfectly on R v2.4.1 patched, and did so also on
> >> >> > earlier R v2.5.0 devel/alpha(?) versions.
> >> >> >
> >> >> > Current directory is:
> >> >> > C:\tmp
> >> >> >
> >> >> > with subdirectory R.oo/ containing inst/ man/ R/ DESCRIPTION as usual.
> >> >> >
> >> >> > I noticed the following in CHANGES and NEWS related to R CMD INSTALL:
> >> >> >
> >> >> > o R CMD INSTALL now installs by default into the first library on
> >> >> >   the library path if R was run in the current environment.
> >> >> >   Similarly, R CMD REMOVE by default removes from that library.
> >> >> >   R CMD INSTALL does a better job of removing its temporary
> >> >> >   directory.
> >> >> >
> >> >> > o R CMD INSTALL and R CMD REMOVE now use as the default library
> >> >> >   (if -l is not specified) the first library that would be used
> >> >> >   if R were run in the current environment (and they run R to
> >> >> >   find it).
> >> >> >
> >> >> >o  R CMD INSTALL now prepends the installation directory (if
> >> >> >   specified) to the library search path.
> >> >> >
> >> >> > But m

Re: [Rd] Rf_PrintValue problem with methods::show

2007-04-08 Thread Prof Brian Ripley
Simon,

There are a couple of subtle issues here.  As I wrote, PrintValue 
evaluates in the base environment, so sees only base functions.  It is not 
clear to me that is the right place (why the base environment and not the 
base namespace, for example), and one might consider evaluating in 
R_GlobalEnv.

However, as I understand it, one can load the methods namespace and turn 
S4 dispatch on without attaching the package.  So it seems entirely 
possible (but unusual) to have a package import 'methods' and then create 
S4 objects, and expect autoprinting to work.  That's why PrintValueEnv has 
to get show() from the methods namespace (at least as a last resort).

Now, there is an issue as to what autoprinting should do if a user defines 
his own version of print or show higher up the search path.  At present I 
believe the users's version is used for autoprinting, so we might want to 
preserve those semantics.  There are also issues with the visibility of S3 
print methods, and possible discrepancies in the choice between methods on 
the search path and registered ones.

I need to think through what the best fix is (suggestions welcome), and 
get this into 2.5.0 as a bug fix (I won't have time until Tuesday at the 
earliest).

Brian

On Sun, 8 Apr 2007, 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 
>> #include 
>> #include 
>>
>> 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")
>> 
>> 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
>

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
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, UKFax:  +44 1865 272595

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Windows binary packages under R-2.5.0 alpha

2007-04-08 Thread Uwe Ligges
Dear package maintainers,

currently, 39 CRAN packages (not counting those on my 
exclude-from-Windows lists) are not passing the checks under Windows for 
R-2.5.0 alpha.
Additional 157 (!!!) packages are only passing with one or more WARNINGS.

Maintainers of failing packages will receive an automatical generated 
message today. In case your package does not pass the checks: Please 
remember that R-2.5.0 will be released in roughly two weeks and we are 
closely approaching beta status ...

I'd like to ask all package maintainers to look into the check summaries 
at http://cran.r-project.org/src/contrib/checkSummary.html

Thank you  -- and keep the updates rolling in,
Uwe Ligges

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Rf_PrintValue problem with methods::show

2007-04-08 Thread Simon Urbanek
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 
>> #include 
>> #include 
>>
>> 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")
>> 
>> 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


Re: [Rd] Rf_PrintValue problem with methods::show

2007-04-08 Thread Simon Urbanek
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 
> #include 
> #include 
>
> 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")
> 
> 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


Re: [Rd] buglet in terms calculations

2007-04-08 Thread Peter Dalgaard
Robert Gentleman wrote:
> Hi,
>Vince and I have noticed a problem with non-syntactic names in data 
> frames and some modeling code (but not all modeling code).
>
>The following, while almost surely as documented could be a bit more 
> helpful:
>
>   m = matrix(rnorm(100), nc=10)
>   colnames(m) = paste(1:10, letters[1:10], sep="_")
>
>   d = data.frame(m, check.names=FALSE)
>
>   f = formula(`1_a` ~ ., data=d)
>
>   tm = terms(f, data=d)
>
>   ##failure here, as somehow back-ticks have become part of the name
>   ##not a quoting mechanism
>   d[attr(tm, "term.labels")]
>
>The variable attribute, in the terms object, keeps them as quotes, so 
> modeling code that uses that attribute seems fine, but code that uses 
> the term.labels fails. In particular, it seems (of those tested) that 
> glm, lda, randomForest seem to work fine, while nnet, rpart can't
> handle nonsyntactic names in formulae as such
>
>In particlar, rpart contains this code:
>
>   lapply(m[attr(Terms, "term.labels")], tfun)
>
>which fails for the reasons given.
>
>
>   One way to get around this, might be to modify the do_termsform code,
> right now we have:
> PROTECT(varnames = allocVector(STRSXP, nvar));
>  for (v = CDR(varlist), i = 0; v != R_NilValue; v = CDR(v))
>  SET_STRING_ELT(varnames, i++, STRING_ELT(deparse1line(CAR(v), 
>  0), 0));
>
>   and then for term.labels, we copy over the varnames (with :, as 
> needed) and perhaps we need to save the unquoted names somewhere?
>
>   Or is there some other approach that will get us there? Certainly 
> cleaning up the names via
>cleanTick = function(x) gsub("`", "", x)
>
>   works, but it seems a bit ugly, and it might be better if the modeling 
> code was modified.
>
>   
Hmm, .Internal(deparse()) has a backtick option (for related 
reasons, IIRC). Could this be  used instead of  deparse1line?

(There's an inbuilt contradiction in having special terms like 
"(Intercept)" and at the same time allowing arbitrary non-syntactical 
names, but I suppose that  people who actually name their variables 
`(Intercept)` deserve whatever they get.)

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] boundary case anomaly

2007-04-08 Thread Robert Gentleman
Hi,
  Any reason these should be different?

  x=matrix(0, nr=0, nc=3)
  colnames(x) = letters[1:3]
  data.frame(x)
#[1] a b c
#<0 rows> (or 0-length row.names)
  y=vector("list", length=3)
  names(y) = letters[1:3]
  data.frame(y)
#NULL data frame with 0 rows


both should have names (the second one does not) and why print something 
different for y?

  The two of the last three examples refer to a "NULL data frame", eg
   (d00 <- d0[FALSE,])  # NULL data frame with 0 rows

  but there is no description of what a NULL data frame should be (zero 
rows or zero columns, or either or both - and why a special name?)


  best wishes
Robert


-- 
Robert Gentleman, PhD
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
PO Box 19024
Seattle, Washington 98109-1024
206-667-7700
[EMAIL PROTECTED]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] buglet in terms calculations

2007-04-08 Thread Robert Gentleman
Hi,
   Vince and I have noticed a problem with non-syntactic names in data 
frames and some modeling code (but not all modeling code).

   The following, while almost surely as documented could be a bit more 
helpful:

  m = matrix(rnorm(100), nc=10)
  colnames(m) = paste(1:10, letters[1:10], sep="_")

  d = data.frame(m, check.names=FALSE)

  f = formula(`1_a` ~ ., data=d)

  tm = terms(f, data=d)

  ##failure here, as somehow back-ticks have become part of the name
  ##not a quoting mechanism
  d[attr(tm, "term.labels")]

   The variable attribute, in the terms object, keeps them as quotes, so 
modeling code that uses that attribute seems fine, but code that uses 
the term.labels fails. In particular, it seems (of those tested) that 
glm, lda, randomForest seem to work fine, while nnet, rpart can't
handle nonsyntactic names in formulae as such

   In particlar, rpart contains this code:

  lapply(m[attr(Terms, "term.labels")], tfun)

   which fails for the reasons given.


  One way to get around this, might be to modify the do_termsform code,
right now we have:
PROTECT(varnames = allocVector(STRSXP, nvar));
 for (v = CDR(varlist), i = 0; v != R_NilValue; v = CDR(v))
 SET_STRING_ELT(varnames, i++, STRING_ELT(deparse1line(CAR(v), 
 0), 0));

  and then for term.labels, we copy over the varnames (with :, as 
needed) and perhaps we need to save the unquoted names somewhere?

  Or is there some other approach that will get us there? Certainly 
cleaning up the names via
   cleanTick = function(x) gsub("`", "", x)

  works, but it seems a bit ugly, and it might be better if the modeling 
code was modified.

   best wishes



-- 

Robert Gentleman, PhD
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
PO Box 19024
Seattle, Washington 98109-1024
206-667-7700
[EMAIL PROTECTED]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Rf_PrintValue problem with methods::show

2007-04-08 Thread Prof Brian Ripley
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 
> #include 
> #include 
>
> 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")
> 
> 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
>

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
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, UKFax:  +44 1865 272595

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel