[Rd] discrete-time survival model

2010-05-14 Thread Christophe Dutang
Dear List,

Last week, I asked on R-help if there was a package implementing the dynamic 
discrete time model of Fahrmeir (1994) - http://www.jstor.org/pss/2336962. 
Unfortunately, nobody answered. So I start to implement it. 

Does anyone interested in such development? Or is it useless because someone 
has already implemented this model?

In the coming days, I plan to move my code on R-forge, so people can easily 
contribute. If you are interested please let me know.

Thanks in advance

Christophe


--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr







[[alternative HTML version deleted]]

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


Re: [Rd] where is libRmath.a libRmath.so

2010-05-14 Thread Uwe Ligges



On 14.05.2010 04:47, Dave Lubbers wrote:


I see Rmath.h in include.  Why can't I find libRmath.a and/or libRmath.so?



Since you have not compiled them yet? See the R Installation and 
Administration manual.


Uwe Ligges

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


[Rd] Creating an S3 method when the generic function is defined in another (imported) package

2010-05-14 Thread Arne Henningsen
Hi,

In one of my packages (maxLik), I would like to add an S3 method,
where the generic function (estfun) is defined in another package
(sandwich). Everything works fine if my package Depends on the other
package and I import the generic function estfun from the sandwich
package and define the new method in the NAMESPACE file. However, I
prefer not to load the entire other package just to use a single
generic function from it. Therefore, I replaced Depends by Imports
in the DESCRIPTION file and (re-)exported estfun in the NAMESPACE
file. Now R CMD check warns about the undocumented code object
estfun but I do not want to include a duplicate of the documentation
of estfun. Do you know a better solution?

Thanks a lot,
Arne

-- 
Arne Henningsen
http://www.arne-henningsen.name

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


Re: [Rd] Creating an S3 method when the generic function is defined in another (imported) package

2010-05-14 Thread Achim Zeileis

On Fri, 14 May 2010, Arne Henningsen wrote:


Hi,

In one of my packages (maxLik), I would like to add an S3 method,
where the generic function (estfun) is defined in another package
(sandwich). Everything works fine if my package Depends on the other
package and I import the generic function estfun from the sandwich
package and define the new method in the NAMESPACE file. However, I
prefer not to load the entire other package just to use a single
generic function from it. Therefore, I replaced Depends by Imports
in the DESCRIPTION file and (re-)exported estfun in the NAMESPACE
file. Now R CMD check warns about the undocumented code object
estfun but I do not want to include a duplicate of the documentation
of estfun. Do you know a better solution?


I probably wouldn't re-export the estfun() generic. People will probably 
load sandwich anyway before calling estfun(), in particular if they want 
to compute the sandwich() covariance matrix.


hth,
Z


Thanks a lot,
Arne

--
Arne Henningsen
http://www.arne-henningsen.name

__
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] Creating an S3 method when the generic function is defined in another (imported) package

2010-05-14 Thread Arne Henningsen
On 14 May 2010 10:37, Achim Zeileis achim.zeil...@uibk.ac.at wrote:
 On Fri, 14 May 2010, Arne Henningsen wrote:

 Hi,

 In one of my packages (maxLik), I would like to add an S3 method,
 where the generic function (estfun) is defined in another package
 (sandwich). Everything works fine if my package Depends on the other
 package and I import the generic function estfun from the sandwich
 package and define the new method in the NAMESPACE file. However, I
 prefer not to load the entire other package just to use a single
 generic function from it. Therefore, I replaced Depends by Imports
 in the DESCRIPTION file and (re-)exported estfun in the NAMESPACE
 file. Now R CMD check warns about the undocumented code object
 estfun but I do not want to include a duplicate of the documentation
 of estfun. Do you know a better solution?

 I probably wouldn't re-export the estfun() generic. People will probably
 load sandwich anyway before calling estfun(), in particular if they want
 to compute the sandwich() covariance matrix.

Good point!

Thanks a lot,
Arne

-- 
Arne Henningsen
http://www.arne-henningsen.name

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


Re: [Rd] results of pnorm as either NaN or Inf

2010-05-14 Thread Prof Brian Ripley
The answer to pnorm(-x, log.p=TRUE) is of course about -0.5*x*x for 
large x.  So trying to compute it for -1e108 is a bit silly, both on 
your part and the C code used.  I've altered the C code not to attempt 
it for x  1e170, which excludes the area where underflow occurs.


On Fri, 14 May 2010, ted.hard...@manchester.ac.uk wrote:


On 13-May-10 20:04:50, efree...@berkeley.edu wrote:

I stumbled across this and I am wondering if this is unexpected
behavior or if I am missing something.


pnorm(-1.0e+307, log.p=TRUE)

[1] -Inf

pnorm(-1.0e+308, log.p=TRUE)

[1] NaN
Warning message:
In pnorm(q, mean, sd, lower.tail, log.p) : NaNs produced

pnorm(-1.0e+309, log.p=TRUE)

[1] -Inf

I don't know C and am not that skilled with R, so it would be hard
for me to look into the code for pnorm. If I'm not just missing
something, I thought it may be of interest.

Details:
I am using Mac OS X 10.5.8. I installed a precompiled binary version.
Here is the output from sessionInfo(), requested in the posting guide:
R version 2.11.0 (2010-04-22)
i386-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

loaded via a namespace (and not attached):
[1] tools_2.11.0

Thank you very much,

Eric Freeman
UC Berkeley


This is probably platform-independent. I get the same results with
R on Linux. More to the point:

You are clearly pushing the envelope here. First, have a look
at what R makes of your inputs to pnorm():

 -1.0e+307
 # [1] -1e+307
 -1.0e+308
 # [1] -1e+308
 -1.0e+309
 # [1] -Inf


So, somewhere beteen -1e+308 and -1.0e+309. the envelope burst!
Given -1.0e+309, R returns -Inf (i.e. R can no longer represent
this internally as a finite number).

Now look at

 pnorm(-Inf,log.p=TRUE)
 # [1] -Inf

So, R knows how to give the correct answer (an exact 0, or -Inf
on the log scale) if you feed pnorm() with -Inf. So you're OK
with -1e+N where N = 309.

For smaller powers, e.g. -1e+(200:306), these give pnorm() much
less than -1.0e+309, and presumably R's algorithm (which I haven't
studied either ... ) returns 0 for pnorm(), as it should to the
available internal accuracy.

So, up to pnorm(-1.0e+307, log.p=TRUE) = -Inf. All is as it should be.
However, at -1e+308, the envelope is about to burst, and something
may occur within the algorithm which results in a NaN.

So there is nothing anomalous about your results except at -1e+308,
which is where R is at a critical point.

That's how I see it, anway!
Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 14-May-10   Time: 00:01:27
-- XFMail --

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



--
Brian D. Ripley,  rip...@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, UKFax:  +44 1865 272595

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


Re: [Rd] Using Sweave in hostile environments

2010-05-14 Thread Duncan Murdoch

Just for the archives, a partial answer to my question:

I was unable to find a definition for the Sinput environment that would 
work, but relatively minor changes to some of the RweaveLatex functions 
cause Sweave to generate SaveVerbatim environments rather than Sinput 
environments, and that's enough to get things to work.  So the example 
below would be handled using


chunkname, eval=FALSE, saveVerbatim=TRUE=
x - 1
@

somewhere safe, and then

\BUseVerbatim[fontshape=sl]{chunkname.in.1}

in the box.  Each piece of input or output will be saved in a separate 
verbatim piece, and they each need to be used explicitly:  you'll 
probably want to look at the .tex file to figure out the names.


This is pretty rough and I won't commit it to R, but I've attached the 
patch file (against R trunk rev 51988) in case anyone else wants to use it.


Duncan Murdoch

On 13/05/2010 10:19 AM, Duncan Murdoch wrote:
I'm trying to put together a poster using the LaTeX a0poster package and 
including some things from pstricks to get gradient shading, etc.


The problem is that the default environments used by Sweave don't work 
where I need them.  A simple code chunk like


eval=FALSE=
x - 1
@

buried in a minipage within a psshadowbox gives the error

Runaway argument?
  x - 1 \end {Sinput} \end {Schunk} and the resulting variable would\ETC.
D:/test.tex:302: Paragraph ended before \FV@
BeginScanning was complete


Has anyone solved this problem?  One way I see that might work is to put 
the code chunk outside the environment and use SaveVerbatim to save it, 
then just put \BUseVerbatim or \LUseVerbatim in place where I need it.  
But because I'm using Sweave, I somehow need to redefine the Sinput, 
Soutput and maybe the Schunk environments to do that, and I don't see 
how to do so. 


Duncan Murdoch

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


Index: Sweave.R
===
--- Sweave.R(revision 51988)
+++ Sweave.R(working copy)
@@ -368,7 +368,8 @@
 split=FALSE, strip.white=true, include=TRUE,
 pdf.version=grDevices::pdf.options()$version,
 pdf.encoding=grDevices::pdf.options()$encoding,
-concordance=FALSE, expand=TRUE)
+concordance=FALSE, expand=TRUE,
+saveVerbatim=FALSE)
 options[names(dots)] - dots
 
 ## to be on the safe side: see if defaults pass the check
@@ -482,8 +483,12 @@
 thisline - thisline + 1
 openSchunk - TRUE
 }
-cat(\\begin{Sinput},
-file=chunkout, append=TRUE)
+if (options$saveVerbatim) 
+cat(\\begin{SaveVerbatim}{, options$label, 
.in., nce, }, sep=, 
+file=chunkout, append=TRUE)

+else
+cat(\\begin{Sinput},
+   file=chunkout, append=TRUE)
 openSinput - TRUE
 }
cat(\n, paste(getOption(prompt), dce[1L:leading], 
sep=, collapse=\n),
@@ -516,7 +521,10 @@
 if(length(output)  (options$results != hide)){
 
 if(openSinput){
-cat(\n\\end{Sinput}\n, file=chunkout, append=TRUE)
+   if (options$saveVerbatim) 
+   cat(\n\\end{SaveVerbatim}\n, file=chunkout, 
append=TRUE)
+   else
+cat(\n\\end{Sinput}\n, file=chunkout, 
append=TRUE)
 linesout[thisline + 1L:2L] - srcline
 thisline - thisline + 2L
 openSinput - FALSE
@@ -529,8 +537,12 @@
 thisline - thisline + 1L
 openSchunk - TRUE
 }
-cat(\\begin{Soutput}\n,
-file=chunkout, append=TRUE)
+if(options$saveVerbatim)
+cat(\\begin{SaveVerbatim}{, options$label, 
.out., nce, }\n,
+   sep=, file=chunkout, append=TRUE)
+else
+cat(\\begin{Soutput}\n,
+   file=chunkout, append=TRUE)
 linesout[thisline + 1L] - srcline
 thisline - thisline + 1L
 }
@@ -552,7 +564,10 @@
 remove(output)
 
 if(options$results==verbatim){
-cat(\n\\end{Soutput}\n, file=chunkout, append=TRUE)
+   if (options$saveVerbatim)
+   cat(\n\\end{SaveVerbatim}\n, file=chunkout, 

[Rd] Compiling R with ATLAS

2010-05-14 Thread Avraham Adler
Hello. I know almost nothing about Linux, so I apologize if the answer to
this is obvious.

I am trying to compile R with ATLAS (successfully compiled 3.9.24 on Ubuntu
10.04 64 bit). I configured with:

./configure --enable-R-shlib --enable-BLAS-shlib
--with-blas=-L/usr/local/atlas/lib -lf77blas -latlas
--with-lapack=-L/usr/local/atlaslib -llapack -lcblas --with-x

and I get this error (from config.log):

configure:28566: checking for dgemm_ in -L/usr/local/atlas/lib -lf77blas
-latlas
configure:28587: gcc -std=gnu99 -o conftest -g -O2 -fpic
-I/usr/local/include  -L/usr/local/lib64 conftest.c -L/usr/local/atlas/lib
-lf77blas -latlas  -lgfortran -lm -ldl -lm  5
conftest.c: In function 'main':
conftest.c:193: warning: implicit declaration of function 'dgemm_'
/usr/local/atlas/lib/libf77blas.so: undefined reference to
`atl_f77wrap_zger2u_'
/usr/local/atlas/lib/libf77blas.so: undefined reference to
`atl_f77wrap_cger2c_'
/usr/local/atlas/lib/libf77blas.so: undefined reference to
`atl_f77wrap_zger2c_'
/usr/local/atlas/lib/libf77blas.so: undefined reference to
`atl_f77wrap_cger2u_'
collect2: ld returned 1 exit status
configure:28587: $? = 1

I found the following e-mail in the archives 
http://www.mail-archive.com/r-devel@r-project.org/msg16853.html, but it has
a different error, and the suggestion of switching out the BLAS later does
not seem to apply to ATLAS which requires two files, I think.

Any advice would be very appreciated.

Thank you.

[[alternative HTML version deleted]]

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


Re: [Rd] Compiling R with ATLAS

2010-05-14 Thread Douglas Bates
There is a Debian/Ubuntu specific list, r-sig-deb...@r-project.org,
which I am cc:'ing on this reply, that is a better location for this
discussion.

It appears that you may be going about things the hard way.  There are
Ubuntu packages for atlas and for R that can handle all of this for
you.  Take a look at http://cran.r-project.org/bin/linux/ubuntu for
information on how to get started.  It will probably be much easier to
install the pre-compiled packages first and worry about compilation
for customization later.

On Thu, May 13, 2010 at 11:16 PM, Avraham Adler avraham.ad...@gmail.com wrote:
 Hello. I know almost nothing about Linux, so I apologize if the answer to
 this is obvious.

 I am trying to compile R with ATLAS (successfully compiled 3.9.24 on Ubuntu
 10.04 64 bit). I configured with:

 ./configure --enable-R-shlib --enable-BLAS-shlib
 --with-blas=-L/usr/local/atlas/lib -lf77blas -latlas
 --with-lapack=-L/usr/local/atlaslib -llapack -lcblas --with-x

 and I get this error (from config.log):

 configure:28566: checking for dgemm_ in -L/usr/local/atlas/lib -lf77blas
 -latlas
 configure:28587: gcc -std=gnu99 -o conftest -g -O2 -fpic
 -I/usr/local/include  -L/usr/local/lib64 conftest.c -L/usr/local/atlas/lib
 -lf77blas -latlas  -lgfortran -lm -ldl -lm  5
 conftest.c: In function 'main':
 conftest.c:193: warning: implicit declaration of function 'dgemm_'
 /usr/local/atlas/lib/libf77blas.so: undefined reference to
 `atl_f77wrap_zger2u_'
 /usr/local/atlas/lib/libf77blas.so: undefined reference to
 `atl_f77wrap_cger2c_'
 /usr/local/atlas/lib/libf77blas.so: undefined reference to
 `atl_f77wrap_zger2c_'
 /usr/local/atlas/lib/libf77blas.so: undefined reference to
 `atl_f77wrap_cger2u_'
 collect2: ld returned 1 exit status
 configure:28587: $? = 1

 I found the following e-mail in the archives 
 http://www.mail-archive.com/r-devel@r-project.org/msg16853.html, but it has
 a different error, and the suggestion of switching out the BLAS later does
 not seem to apply to ATLAS which requires two files, I think.

 Any advice would be very appreciated.

 Thank you.

        [[alternative HTML version deleted]]

 __
 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] update.packages fails with directory not found

2010-05-14 Thread Mike Prager
Bill,

Thanks.  The problem is common but not consistent on update.  I'll
wait a few days for packages to be updated at CRAN, then try it.

Mike


On Wed, 12 May 2010 08:49:42 -0700, William Dunlap
wdun...@tibco.com wrote:

  If you have the time and can consistently reproduce
this problem you might try using Sysinternal's
Process Monitor program to capture the details of what
R and other programs were doing in that directory around
the time of the problem.
  http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

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


Re: [Rd] Restrict access to variables in parent environment

2010-05-14 Thread Jeff Ryan
This isn't like a local variable though, since any function above the
baseenv() in the search path will also not be found.

 f
function(a) { rnorm(b) }
environment: base

 f()
Error in f() : could not find function rnorm

Jeff

On Fri, May 14, 2010 at 9:20 AM, Hadley Wickham had...@rice.edu wrote:

  Hello All,
 
  By default, a reference of a variable in a function cause R to look
  for the variable in the parent environment if it is not available in
  the current environment (without generating any errors or warnings).
  I'm wondering if there is a way to revert this behaviors, such that it
  will not look for the parent environment and will generate an error if
  the variable is not available in the current environment. Is this
  tuning has to be done at the C level?

 Try this:
 b - 1
 f - function(a) {
  b
 }

 environment(f) - baseenv()
 f()

 Hadley

 --
 Assistant Professor / Dobelman Family Junior Chair
 Department of Statistics / Rice University
 http://had.co.nz/

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




-- 
Jeffrey Ryan
jeffrey.r...@insightalgo.com

ia: insight algorithmics
www.insightalgo.com

[[alternative HTML version deleted]]

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


Re: [Rd] Restrict access to variables in parent environment

2010-05-14 Thread Gabor Grothendieck
You can get around that by using this instead:

environment(f) - as.environment(2)

provided it is done after you have loaded all your packages.

On Fri, May 14, 2010 at 10:29 AM, Jeff Ryan jeff.a.r...@gmail.com wrote:
 This isn't like a local variable though, since any function above the
 baseenv() in the search path will also not be found.

 f
 function(a) { rnorm(b) }
 environment: base

 f()
 Error in f() : could not find function rnorm

 Jeff

 On Fri, May 14, 2010 at 9:20 AM, Hadley Wickham had...@rice.edu wrote:

  Hello All,
 
  By default, a reference of a variable in a function cause R to look
  for the variable in the parent environment if it is not available in
  the current environment (without generating any errors or warnings).
  I'm wondering if there is a way to revert this behaviors, such that it
  will not look for the parent environment and will generate an error if
  the variable is not available in the current environment. Is this
  tuning has to be done at the C level?

 Try this:
 b - 1
 f - function(a) {
  b
 }

 environment(f) - baseenv()
 f()

 Hadley

 --
 Assistant Professor / Dobelman Family Junior Chair
 Department of Statistics / Rice University
 http://had.co.nz/

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




 --
 Jeffrey Ryan
 jeffrey.r...@insightalgo.com

 ia: insight algorithmics
 www.insightalgo.com

        [[alternative HTML version deleted]]

 __
 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] Restrict access to variables in parent environment

2010-05-14 Thread Hadley Wickham
On Fri, May 14, 2010 at 10:10 AM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 You can get around that by using this instead:

 environment(f) - as.environment(2)

 provided it is done after you have loaded all your packages.

Another approach is to inspect function by function:

library(codetools)
findGlobals(f, F)$variables

Hadley
-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

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


Re: [Rd] Restrict access to variables in parent environment

2010-05-14 Thread Simon Urbanek

On May 14, 2010, at 10:29 AM, Jeff Ryan wrote:

 This isn't like a local variable though, since any function above the
 baseenv() in the search path will also not be found.
 

Yes, but that is a consequence of the request and hence intended. You can 
always either specify the full path to the function or assign locally any 
functions you'll need:

 f = function(a) stats::rnorm(b)
 environment(f) - baseenv()
 f()
Error in stats::rnorm(b) : object 'b' not found

 f = function(a) { rnorm=stats::rnorm; rnorm(b) }
 environment(f) - baseenv()
 f()
Error in rnorm(b) : object 'b' not found

Alternatively you can use any environment up the search path hoping that those 
won't define further variables.

But back to the original question -- if taken literally, it's quite useless 
since it corresponds to using emptyenv() instead of baseenv() which means that 
you can't do anything:

 local(1+1,emptyenv())
Error in eval(expr, envir, enclos) : could not find function +


So likely the only useful(?) distinction would be to allow function lookup the 
regular way but change only the variable lookup to not look beyond the current 
environment. That is stretching it, though...

Cheers,
Simon





 f
 function(a) { rnorm(b) }
 environment: base
 
 f()
 Error in f() : could not find function rnorm
 
 Jeff
 
 On Fri, May 14, 2010 at 9:20 AM, Hadley Wickham had...@rice.edu wrote:
 
 Hello All,
 
 By default, a reference of a variable in a function cause R to look
 for the variable in the parent environment if it is not available in
 the current environment (without generating any errors or warnings).
 I'm wondering if there is a way to revert this behaviors, such that it
 will not look for the parent environment and will generate an error if
 the variable is not available in the current environment. Is this
 tuning has to be done at the C level?
 
 Try this:
 b - 1
 f - function(a) {
 b
 }
 
 environment(f) - baseenv()
 f()
 
 Hadley
 
 --
 Assistant Professor / Dobelman Family Junior Chair
 Department of Statistics / Rice University
 http://had.co.nz/
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
 
 
 
 
 -- 
 Jeffrey Ryan
 jeffrey.r...@insightalgo.com
 
 ia: insight algorithmics
 www.insightalgo.com
 
   [[alternative HTML version deleted]]
 
 __
 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] Restrict access to variables in parent environment

2010-05-14 Thread thmsfuller...@gmail.com
On Fri, May 14, 2010 at 10:13 AM, Simon Urbanek
simon.urba...@r-project.org wrote:

 On May 14, 2010, at 10:29 AM, Jeff Ryan wrote:

 This isn't like a local variable though, since any function above the
 baseenv() in the search path will also not be found.


 Yes, but that is a consequence of the request and hence intended. You can 
 always either specify the full path to the function or assign locally any 
 functions you'll need:

 f = function(a) stats::rnorm(b)
 environment(f) - baseenv()
 f()
 Error in stats::rnorm(b) : object 'b' not found

 f = function(a) { rnorm=stats::rnorm; rnorm(b) }
 environment(f) - baseenv()
 f()
 Error in rnorm(b) : object 'b' not found

 Alternatively you can use any environment up the search path hoping that 
 those won't define further variables.

 But back to the original question -- if taken literally, it's quite useless 
 since it corresponds to using emptyenv() instead of baseenv() which means 
 that you can't do anything:

 local(1+1,emptyenv())
 Error in eval(expr, envir, enclos) : could not find function +


 So likely the only useful(?) distinction would be to allow function lookup 
 the regular way but change only the variable lookup to not look beyond the 
 current environment. That is stretching it, though...

I didn't think of the corner cases. I'm OK with stats::rnorm or
stats:::rnorm. But '{' is not recognized. How to make it be
recognized?

b=1
f=function() {
  stats::rnorm(b)
}
f()
#environment(f)=base()
environment(f)=emptyenv()
f()
 Cheers,
 Simon





 f
 function(a) { rnorm(b) }
 environment: base

 f()
 Error in f() : could not find function rnorm

 Jeff

 On Fri, May 14, 2010 at 9:20 AM, Hadley Wickham had...@rice.edu wrote:

 Hello All,

 By default, a reference of a variable in a function cause R to look
 for the variable in the parent environment if it is not available in
 the current environment (without generating any errors or warnings).
 I'm wondering if there is a way to revert this behaviors, such that it
 will not look for the parent environment and will generate an error if
 the variable is not available in the current environment. Is this
 tuning has to be done at the C level?

 Try this:
 b - 1
 f - function(a) {
 b
 }

 environment(f) - baseenv()
 f()

 Hadley

 --
 Assistant Professor / Dobelman Family Junior Chair
 Department of Statistics / Rice University
 http://had.co.nz/

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




 --
 Jeffrey Ryan
 jeffrey.r...@insightalgo.com

 ia: insight algorithmics
 www.insightalgo.com

       [[alternative HTML version deleted]]

 __
 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




-- 
Tom

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


Re: [Rd] results of pnorm as either NaN or Inf

2010-05-14 Thread efreeman
Thank you for your responses. 

I presented a minimal example of the issue, but I should have explained
that this came up in the context of maximizing a log likelihood function
(with optim). I certainly agree that there would be no good reason for a
human to evaluate the function pnorm(-x, log.p=TRUE) for large x. However,
I would suggest that one may want the function to return a value of -Inf
for large x, rather than issue an error or a warning, as I'm guessing your
alteration of the C code would do. Returning a value of -Inf would allow an
optimization routine (or a pre-optimization-routine grid search) to know
that it's going into (or is currently in) the wrong region. I can
definitely see the counterargument that someone using an optimization
routine should think about the function they are optimizing more carefully,
especially given that there could be numerical issues. I think I'm not the
right person to judge, both because I don't know the programming issues nor
much about numerical optimization, but I wanted to offer a possible
argument for returning -Inf in case it hasn't already been considered, and
others can evaluate the issue. (In general, my earlier purpose was just to
point out what I thought might be an inconsistency in case people wanted to
change it. I'm not concerned about it for my own usage at all, since I can
just adjust my own programs.)

Thank you, and to all, thank you for all of your work on R.

Eric

On Fri, 14 May 2010 11:50:09 +0100 (BST), Prof Brian Ripley
rip...@stats.ox.ac.uk wrote:
 The answer to pnorm(-x, log.p=TRUE) is of course about -0.5*x*x for 
 large x.  So trying to compute it for -1e108 is a bit silly, both on 
 your part and the C code used.  I've altered the C code not to attempt 
 it for x  1e170, which excludes the area where underflow occurs.
 
 On Fri, 14 May 2010, ted.hard...@manchester.ac.uk wrote:
 
 On 13-May-10 20:04:50, efree...@berkeley.edu wrote:
 I stumbled across this and I am wondering if this is unexpected
 behavior or if I am missing something.

 pnorm(-1.0e+307, log.p=TRUE)
 [1] -Inf
 pnorm(-1.0e+308, log.p=TRUE)
 [1] NaN
 Warning message:
 In pnorm(q, mean, sd, lower.tail, log.p) : NaNs produced
 pnorm(-1.0e+309, log.p=TRUE)
 [1] -Inf

 I don't know C and am not that skilled with R, so it would be hard
 for me to look into the code for pnorm. If I'm not just missing
 something, I thought it may be of interest.

 Details:
 I am using Mac OS X 10.5.8. I installed a precompiled binary version.
 Here is the output from sessionInfo(), requested in the posting guide:
 R version 2.11.0 (2010-04-22)
 i386-apple-darwin9.8.0

 locale:
 [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

 loaded via a namespace (and not attached):
 [1] tools_2.11.0

 Thank you very much,

 Eric Freeman
 UC Berkeley

 This is probably platform-independent. I get the same results with
 R on Linux. More to the point:

 You are clearly pushing the envelope here. First, have a look
 at what R makes of your inputs to pnorm():

  -1.0e+307
  # [1] -1e+307
  -1.0e+308
  # [1] -1e+308
  -1.0e+309
  # [1] -Inf


 So, somewhere beteen -1e+308 and -1.0e+309. the envelope burst!
 Given -1.0e+309, R returns -Inf (i.e. R can no longer represent
 this internally as a finite number).

 Now look at

  pnorm(-Inf,log.p=TRUE)
  # [1] -Inf

 So, R knows how to give the correct answer (an exact 0, or -Inf
 on the log scale) if you feed pnorm() with -Inf. So you're OK
 with -1e+N where N = 309.

 For smaller powers, e.g. -1e+(200:306), these give pnorm() much
 less than -1.0e+309, and presumably R's algorithm (which I haven't
 studied either ... ) returns 0 for pnorm(), as it should to the
 available internal accuracy.

 So, up to pnorm(-1.0e+307, log.p=TRUE) = -Inf. All is as it should be.
 However, at -1e+308, the envelope is about to burst, and something
 may occur within the algorithm which results in a NaN.

 So there is nothing anomalous about your results except at -1e+308,
 which is where R is at a critical point.

 That's how I see it, anway!
 Ted.

 
 E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
 Fax-to-email: +44 (0)870 094 0861
 Date: 14-May-10   Time: 00:01:27
 -- XFMail --

 __
 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] Compiling R with ATLAS

2010-05-14 Thread Avraham Adler
Thank you.

I am doing it this way as I really do not know much about Linux, and I would
not know how to re-compile Rblas and Rlapack with the ATLAS BLAS and tuned
LAPACK after I install the precompiled packages through synaptic. This way,
ostensibly, I should be compiling it from scratch so it should work. Also,
this way, I can compile R itself with optimization and -march=native to
squeeze out whatever speed I can from my machine.

Any advice would be very much appreciated, and thank you for pointing me to
the correct list.

--Avi


On Fri, May 14, 2010 at 9:00 AM, Douglas Bates ba...@stat.wisc.edu wrote:

 There is a Debian/Ubuntu specific list, r-sig-deb...@r-project.org,
 which I am cc:'ing on this reply, that is a better location for this
 discussion.

 It appears that you may be going about things the hard way.  There are
 Ubuntu packages for atlas and for R that can handle all of this for
 you.  Take a look at http://cran.r-project.org/bin/linux/ubuntu for
 information on how to get started.  It will probably be much easier to
 install the pre-compiled packages first and worry about compilation
 for customization later.

 On Thu, May 13, 2010 at 11:16 PM, Avraham Adler avraham.ad...@gmail.com
 wrote:
  Hello. I know almost nothing about Linux, so I apologize if the answer to
  this is obvious.
 
  I am trying to compile R with ATLAS (successfully compiled 3.9.24 on
 Ubuntu
  10.04 64 bit). I configured with:
 
  ./configure --enable-R-shlib --enable-BLAS-shlib
  --with-blas=-L/usr/local/atlas/lib -lf77blas -latlas
  --with-lapack=-L/usr/local/atlaslib -llapack -lcblas --with-x
 
  and I get this error (from config.log):
 
  configure:28566: checking for dgemm_ in -L/usr/local/atlas/lib -lf77blas
  -latlas
  configure:28587: gcc -std=gnu99 -o conftest -g -O2 -fpic
  -I/usr/local/include  -L/usr/local/lib64 conftest.c
 -L/usr/local/atlas/lib
  -lf77blas -latlas  -lgfortran -lm -ldl -lm  5
  conftest.c: In function 'main':
  conftest.c:193: warning: implicit declaration of function 'dgemm_'
  /usr/local/atlas/lib/libf77blas.so: undefined reference to
  `atl_f77wrap_zger2u_'
  /usr/local/atlas/lib/libf77blas.so: undefined reference to
  `atl_f77wrap_cger2c_'
  /usr/local/atlas/lib/libf77blas.so: undefined reference to
  `atl_f77wrap_zger2c_'
  /usr/local/atlas/lib/libf77blas.so: undefined reference to
  `atl_f77wrap_cger2u_'
  collect2: ld returned 1 exit status
  configure:28587: $? = 1
 
  I found the following e-mail in the archives 
  http://www.mail-archive.com/r-devel@r-project.org/msg16853.html, but it
 has
  a different error, and the suggestion of switching out the BLAS later
 does
  not seem to apply to ATLAS which requires two files, I think.
 
  Any advice would be very appreciated.
 
  Thank you.
 
 [[alternative HTML version deleted]]
 
  __
  R-devel@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-devel
 


[[alternative HTML version deleted]]

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


[Rd] Fwd: Compiling R with ATLAS

2010-05-14 Thread Avraham Adler
(Resent as plain text, sorry)

Thank you.

I am doing it this way as I really do not know much about Linux, and I
would not know how to re-compile Rblas and Rlapack with the ATLAS BLAS
and tuned LAPACK after I install the precompiled packages through
synaptic. This way, ostensibly, I should be compiling it from scratch
so it should work. Also, this way, I can compile R itself with
optimization and -march=native to squeeze out whatever speed I can
from my machine.

Any advice would be very much appreciated, and thank you for pointing
me to the correct list.

--Avi


On Fri, May 14, 2010 at 9:00 AM, Douglas Bates ba...@stat.wisc.edu wrote:

 There is a Debian/Ubuntu specific list, r-sig-deb...@r-project.org,
 which I am cc:'ing on this reply, that is a better location for this
 discussion.

 It appears that you may be going about things the hard way.  There are
 Ubuntu packages for atlas and for R that can handle all of this for
 you.  Take a look at http://cran.r-project.org/bin/linux/ubuntu for
 information on how to get started.  It will probably be much easier to
 install the pre-compiled packages first and worry about compilation
 for customization later.

 On Thu, May 13, 2010 at 11:16 PM, Avraham Adler avraham.ad...@gmail.com 
 wrote:
  Hello. I know almost nothing about Linux, so I apologize if the answer to
  this is obvious.
 
  I am trying to compile R with ATLAS (successfully compiled 3.9.24 on Ubuntu
  10.04 64 bit). I configured with:
 
  ./configure --enable-R-shlib --enable-BLAS-shlib
  --with-blas=-L/usr/local/atlas/lib -lf77blas -latlas
  --with-lapack=-L/usr/local/atlaslib -llapack -lcblas --with-x
 
  and I get this error (from config.log):
 
  configure:28566: checking for dgemm_ in -L/usr/local/atlas/lib -lf77blas
  -latlas
  configure:28587: gcc -std=gnu99 -o conftest -g -O2 -fpic
  -I/usr/local/include  -L/usr/local/lib64 conftest.c -L/usr/local/atlas/lib
  -lf77blas -latlas  -lgfortran -lm -ldl -lm  5
  conftest.c: In function 'main':
  conftest.c:193: warning: implicit declaration of function 'dgemm_'
  /usr/local/atlas/lib/libf77blas.so: undefined reference to
  `atl_f77wrap_zger2u_'
  /usr/local/atlas/lib/libf77blas.so: undefined reference to
  `atl_f77wrap_cger2c_'
  /usr/local/atlas/lib/libf77blas.so: undefined reference to
  `atl_f77wrap_zger2c_'
  /usr/local/atlas/lib/libf77blas.so: undefined reference to
  `atl_f77wrap_cger2u_'
  collect2: ld returned 1 exit status
  configure:28587: $? = 1
 
  I found the following e-mail in the archives 
  http://www.mail-archive.com/r-devel@r-project.org/msg16853.html, but it has
  a different error, and the suggestion of switching out the BLAS later does
  not seem to apply to ATLAS which requires two files, I think.
 
  Any advice would be very appreciated.
 
  Thank you.
 
         [[alternative HTML version deleted]]
 
  __
  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] [R] Subscripting a matrix-like object

2010-05-14 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Jeffrey J. Hallman
 Sent: Friday, May 14, 2010 9:17 AM
 To: r-h...@stat.math.ethz.ch
 Subject: Re: [R] Subscripting a matrix-like object
 
 jhall...@frb.gov writes:
 
 Answering my own question here, so you can ignore this unless you are
 really interested in some fairly obscure stuff.  It turns out 
 that this works:
 
 singleIndex - missing(j)  (length(sys.call()) == 
 length(match.call()))
 
 since sys.call() has an element for the empty argument created by
 
 x[i,] - value
 
 and match.call() does not.  But it is pretty obscure.

I was curious about this because in the version of R
I'm using (2.11.0, 2010-04-22), nargs() does distinguish
between x[i] and x[i,].  E.g., with the following
replacement function
  `[-.foo` - function (x, i, j, ..., value)
  {
  cat([-.foo: nargs=, nargs(), \n, sep = )
  cat( sys.call()=, deparse(sys.call()), \n, sep = )
  cat( missing(i)=, missing(i), \n, sep = )
  cat( missing(j)=, missing(j), \n, sep = )
  x
  }
I get
   fooObject - structure(1:4, class=foo)
   fooObject[1] - 12
  [-.foo: nargs=3
   sys.call()=`[-.foo`(`*tmp*`, 1, value = 12)
   missing(i)=FALSE
   missing(j)=TRUE
   fooObject[1,] - 12
  [-.foo: nargs=4
   sys.call()=`[-.foo`(`*tmp*`, 1, , value = 12)
   missing(i)=FALSE
   missing(j)=TRUE
   fooObject[,1] - 12
  [-.foo: nargs=4
   sys.call()=`[-.foo`(`*tmp*`, , 1, value = 12)
   missing(i)=TRUE
   missing(j)=FALSE
  
Is this a bug in nargs() that was recently fixed?

sys.call() and especially match.call() are
fairly expensive functions to call so it would be nice
to be able to avoid them.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

 
 Jeff
 
  I have an S3 class called tis (Time Indexed Series) which 
 may or may
  not have multiple columns.  I have a function [-.tis that I've
  reproduced below.  
 
  My question is this: inside of [-.tis, how can I 
 distinguish between
  calls of the form 
 
  x[i] - someValue
 
  and
 
  x[i,] - someValue ?
 
  In either case, nargs() is 3, and looking at the values 
 from sys.call()
  and match.call() I could not tell them apart.  Am I missing 
 something?
 
 
  [-.tis - function(x, i, j, ..., value){
tif - tif(x)
xStart - start(x)
x - stripTis(x)
if(missing(i)){
  if(missing(j)) x[]   - value
  else   x[,j] - value
}
else {
  i - i[!is.na(i)]
  if(is.numeric(i)){
if(!is.ti(i)  couldBeTi(i, tif = tif))
  i - asTi(i)
if(is.ti(i)){
  i - i + 1 - xStart
  if(any(i  1)){
newRows - 1 - min(i)
xStart - xStart - newRows
if(is.null(m - ncol(x)))  m - 1
i - i + newRows
if(is.matrix(x))
  x - rbind(matrix(NA, newRows, m), x)
else
  x - c(rep(NA, newRows), x)
  }
}
  }
  else if(!is.logical(i)) stop(non-numeric, non-logical 
 row index)
 if(is.matrix(x)){
if(any(i  nrow(x))){
  newRows - max(i) - nrow(x)
  x - rbind(x, matrix(NA, newRows, ncol(x)))
}
if(missing(j)){
  if(is.matrix(i))  x[i] - value
  else {
if(is.logical(i))
  x[i,] - rep(value, length = sum(i)*ncol(x))
else
  x[i,] - rep(value, length = length(i)*ncol(x))
  }
}
else x[i,j] - value
  }
  else x[i] - value
}
start(x) - xStart
class(x) - c(tis, oldClass(x))
x
  }
 
 
 -- 
 Jeff
 
 __
 r-h...@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

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


[Rd] S4 default/missing args

2010-05-14 Thread Paul Gilbert
I am trying to understand the missing vs default value for an argument
to an S4 method. (I'm not sure if this is a bug or my confusion.) In S3
I can specify a default value for an argument and then both check if the
argument was missing in the call, and use it because it takes on the
default value. I do not seem to be able to do that in S4 as shown by
this simplified example:

 

setGeneric(TSdoc,

   def= function(x, con, ...) standardGeneric(TSdoc))

 

setMethod(TSdoc,   signature(x=character, con=missing),

definition= function(x, con=getOption(TSconnection), ...){

if(is.null(con))

   stop(con should be specified or set with
options(TSconnection=con).)

else return('ok')} )

 

Then when I try

   TSdoc(B103)

In my original problem I got

   Error in is.null(con) : 'con' is missing

And in the simplified example I get

  Error in TSdoc(B103) :

element 1 is empty;

 the part of the args list of 'is.null' being evaluated was:

 (con)

 

I'm not sure why there is a difference, but the implication is the same
in both, the default   

 getOption(TSconnection)

NULL

 

Is not getting through to the is.null().  I can fix (or work around)
this with

 

setMethod(TSdoc,   signature(x=character, con=missing),

   definition= function(x, con,  ...){

   if(is.null(con - getOption(TSconnection)))

  stop(con should be specified or set with
options(TSconnection=con).)

   else return('ok') } )

 

TSdoc(B103)

Error in TSdoc(B103) :

  con should be specified or set with options(TSconnection=con).

 

So my question is, is this a bug or do I have to adjust my programming
style for the way missing/default arguments are handled in S4?

 

Paul Gilbert



La version française suit le texte anglais.



This email may contain privileged and/or confidential information, and the Bank 
of
Canada does not waive any related rights. Any distribution, use, or copying of 
this
email or the information it contains by other than the intended recipient is
unauthorized. If you received this email in error please delete it immediately 
from
your system and notify the sender promptly by email that you have done so. 



Le présent courriel peut contenir de l'information privilégiée ou 
confidentielle.
La Banque du Canada ne renonce pas aux droits qui s'y rapportent. Toute 
diffusion,
utilisation ou copie de ce courriel ou des renseignements qu'il contient par une
personne autre que le ou les destinataires désignés est interdite. Si vous 
recevez
ce courriel par erreur, veuillez le supprimer immédiatement et envoyer sans 
délai à
l'expéditeur un message électronique pour l'aviser que vous avez éliminé de 
votre
ordinateur toute copie du courriel reçu.

[[alternative HTML version deleted]]

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


Re: [Rd] Restrict access to variables in parent environment

2010-05-14 Thread Simon Urbanek

On May 14, 2010, at 11:33 AM, thmsfuller...@gmail.com wrote:

 On Fri, May 14, 2010 at 10:13 AM, Simon Urbanek
 simon.urba...@r-project.org wrote:
 
 On May 14, 2010, at 10:29 AM, Jeff Ryan wrote:
 
 This isn't like a local variable though, since any function above the
 baseenv() in the search path will also not be found.
 
 
 Yes, but that is a consequence of the request and hence intended. You can 
 always either specify the full path to the function or assign locally any 
 functions you'll need:
 
 f = function(a) stats::rnorm(b)
 environment(f) - baseenv()
 f()
 Error in stats::rnorm(b) : object 'b' not found
 
 f = function(a) { rnorm=stats::rnorm; rnorm(b) }
 environment(f) - baseenv()
 f()
 Error in rnorm(b) : object 'b' not found
 
 Alternatively you can use any environment up the search path hoping that 
 those won't define further variables.
 
 But back to the original question -- if taken literally, it's quite useless 
 since it corresponds to using emptyenv() instead of baseenv() which means 
 that you can't do anything:
 
 local(1+1,emptyenv())
 Error in eval(expr, envir, enclos) : could not find function +
 
 
 So likely the only useful(?) distinction would be to allow function lookup 
 the regular way but change only the variable lookup to not look beyond the 
 current environment. That is stretching it, though...
 
 I didn't think of the corner cases. I'm OK with stats::rnorm or
 stats:::rnorm. But '{' is not recognized. How to make it be
 recognized?
 

You either include base or (if you don't want to) you have to create functions 
for everything you'll need including `{` so for example:

 f=function(a) base::rnorm(b)
 environment(f)=mini.env
 mini.env=new.env(parent=emptyenv())
 import=c({,::,+,rnorm) # add all functions you want to use
 for (fn in import) mini.env[[fn]] = get(fn)

 f=function(a) rnorm(a+b)
 environment(f)=mini.env

 f(1)
Error in rnorm(a + b) : object 'b' not found


Cheers,
Simon



 b=1
 f=function() {
  stats::rnorm(b)
 }
 f()
 #environment(f)=base()
 environment(f)=emptyenv()
 f()
 Cheers,
 Simon
 
 
 
 
 
 f
 function(a) { rnorm(b) }
 environment: base
 
 f()
 Error in f() : could not find function rnorm
 
 Jeff
 
 On Fri, May 14, 2010 at 9:20 AM, Hadley Wickham had...@rice.edu wrote:
 
 Hello All,
 
 By default, a reference of a variable in a function cause R to look
 for the variable in the parent environment if it is not available in
 the current environment (without generating any errors or warnings).
 I'm wondering if there is a way to revert this behaviors, such that it
 will not look for the parent environment and will generate an error if
 the variable is not available in the current environment. Is this
 tuning has to be done at the C level?
 
 Try this:
 b - 1
 f - function(a) {
 b
 }
 
 environment(f) - baseenv()
 f()
 
 Hadley
 
 --
 Assistant Professor / Dobelman Family Junior Chair
 Department of Statistics / Rice University
 http://had.co.nz/
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
 
 
 
 
 --
 Jeffrey Ryan
 jeffrey.r...@insightalgo.com
 
 ia: insight algorithmics
 www.insightalgo.com
 
   [[alternative HTML version deleted]]
 
 __
 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
 
 
 
 
 -- 
 Tom
 
 

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


Re: [Rd] Restrict access to variables in parent environment

2010-05-14 Thread Duncan Murdoch

On 14/05/2010 10:14 AM, thmsfuller...@gmail.com wrote:

Hello All,

By default, a reference of a variable in a function cause R to look
for the variable in the parent environment if it is not available in
the current environment (without generating any errors or warnings).
I'm wondering if there is a way to revert this behaviors, such that it
will not look for the parent environment and will generate an error if
the variable is not available in the current environment. Is this
tuning has to be done at the C level?


You could do that by setting the environment of the function to 
emptyenv(), but it will not be pretty.  Remember that everything in R is 
an object, so you won't have access to the base level objects like +, or 
mean, or any other function.


Duncan Murdoch

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


[Rd] The parsing of '{' and a function that equal to '{'

2010-05-14 Thread thmsfuller...@gmail.com
Hello All,

I tried the sample code from the help. Although '{' is assigned to
'do', the call syntaxes for 'do' and '{' are not the same ('do' has
','s, but '{' has line breaks). I guess there is a difference in
parsing the code block of 'do' and the code block of '{'. Could you
please let me know some internal details so that I can understand the
differences?

 do=get({)
 do(x - 3, y - 2*x-3, 6-x-y)
[1] 0
 {
+   x - 3
+   y - 2*x-3
+   6-x-y
+ }
[1] 0
 x
[1] 3
 y
[1] 3


-- 
Tom

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


Re: [Rd] The parsing of '{' and a function that equal to '{'

2010-05-14 Thread Simon Urbanek

On May 14, 2010, at 3:38 PM, thmsfuller...@gmail.com wrote:

 Hello All,
 
 I tried the sample code from the help. Although '{' is assigned to
 'do', the call syntaxes for 'do' and '{' are not the same ('do' has
 ','s, but '{' has line breaks). I guess there is a difference in
 parsing the code block of 'do' and the code block of '{'. Could you
 please let me know some internal details so that I can understand the
 differences?
 

{ foo; bar } 

gets parsed into

`{`(foo, bar)

as you illustrated below. You can see that in the resulting expression:

 e=parse(text={foo; bar})[[1]]
 attributes(e)=NULL ## remove the original sources
 e
{
foo
bar
}
 .Internal(inspect(e))
@102182578 06 LANGSXP g0c0 [NAM(2)] 
  @10082c9b8 01 SYMSXP g0c0 [MARK,gp=0x4000] {
  @100edfaa0 01 SYMSXP g0c0 [] foo
  @100edfc98 01 SYMSXP g0c0 [] bar


and in case you are not familiar with the internal representation:

 quote(`{`(foo,bar))
{
foo
bar
}
 .Internal(inspect(quote(`{`(foo,bar
@100f99868 06 LANGSXP g0c0 [] 
  @10082c9b8 01 SYMSXP g0c0 [MARK,gp=0x4000] {
  @100edfaa0 01 SYMSXP g0c0 [] foo
  @100edfc98 01 SYMSXP g0c0 [] bar

Cheers,
Simon




 do=get({)
 do(x - 3, y - 2*x-3, 6-x-y)
 [1] 0
 {
 +   x - 3
 +   y - 2*x-3
 +   6-x-y
 + }
 [1] 0
 x
 [1] 3
 y
 [1] 3
 
 
 -- 
 Tom
 
 __
 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] where is libRmath.a libRmath.so

2010-05-14 Thread Dave Lubbers

R 2.7.2 -   the manual says 
configure
make

Which is what I did.  So I did read the manual and followed the directions. 
The manual is too terse to get me there.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/where-is-libRmath-a-libRmath-so-tp2216048p2217224.html
Sent from the R devel mailing list archive at Nabble.com.

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


Re: [Rd] S4 default/missing args

2010-05-14 Thread John Chambers

From the documentation for setMethod():

Method definitions can have default expressions for arguments, but a 
current limitation is that the generic function must have some default 
expression for the same argument in order for the method's defaults to 
be used. 


(It would be nice to fix this, but would require some significant change 
to how methods are dispatched, with some possible inefficiencies.  The 
issue is that R processes formal arguments differently if there is no 
default expression.  Volunteers among the R hackers welcome, though.)


Meanwhile, if you own the generic function just give it a default, say:

setGeneric(TSdoc,
 def= function(x, con = stop(Sorry, no generic default), ...) 
standardGeneric(TSdoc))


John


On 5/14/10 9:50 AM, Paul Gilbert wrote:

I am trying to understand the missing vs default value for an argument
to an S4 method. (I'm not sure if this is a bug or my confusion.) In S3
I can specify a default value for an argument and then both check if the
argument was missing in the call, and use it because it takes on the
default value. I do not seem to be able to do that in S4 as shown by
this simplified example:



setGeneric(TSdoc,

def= function(x, con, ...) standardGeneric(TSdoc))



setMethod(TSdoc,   signature(x=character, con=missing),

 definition= function(x, con=getOption(TSconnection), ...){

 if(is.null(con))

stop(con should be specified or set with
options(TSconnection=con).)

 else return('ok')} )



Then when I try

TSdoc(B103)

In my original problem I got

Error in is.null(con) : 'con' is missing

And in the simplified example I get

   Error in TSdoc(B103) :

 element 1 is empty;

  the part of the args list of 'is.null' being evaluated was:

  (con)



I'm not sure why there is a difference, but the implication is the same
in both, the default


getOption(TSconnection)


NULL



Is not getting through to the is.null().  I can fix (or work around)
this with



setMethod(TSdoc,   signature(x=character, con=missing),

definition= function(x, con,  ...){

if(is.null(con- getOption(TSconnection)))

   stop(con should be specified or set with
options(TSconnection=con).)

else return('ok') } )



TSdoc(B103)

Error in TSdoc(B103) :

   con should be specified or set with options(TSconnection=con).



So my question is, is this a bug or do I have to adjust my programming
style for the way missing/default arguments are handled in S4?



Paul Gilbert



La version française suit le texte anglais.



This email may contain privileged and/or confidential information, and the Bank 
of
Canada does not waive any related rights. Any distribution, use, or copying of 
this
email or the information it contains by other than the intended recipient is
unauthorized. If you received this email in error please delete it immediately 
from
your system and notify the sender promptly by email that you have done so.



Le présent courriel peut contenir de l'information privilégiée ou 
confidentielle.
La Banque du Canada ne renonce pas aux droits qui s'y rapportent. Toute 
diffusion,
utilisation ou copie de ce courriel ou des renseignements qu'il contient par une
personne autre que le ou les destinataires désignés est interdite. Si vous 
recevez
ce courriel par erreur, veuillez le supprimer immédiatement et envoyer sans 
délai Ã
l'expéditeur un message électronique pour l'aviser que vous avez éliminé de 
votre
ordinateur toute copie du courriel reçu.

[[alternative HTML version deleted]]




__
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] where is libRmath.a libRmath.so

2010-05-14 Thread Simon Urbanek

On May 14, 2010, at 4:52 PM, Dave Lubbers wrote:

 
 R 2.7.2 -   the manual says 
 configure
 make
 
 Which is what I did.  So I did read the manual and followed the directions. 
 The manual is too terse to get me there.

cd src/nmath/standalone
make

Cheers,
Simon


 -- 
 View this message in context: 
 http://r.789695.n4.nabble.com/where-is-libRmath-a-libRmath-so-tp2216048p2217224.html
 Sent from the R devel mailing list archive at Nabble.com.
 
 __
 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] where is libRmath.a libRmath.so

2010-05-14 Thread Dirk Eddelbuettel

On 14 May 2010 at 13:52, Dave Lubbers wrote:
| 
| R 2.7.2 -   the manual says 
| configure
| make
| 
| Which is what I did.  So I did read the manual and followed the directions. 
| The manual is too terse to get me there.

On Debian / Ubuntu, you can also do

   sudo apt-get install r-mathlib

to install this library.

-- 
  Regards, Dirk

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


Re: [Rd] where is libRmath.a libRmath.so

2010-05-14 Thread Duncan Murdoch

On 14/05/2010 4:52 PM, Dave Lubbers wrote:
R 2.7.2 -   the manual says 
configure

make

Which is what I did.  So I did read the manual and followed the directions. 
The manual is too terse to get me there.
  


You used the wrong tense.  In referring to R 2.7.2, only past tenses are 
grammatically correct.


If you want to say the manual *is* too terse, then you need to install 
R 2.11.0.


Duncan Murdoch

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