Re: [Rd] Defining environments within functions

2008-08-29 Thread Duncan Murdoch

Matt Calder wrote:

Duncan,

Sorry to be, well, nit picking, but I can't get your example to run. I 
am a longtime Splus user and am only using R on the side. The concept of 
environments is one I have yet to grasp. I think the example you are trying 
to provide will illuminate things for me, but it doesn't source. The 
definition of fnBuilder sources fine, though I am not sure what the 
commonArgs - ... is meant to do. Anyway, calling:
  


That wasn't R code, it was pseudocode.  That's why I asked the original 
poster for a real example: pseudocode examples aren't useful.  But I 
shouldn't have posted one myself, I should just have stopped at the 
first paragraph.


Duncan Murdoch
  

both - fnBuilder(...)


Error: '...' used in an incorrect context

and so I though, maybe you meant:

  

both - fnBuilder(c(1,2,3))


Error in fnBuilder(c(1, 2, 3)) : '...' used in an incorrect context

But then I thought you were perhaps using ... as a placeholder not as 
syntax and so I have little idea what it is you are trying to show. Could 
you clarify what your example is demonstrating in regards to scoping?


So far, I have found the only part of R my Splus knowledge doesn't 
translate is in regard to this sort of thing. I can't tell you how much pain 
translating substitute idioms into R has caused me. Thanks,


Matt




- Original Message - 
From: Duncan Murdoch [EMAIL PROTECTED]

To: [EMAIL PROTECTED]
Cc: r-devel@r-project.org
Sent: Thursday, August 28, 2008 5:42 AM
Subject: Re: [Rd] Defining environments within functions


  

Giles Hooker wrote:


How can I define environments within a function so that they are visible
to calls to a sub-function?

  
I think you need to give a simplified, runnable example.  (Or at least 
runnable until it hits the scoping problem you've got.)  Sub-function 
isn't R terminology, and it's not clear what you mean by it.


In R, you rarely need to work with environments explicitly.  You just 
define functions in the same location and they share the same environment. 
For example,


fnBuilder - function(commonArgs) {
 commonVars - ...
 ProfileErr - function(params, ...) {}
 coefs - function(params, ...) {}
 return(list(ProfileErr, coefs))
}

both - fnBuilder(...)
ProfileErr - both[[1]]
coefs - both[[2]]

Now ProfileErr and coefs share the same environment, and both can see (and 
modify) commonArgs and commonVars.


Duncan Murdoch




I have defined an objective function,

ProfileErr = function(params,...)

which I would like to optimize using standard routines (optim,
nlminb,) but which contains auxiliary variables which need to be
updated along with params. No optimization routine in R that I have
found has facilities for this.

Specifically, within ProfileErr, I need to calculate

  coefs(params,...)

This a function which requires a further optimization, and I can achieve
significant efficiency gains by starting  where the last optimization
ended, so I would like to keep track of it.

At the command line, I get around this by

ProfileEnv = new.env()
assign('coefs',coefs,3,ProfileEnv)

and within ProfileErr, I can call

startcoefs = get('coefs',envir=ProfileEnv)
* do the optimization to get newcoefs *
assign('coefs',newcoefs,3,ProfileEnv)

Then calling

optim(pars,ProfileErr,)

works fine. However, when I try to wrap all of that in its own function

profile.estimate = fn(pars,...){
ProfileEnv = new.env()
assign('coefs',coefs,3,ProfileEnv)

res = optim(pars,ProfileErr,)
}


ProfileErr no longer sees ProfileEnv. I haven't been able to make much
sense out of the documentation on environments, but is there a way to
make this work? Otherwise I'm back to writing variables out to files.

Many thanks,

Giles



  

__
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


[Rd] non user-friendly error for chol2inv functions

2008-08-29 Thread christophe dutang
Hi,

In function chol2inv with the option LINPACK set to false (default), it
raises an error when the matrix is 1x1 matrix (i.e. just a real) saying

'a' must be a numeric matrix

This error is raised by the underlying C function (modLa_chol2inv in
function Lapack.c). Everything is normal, but I wonder if we could have
another behavior when we pass a 1x1 matrix. I spent time this morning
finding where was the error, and it was this problem.

Thanks in advance

Christophe

[[alternative HTML version deleted]]

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


Re: [Rd] non user-friendly error for chol2inv functions

2008-08-29 Thread Martin Maechler
 cd == christophe dutang [EMAIL PROTECTED]
 on Fri, 29 Aug 2008 12:44:18 +0200 writes:

cd Hi,
cd In function chol2inv with the option LINPACK set to false (default), it
cd raises an error when the matrix is 1x1 matrix (i.e. just a real) saying

cd 'a' must be a numeric matrix

It is very helpful, but you have to read and understand it.
I'm pretty sure you did not provide a  1 x 1 matrix.

Here's an example showing how things works :

 m - matrix(4,1,1)
 cm - chol(m)
 cm
 [,1]
[1,]2
 chol2inv(cm)
 [,1]
[1,] 0.25
 

Martin Maechler, ETH Zurich


cd This error is raised by the underlying C function (modLa_chol2inv in
cd function Lapack.c). Everything is normal, but I wonder if we could have
cd another behavior when we pass a 1x1 matrix. I spent time this morning
cd finding where was the error, and it was this problem.

cd Thanks in advance

cd Christophe

cd [[alternative HTML version deleted]]

cd __
cd R-devel@r-project.org mailing list
cd 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] non user-friendly error for chol2inv functions

2008-08-29 Thread Martin Maechler
 cd == christophe dutang [EMAIL PROTECTED]
 on Fri, 29 Aug 2008 14:28:42 +0200 writes:

cd Yes, I do not cast the first argument as a matrix with as.matrix 
function.
cd Maybe we could detail the error message if the first argument is a 
numeric?

cd error(_('a' is a numeric and must be coerced to a numeric matrix));

Merci, Christophe.   Yes, we *could* do that.
Alternatively, I think I will just make it work in that case,
since I see that 
  qr(), chol(), svd(), solve()  all 
treat a numeric (of length 1) as a  1 x 1 matrix automatically.

cd Thanks for your answer
De rien!
Martin

cd 2008/8/29 Martin Maechler [EMAIL PROTECTED]

  cd == christophe dutang [EMAIL PROTECTED]
  on Fri, 29 Aug 2008 12:44:18 +0200 writes:
 
cd Hi,
cd In function chol2inv with the option LINPACK set to false (default),
 it
cd raises an error when the matrix is 1x1 matrix (i.e. just a real)
 saying
 
cd 'a' must be a numeric matrix
 
 It is very helpful, but you have to read and understand it.
 I'm pretty sure you did not provide a  1 x 1 matrix.
 
 Here's an example showing how things works :
 
  m - matrix(4,1,1)
  cm - chol(m)
  cm
 [,1]
 [1,]2
  chol2inv(cm)
 [,1]
 [1,] 0.25
 
 
 Martin Maechler, ETH Zurich
 
 
cd This error is raised by the underlying C function (modLa_chol2inv in
cd function Lapack.c). Everything is normal, but I wonder if we could
 have
cd another behavior when we pass a 1x1 matrix. I spent time this
 morning
cd finding where was the error, and it was this problem.
 
cd Thanks in advance
 
cd Christophe
 
cd [[alternative HTML version deleted]]
 
cd __
cd R-devel@r-project.org mailing list
cd https://stat.ethz.ch/mailman/listinfo/r-devel
 

cd [[alternative HTML version deleted]]

cd __
cd R-devel@r-project.org mailing list
cd 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] Defining environments within functions

2008-08-29 Thread Giles Hooker


Thanks,

I think I over-emphasized the secondary function, but I can generate the 
scoping problem as follows. First, at the command line, I can get a 
function to access objects that were not in its arguments by


ProfileEnv = new.env()
hello.world = Hello World
assign('hello.world',hello.world,3,envir=ProfileEnv)

fn1 = function()
{
hw = get('hello.world',envir=ProfileEnv)
print(hw)
}

and then call

 fn1()
[1] Hello World


Now I want to define a wrapper function

fn2 = function()
{
ProfileEnv = new.env()
hello.world = Hello World
assign('hello.world',hello.world,3,envir=ProfileEnv)

fn1()
}

and if I try

 rm(ProfileEnv)  # Just to be safe
 rm(hello.world)
 fn2()
Error in get(hello.world, envir = ProfileEnv) :
  object ProfileEnv not found

In my actual code, fn1() is really a call to

optim(pars,ProfileErr,)

and hello.world are quantities that were calculated the last time that 
ProfileErr was called and that I want to keep track of.


As an alternative simple example, how would I keep a counter for the 
number of times that optim (or any other generic optimizer) has called 
ProfileErr?


giles


How can I define environments within a function so that they are visible
to calls to a sub-function?
  


I think you need to give a simplified, runnable example.  (Or at least 
runnable until it hits the scoping problem you've got.)  Sub-function 
isn't R terminology, and it's not clear what you mean by it.


--
Giles Hooker
Assistant Professor:

Department of Biological Statistics and Computational Biology
Department of Statistical Science
1186 Comstock Hall
Cornell University
Ithaca, NY, 14853

Ph:  (+1 607) 255 1638
Fax: (+1 607) 255 4698

Email:  [EMAIL PROTECTED]

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


Re: [Rd] non user-friendly error for chol2inv functions

2008-08-29 Thread Ted Harding
On 29-Aug-08 13:00:01, Martin Maechler wrote:
 cd == christophe dutang [EMAIL PROTECTED]
 on Fri, 29 Aug 2008 14:28:42 +0200 writes:
 
 cd Yes, I do not cast the first argument as a matrix with
 cd as.matrix function.
 cd Maybe we could detail the error message if the first
 cd argument
 cd is a numeric?
 
 cd error(_('a' is a numeric and must be coerced to a numeric
 cd matrix));
 
 Merci, Christophe.   Yes, we *could* do that.
 Alternatively, I think I will just make it work in that case,
 since I see that 
   qr(), chol(), svd(), solve()  all 
 treat a numeric (of length 1) as a  1 x 1 matrix automatically.

I was about to draw attention to this inconsistency!
While one is about it, might it not be useful also to do
the converse: Treat a 1x1 matrix as a scalar in appropriate
contexts?

E.g.

  a - 4
  A - matrix(4,1,1)
  B - matrix(c(1,2,3,4),2,2)
  a*B
#  [,1] [,2]
# [1,]4   12
# [2,]8   16

  a+B
#  [,1] [,2]
# [1,]57
# [2,]68

  A*B
# Error in A * B : non-conformable arrays
  A+B
# Error in A + B : non-conformable arrays

Ted. 


 
 cd Thanks for your answer
 De rien!
 Martin
 
 cd 2008/8/29 Martin Maechler [EMAIL PROTECTED]
 
   cd == christophe dutang [EMAIL PROTECTED]
   on Fri, 29 Aug 2008 12:44:18 +0200 writes:
  
 cd Hi,
 cd In function chol2inv with the option LINPACK set to false
 (default),
  it
 cd raises an error when the matrix is 1x1 matrix (i.e. just a
 real)
  saying
  
 cd 'a' must be a numeric matrix
  
  It is very helpful, but you have to read and understand it.
  I'm pretty sure you did not provide a  1 x 1 matrix.
  
  Here's an example showing how things works :
  
   m - matrix(4,1,1)
   cm - chol(m)
   cm
  [,1]
  [1,]2
   chol2inv(cm)
  [,1]
  [1,] 0.25
  
  
  Martin Maechler, ETH Zurich
  
  
 cd This error is raised by the underlying C function
 (modLa_chol2inv in
 cd function Lapack.c). Everything is normal, but I wonder if we
 could
  have
 cd another behavior when we pass a 1x1 matrix. I spent time this
  morning
 cd finding where was the error, and it was this problem.
  
 cd Thanks in advance
  
 cd Christophe
  
 cd [[alternative HTML version deleted]]
  
 cd __
 cd R-devel@r-project.org mailing list
 cd https://stat.ethz.ch/mailman/listinfo/r-devel
  
 
 cd [[alternative HTML version deleted]]
 
 cd __
 cd R-devel@r-project.org mailing list
 cd https://stat.ethz.ch/mailman/listinfo/r-devel
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel


E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 29-Aug-08   Time: 14:16:03
-- XFMail --

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


Re: [Rd] non user-friendly error for chol2inv functions

2008-08-29 Thread Martin Maechler
 TH == Ted Harding [EMAIL PROTECTED]
 on Fri, 29 Aug 2008 14:21:05 +0100 (BST) writes:

TH On 29-Aug-08 13:00:01, Martin Maechler wrote:
 cd == christophe dutang [EMAIL PROTECTED]
 on Fri, 29 Aug 2008 14:28:42 +0200 writes:
 
cd Yes, I do not cast the first argument as a matrix with
cd as.matrix function.
cd Maybe we could detail the error message if the first
cd argument
cd is a numeric?
 
cd error(_('a' is a numeric and must be coerced to a numeric
cd matrix));
 
 Merci, Christophe.   Yes, we *could* do that.
 Alternatively, I think I will just make it work in that case,
 since I see that 
 qr(), chol(), svd(), solve()  all 
 treat a numeric (of length 1) as a  1 x 1 matrix automatically.

TH I was about to draw attention to this inconsistency!
TH While one is about it, might it not be useful also to do
TH the converse: Treat a 1x1 matrix as a scalar in appropriate
TH contexts?

TH E.g.

TH a - 4
TH A - matrix(4,1,1)
TH B - matrix(c(1,2,3,4),2,2)
TH a*B
TH #  [,1] [,2]
TH # [1,]4   12
TH # [2,]8   16

TH a+B
TH #  [,1] [,2]
TH # [1,]57
TH # [2,]68

TH A*B
TH # Error in A * B : non-conformable arrays
TH A+B
TH # Error in A + B : non-conformable arrays

TH Ted. 

I can only speak for myself and my own taste,
but I'd clearly not want that the above would just work.

I could agree of having it work  *WITH A WARNING* ...
particularly if there were more good arguments along your line
of thought..

Martin




 
cd Thanks for your answer
 De rien!
 Martin
 
cd 2008/8/29 Martin Maechler [EMAIL PROTECTED]
 
   cd == christophe dutang [EMAIL PROTECTED]
   on Fri, 29 Aug 2008 12:44:18 +0200 writes:
  
cd Hi,
cd In function chol2inv with the option LINPACK set to false
 (default),
  it
cd raises an error when the matrix is 1x1 matrix (i.e. just a
 real)
  saying
  
cd 'a' must be a numeric matrix
  
  It is very helpful, but you have to read and understand it.
  I'm pretty sure you did not provide a  1 x 1 matrix.
  
  Here's an example showing how things works :
  
   m - matrix(4,1,1)
   cm - chol(m)
   cm
  [,1]
  [1,]2
   chol2inv(cm)
  [,1]
  [1,] 0.25
  
  
  Martin Maechler, ETH Zurich
  
  
cd This error is raised by the underlying C function
 (modLa_chol2inv in
cd function Lapack.c). Everything is normal, but I wonder if we
 could
  have
cd another behavior when we pass a 1x1 matrix. I spent time this
  morning
cd finding where was the error, and it was this problem.
  
cd Thanks in advance
  
cd Christophe
  
cd [[alternative HTML version deleted]]
  
cd __
cd R-devel@r-project.org mailing list
cd https://stat.ethz.ch/mailman/listinfo/r-devel
  
 
cd [[alternative HTML version deleted]]
 
cd __
cd R-devel@r-project.org mailing list
cd https://stat.ethz.ch/mailman/listinfo/r-devel
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel

TH 
TH E-Mail: (Ted Harding) [EMAIL PROTECTED]
TH Fax-to-email: +44 (0)870 094 0861
TH Date: 29-Aug-08   Time: 14:16:03
TH -- XFMail --

TH __
TH R-devel@r-project.org mailing list
TH 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] Defining environments within functions

2008-08-29 Thread Luke Tierney

If you want to use this pattern repeatedly you can define something like

makeFunWithCounter - function(fun) {
counter - 0
list(count = function() counter,
 fun = function(...) { counter - counter + 1; fun(...)})
}

and then do

 fwc - makeFunWithCounter(function() print(Hello))
 f2 - fwc$fun
 f2()
[1] Hello
 f2()
[1] Hello
 f2()
[1] Hello
 fwc$count()
[1] 3

If you only want to do it once you can use local,

fwc - local({
counter - 0
fun - function() { counter - counter + 1; print(Hello) }
list(count = function() counter, fun = fun)
})

Best,

luke

On Fri, 29 Aug 2008, Giles Hooker wrote:



Thanks,

I think I over-emphasized the secondary function, but I can generate the 
scoping problem as follows. First, at the command line, I can get a function 
to access objects that were not in its arguments by


ProfileEnv = new.env()
hello.world = Hello World
assign('hello.world',hello.world,3,envir=ProfileEnv)

fn1 = function()
{
hw = get('hello.world',envir=ProfileEnv)
print(hw)
}

and then call


fn1()

[1] Hello World


Now I want to define a wrapper function

fn2 = function()
{
ProfileEnv = new.env()
hello.world = Hello World
assign('hello.world',hello.world,3,envir=ProfileEnv)

fn1()
}

and if I try


rm(ProfileEnv)  # Just to be safe
rm(hello.world)
fn2()

Error in get(hello.world, envir = ProfileEnv) :
 object ProfileEnv not found

In my actual code, fn1() is really a call to

optim(pars,ProfileErr,)

and hello.world are quantities that were calculated the last time that 
ProfileErr was called and that I want to keep track of.


As an alternative simple example, how would I keep a counter for the number 
of times that optim (or any other generic optimizer) has called ProfileErr?


giles


How can I define environments within a function so that they are visible
to calls to a sub-function?



I think you need to give a simplified, runnable example.  (Or at least 
runnable until it hits the scoping problem you've got.)  Sub-function 
isn't R terminology, and it's not clear what you mean by it.





--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:  [EMAIL PROTECTED]
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

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


[Rd] Security issue with javareconf script (PR#12636)

2008-08-29 Thread tcallawa
Full_Name: Tom Callaway
Version: 2.7.2
OS: Fedora 10 (Linux/x86_64)
Submission from: (NULL) (96.233.67.230)


Recently, Debian identified a security issue with the javareconf script in R. I
confirmed that this is still unfixed in R 2.7.2.

The following patch resolves the issue:

diff -up R-2.7.2/src/scripts/javareconf.BAD R-2.7.1/src/scripts/javareconf
--- R-2.7.2/src/scripts/javareconf.BAD  2008-08-29 11:04:21.0 -0400
+++ R-2.7.2/src/scripts/javareconf  2008-08-29 11:05:34.0 -0400
@@ -125,16 +125,17 @@ fi
 javac_works='not present'
 if test -n $JAVAC; then
 javac_works='not functional'
-rm -rf /tmp/A.java /tmp/A.class
-echo public class A { }  /tmp/A.java
-if test -e /tmp/A.java; then
-   if ${JAVAC} /tmp/A.java /dev/null; then
-   if test -e /tmp/A.class; then
+tempdir=`mktemp -d`
+echo public class A { }  ${tempdir}/A.java
+if test -e ${tempdir}/A.java; then
+   if ${JAVAC} ${tempdir}/A.java /dev/null; then
+   if test -e ${tempdir}/A.class; then
javac_works=yes
fi
fi
 fi
-rm -rf /tmp/A.java /tmp/A.class
+rm -rf ${tempdir}
+
 fi
 if test ${javac_works} = yes; then
 echo Java compiler: ${JAVAC}

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


Re: [Rd] specifying compiler path in configure

2008-08-29 Thread Mark Kimpel
After reading over the relevant sections of the manual more carefully,
I now see where the information is presented and I was able to get R
to compile with an alternate version of gcc. On thing, however,
remains unclear to me. If R is compiled with a non-default version of
a compiler, are subsequent add-on packages and updated automatically
directed to use the alternate or is it necessary to include this
information in 'install.packages' and 'update.packages'? If the
latter, then it is unclear to me how this is accomplished. Below is my
best attempt at putting this instruction into install.packages and it
failed to produce the intended result, with gcc-4.3 being used instead
of 4.2.

 install.packages(affxparser, repos=repos,configure.args =
c('CC=/usr/bin/gcc-4.2', 'CXX=/usr/bin/g++-4.2'))

Thanks, Mark

On Wed, Aug 27, 2008 at 4:38 PM, Prof Brian Ripley
[EMAIL PROTECTED] wrote:
 On Wed, 27 Aug 2008, Mark Kimpel wrote:

 I'm having trouble building some packages while running Debian Lenny
 (testing) and suspect that the issues are related to the default use
 of gcc-4.3.

 You might want to compare your problems with the CRAN checks at

 http://cran.r-project.org/web/checks/check_summary.html

 as those are run with gcc 4.3.x on Debian testing.  From memory, the
 problems are confined to C++-(mis)using packages.

 With Lenny, build-essentials depends on 4.3, so I'd like
 to leave it installed but have also installed 4.2.1. How do I tell
 ./configure the path to 4.2.1 ? Im sure it's an option, but I don't
 see it documented in the R-admin manual.

 From configure --help:

  CC  C compiler command
  CFLAGS  C compiler flags

 There are many examples of setting CC in the R-admin manual, and the first
 para of 'Essential Programs' seems to me to tell you that as well.

 --
 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




-- 
Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry
Indiana University School of Medicine

15032 Hunter Court, Westfield, IN 46074

(317) 490-5129 Work,  Mobile  VoiceMail
(317) 663-0513 Home (no voice mail please)

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


Re: [Rd] Security issue with javareconf script (PR#12636)

2008-08-29 Thread Dirk Eddelbuettel

On 29 August 2008 at 17:35, [EMAIL PROTECTED] wrote:
| Full_Name: Tom Callaway
| Version: 2.7.2
| OS: Fedora 10 (Linux/x86_64)
| Submission from: (NULL) (96.233.67.230)
| 
| 
| Recently, Debian identified a security issue with the javareconf script in R. 

Yes, somewhat launched a massive list of bug reports against all script using
plain /tmp.  The fact that javareconf already rm's the file just before
creation leaves just a tiny tiny tiny window -- but I didn't argue this with
our folks either as the patch (almost like yours) is easy enough.

| I confirmed that this is still unfixed in R 2.7.2.
| 
| The following patch resolves the issue:
| 
| diff -up R-2.7.2/src/scripts/javareconf.BAD R-2.7.1/src/scripts/javareconf
| --- R-2.7.2/src/scripts/javareconf.BAD  2008-08-29 11:04:21.0 -0400
| +++ R-2.7.2/src/scripts/javareconf2008-08-29 11:05:34.0 -0400
| @@ -125,16 +125,17 @@ fi
|  javac_works='not present'
|  if test -n $JAVAC; then
|  javac_works='not functional'
| -rm -rf /tmp/A.java /tmp/A.class
| -echo public class A { }  /tmp/A.java
| -if test -e /tmp/A.java; then
| - if ${JAVAC} /tmp/A.java /dev/null; then
| -   if test -e /tmp/A.class; then
| +tempdir=`mktemp -d`

mktemp -d -t is preferable, and that is what out patch does. 

I reported this to Simon off-list. The trouble is that such a patch, at the R
source level, would require mktemp to be present on all system which is not a
given.  So I suggested to Simon to add a function that will use mktemp where
available and 'does something else' otherwise.  I have not heard back yet.

Dirk


| +echo public class A { }  ${tempdir}/A.java
| +if test -e ${tempdir}/A.java; then
| + if ${JAVAC} ${tempdir}/A.java /dev/null; then
| +   if test -e ${tempdir}/A.class; then
| javac_works=yes
| fi
|   fi
|  fi
| -rm -rf /tmp/A.java /tmp/A.class
| +rm -rf ${tempdir}
| +
|  fi
|  if test ${javac_works} = yes; then
|  echo Java compiler: ${JAVAC}
| 
| __
| R-devel@r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Three out of two people have difficulties with fractions.

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


Re: [Rd] Security issue with javareconf script (PR#12636)

2008-08-29 Thread Peter Dalgaard

[EMAIL PROTECTED] wrote:

Full_Name: Tom Callaway
Version: 2.7.2
OS: Fedora 10 (Linux/x86_64)
Submission from: (NULL) (96.233.67.230)


Recently, Debian identified a security issue with the javareconf script in R. I
confirmed that this is still unfixed in R 2.7.2.

The following patch resolves the issue:

diff -up R-2.7.2/src/scripts/javareconf.BAD R-2.7.1/src/scripts/javareconf
--- R-2.7.2/src/scripts/javareconf.BAD  2008-08-29 11:04:21.0 -0400
+++ R-2.7.2/src/scripts/javareconf  2008-08-29 11:05:34.0 -0400
@@ -125,16 +125,17 @@ fi
 javac_works='not present'
 if test -n $JAVAC; then
 javac_works='not functional'
-rm -rf /tmp/A.java /tmp/A.class
-echo public class A { }  /tmp/A.java
-if test -e /tmp/A.java; then
-   if ${JAVAC} /tmp/A.java /dev/null; then
-   if test -e /tmp/A.class; then
+tempdir=`mktemp -d`
+echo public class A { }  ${tempdir}/A.java
+if test -e ${tempdir}/A.java; then
+   if ${JAVAC} ${tempdir}/A.java /dev/null; then
+   if test -e ${tempdir}/A.class; then
javac_works=yes
fi
fi
 fi
-rm -rf /tmp/A.java /tmp/A.class
+rm -rf ${tempdir}
+
 fi
 if test ${javac_works} = yes; then
 echo Java compiler: ${JAVAC}
  
OK, committed. Not the easiest hole to exploit, I'd say (notice that we 
only compile something, not execute it).



.

Oh, sh*! This is not portable! Needs code like INSTALL. Will refix.

--
  O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
 c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

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


Re: [Rd] R 2.7.2 for Windows fails to install local zip package (PR#12612)

2008-08-29 Thread Claude Rubinson
On Wed, Aug 27, 2008 at 06:54:27AM -0400, Duncan Murdoch wrote:
 [EMAIL PROTECTED] wrote:
 R version 2.7.2 for Windows fails to install local (zipped) packages
 with following messages:

   
 utils:::menuInstallLocal()
 
 updating HTML package descriptions
 Error in .readRDS(pfile) : error reading from connection
   
 It works for me.  I suspect you have permissions problems. 

It appears that it may have been a problem in how I was compiling the
Windows-version of the package.  I'll let you know if the error rears
its head again.

Claude

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


[Rd] coxph function (Survival Library) (PR#12638)

2008-08-29 Thread ana . marcos
Hi,

I am pretty sure that the results of Likelihood ratio test are bigger 
than the real value. They are multiplied for the factor Ln(10), in this 
way the p-values are smaller than what they should be.
The reason is that you apply the formula -2*log(exp(L(0)/exp(L(B)) and 
not  what it should be -2*log(L(0)/L(B)).

Please if I am not right, tell me

Thanks

Ana

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


Re: [Rd] R 2.7.2 for Windows fails to install local zip package (PR#12639)

2008-08-29 Thread rubinson
On Wed, Aug 27, 2008 at 06:54:27AM -0400, Duncan Murdoch wrote:
 [EMAIL PROTECTED] wrote:
 R version 2.7.2 for Windows fails to install local (zipped) packages
 with following messages:

   
 utils:::menuInstallLocal()
 
 updating HTML package descriptions
 Error in .readRDS(pfile) : error reading from connection
   
 It works for me.  I suspect you have permissions problems. 

It appears that it may have been a problem in how I was compiling the
Windows-version of the package.  I'll let you know if the error rears
its head again.

Claude

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


Re: [Rd] Security issue with javareconf script (PR#12636)

2008-08-29 Thread Tom spot Callaway
On Fri, 2008-08-29 at 20:04 +0200, Peter Dalgaard wrote:
 OK, committed. Not the easiest hole to exploit, I'd say (notice that
 we 
 only compile something, not execute it).
 
 
 .
 
 Oh, sh*! This is not portable! Needs code like INSTALL. Will refix.

Sorry about that. I forgot that people cared about *nix that has a
supported Java but no mktemp implementation... :)

~spot

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


Re: [Rd] serialize() to via temporary file is heaps faster than doing it directly (on Windows)

2008-08-29 Thread Henrik Bengtsson
I just want to re-post this thread in case it slipped through the
summer sieve of someone that might be interested and/or has a real
solution beyond my serialize2() patch.

Cheers

Henrik

On Thu, Jul 24, 2008 at 8:10 PM, Henrik Bengtsson [EMAIL PROTECTED] wrote:
 Hi,

 FYI, I just notice that on Windows (but not Linux) it is orders of
 magnitude (below it's 50x) faster to serialize() and object to a
 temporary file and then read it back, than to serialize to an object
 directly.  This has for instance impact on how fast digest::digest()
 can provide a checksum.

 Example:
 x - 1:1e7;
 t1 - system.time(raw1 - serialize(x, connection=NULL));
 print(t1);
 #user  system elapsed
 #   174.23  129.35  304.70  ## 5 minutes
 t2 - system.time(raw2 - serialize2(x, connection=NULL));
 print(t2);
 # user  system elapsed
 # 2.190.185.72  ## 5 seconds
 print(t1/t2);
 #  usersystem   elapsed
 #   79.55708 718.6  53.26923
 stopifnot(identical(raw1, raw2));

 where serialize2() is serialize():ing to file and reading the results back:

 serialize2 - function(object, connection, ...) {
  if (is.null(connection)) {
# It is faster to serialize to a temporary file and read it back
pathname - tempfile();
con - file(pathname, open=wb);
on.exit({
  if (!is.null(con))
close(con);
  if (file.exists(pathname))
file.remove(pathname);
});
base::serialize(object, connection=con, ...);
close(con);
con - NULL;
fileSize - file.info(pathname)$size;
readBin(pathname, what=raw, n=fileSize);
  } else {
base::serialize(object, connection=connection, ...);
  }
 } # serialize2()

 The above benchmarking was done in a fresh R v2.7.1 session on WinXP Pro:

 sessionInfo()
 R version 2.7.1 Patched (2008-06-27 r46012)
 i386-pc-mingw32

 locale:
 LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
 States.1252;LC_MON
 ETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United 
 States.1252

 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base


 When I do the same on a Linux machine there is no difference:

 sessionInfo()
 R version 2.7.1 (2008-06-23)
 x86_64-unknown-linux-gnu

 locale:
 LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base

 Is there an obvious reason (and an obvious fix) for this?

 Cheers

 Henrik


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


Re: [Rd] locale2charset CPU overhead (PR#12633)

2008-08-29 Thread Duncan Murdoch

On 8/28/2008 3:25 PM, [EMAIL PROTECTED] wrote:

Full_Name: R User
Version: 2.7.2 (default binary)
OS: Windows XP SP2
Submission from: (NULL) (83.25.29.163)


Hello!

I have conducted following experiment running simple R script:

for (i in 1:1) {
a-0
   for (j in 1:1000)
 a-c(a,j)
}

profiled R.dll using Intel Vtune and obtained following results!!!

Func. Name  Clocticks
locale2charset  46,58%  
R_RunWeakRefFinalizer   20,85%  
Rf_eval 8,77%   

Rf_eval takes only about 9% of CPU time, a huge overhead on checking 
locale character set!!! It seems that is the problem with family of 
functions: c(), rbind(), cbind()


I don't have Vtune, so I don't know that its clock counts are reliable. 
 Could you please identify where the calls to locale2charset are coming 
from?  I don't see anything obvious in the source that would explain 
this, so I suspect Vtune is misreporting.


If I were to guess, I would say your loop would be spending most of its 
time in memory management functions, since you allocate and reallocate 
a so many times.  Since those aren't even mentioned by Vtune, I think 
it is confused.


Duncan Murdoch

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


Re: [Rd] coxph function (Survival Library) (PR#12638)

2008-08-29 Thread Peter Dalgaard

[EMAIL PROTECTED] wrote:

Hi,

I am pretty sure that the results of Likelihood ratio test are bigger 
than the real value. They are multiplied for the factor Ln(10), in this 
way the p-values are smaller than what they should be.
The reason is that you apply the formula -2*log(exp(L(0)/exp(L(B)) and 
not  what it should be -2*log(L(0)/L(B)).


Please if I am not right, tell me
  


I don't think you are and please don't use the bug report system when 
you are not sure.


Notice that the conventions for the default base in log differ between 
countries (and even between education levels with countries). There's no 
indication that base 10 logs are used anywhere, so where would a factor 
of ln(10) creep in?


--
  O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
 c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

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