Re: [Rd] %s in filename when opening device causes crash (PR#10571)

2008-01-15 Thread Richard . Cotton
> > Using %s in a filename when opening a device causes R to crash, e.g.,
> >
> > pdf("foo%s.pdf")
> > win.metafile("foo%s.wmf")
> > postscript("foo%s.ps")
> 
> Do you have a workaround for this?  Since that is done at C level, we 
> can't easily trap this (especially on Windows), and the list of possible 

> errors that might cause a crash is rather long.
> 
> It has been considered as a vulnerability, but there seems no simple 
> solution.

The simplest workaround is probably to check that '%s' isn't included in 
the character string for the file argument to each of the R wrapper 
functions, something like

if(length(grep("%s", file))) stop("using '%s' in a filename is invalid")

This of course means that we couldn't use '%s' in a file string (is this a 
great loss?), and that users could still cause a crash by calling the 
.External code directly.

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION:

This message contains privileged and confidential inform...{{dropped:21}}

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


[Rd] bug in mmlcr ? (PR#10576)

2008-01-15 Thread cgenolin
Hi the list.

Is there a bug in mmlcr package ?
The following code does not compile:

mmlcrTest <- function(dataW){
  dataL <-
reshape(dataW,idvar="id",timevar="T",varying=list("T0","T1","T2"),direction="long",v.names="score")

  resultR <- mmlcr(outer= ~ 1 | id,
   components = list(list(formula = score~1+T,class=
"normlong")), n.groups=3,
   data=dataL,
   max.iter=500
   )
  plot(resultR)
}
mmlcrTest(dataW)

The error is (translate from french):
"Error in inherits(x, "data.frame") : objet "dataL" not find"

It seems that mmlcr does not look for the data at the right place since
it did find dataL if we set it a a global variable but it does not find
it if we define it in a function.

Christophe


Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre

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


Re: [Rd] bug in mmlcr ? (PR#10576)

2008-01-15 Thread Ken Beath
On 15/01/2008, at 7:40 PM, [EMAIL PROTECTED] wrote:

> Hi the list.
>
> Is there a bug in mmlcr package ?
> The following code does not compile:
>
> mmlcrTest <- function(dataW){
>  dataL <-
> reshape
> (dataW
> ,idvar
> =
> "id
> ",timevar
> ="T",varying=list("T0","T1","T2"),direction="long",v.names="score")
>
>  resultR <- mmlcr(outer= ~ 1 | id,
>   components = list(list(formula = score~1+T,class=
> "normlong")), n.groups=3,
>   data=dataL,
>   max.iter=500
>   )
>  plot(resultR)
> }
> mmlcrTest(dataW)
>
> The error is (translate from french):
> "Error in inherits(x, "data.frame") : objet "dataL" not find"
>
> It seems that mmlcr does not look for the data at the right place  
> since
> it did find dataL if we set it a a global variable but it does not  
> find
> it if we define it in a function.
>

This should be directed to the package maintainer Steve Buyske, who I  
have included in the reply.

Ken

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


[Rd] Pb with defineVar() example in the "Writing R Extensions" manual

2008-01-15 Thread Herve Pages
Hi,

I'm wondering if this code from the "Writing R Extensions" manual
is really safe:

 SEXP mkans(double x)
 {
 SEXP ans;
 PROTECT(ans = allocVector(REALSXP, 1));
 REAL(ans)[0] = x;
 UNPROTECT(1);
 return ans;
 }

 double feval(double x, SEXP f, SEXP rho)
 {
 defineVar(install("x"), mkans(x), rho);
 return(REAL(eval(f, rho))[0]);
 }

In C, the order in which function arguments are evaluated before the
function itself is called is undefined. Hence there is no guarantee
that install("x") will be evaluated before mkans(x). What happens if
mkans(x) is evaluated first? Then install("x") will be called and
eventually trigger garbage collection while the SEXP returned by
mkans(x) is still unprotected.

I'm asking because I'm getting all sorts of problems with

  defineVar(install(somekey), mkans(x), rho);

In my code this line is inside a big loop (hundred of thousands of
iterations) so I end up with a lot of symbols in the rho environment.

The problems I've seen are hard to reproduce: sometimes it's a segfault,
sometimes a "cons memory exhausted" error, or sometimes everything looks
fine except that, later, when I retrieve values from the rho environment
with findVar(), some of them are altered!

But if I replace the above line by:

  PROTECT(ans = mkans(x));
  defineVar(install(somekey), ans, rho);
  UNPROTECT(1);

then everything works fine :-)

Cheers,
H.

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