[Rd] tilde expansion with install.packages

2007-04-05 Thread Roger D. Peng
I've noticed recently that 'update.packages' and 'install.packages' seem to not 
do tilde expansion anymore, i.e. when I run


update.packages("~/R-local/lib")

on R-alpha (r41043) I get the message

/home/rpeng/install/R-alpha/lib64/R/bin/INSTALL: line 304: cd: ~/R-local/lib: No 
such file or directory


and the package is subsequently installed in the current working directory.

The attached patch solves the problem for me.

-roger
--
Roger D. Peng  |  http://www.biostat.jhsph.edu/~rpeng/
Index: src/scripts/INSTALL.in
===
--- src/scripts/INSTALL.in  (revision 41043)
+++ src/scripts/INSTALL.in  (working copy)
@@ -294,6 +294,7 @@
   shift
 done
 
+lib=`tilde_expand "${lib}"`
 if test -z "${lib}"; then
   lib=`echo "cat('~~~', .libPaths()[1], sep = '')" | \
 R_DEFAULT_PACKAGES=NULL "${R_EXE}" --no-save --slave | \
@@ -332,7 +333,6 @@
   exit 1
 fi
 
-lib=`tilde_expand "${lib}"`
 if (test -d "${lib}" && test -w "${lib}") || \
 ${MKDIR_P} "${lib}" 2> /dev/null; then
   lib=`cd "${lib}" && ${GETWD}`
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] 'R CMD check' fails when suggested package is not available

2007-04-05 Thread Jari Oksanen
On Wed, 2007-04-04 at 17:05 -0700, Herve Pages wrote:
> Hi there,
> 
> I was wondering why I get the following error message:
> 
>   * checking package dependencies ... ERROR
>   Packages required but not available:
> Rmpi
> 
> when I run 'R CMD check' on a package that _suggests_ Rmpi?
> Why isn't it OK to not have all the suggested packages installed?
> 
Hi there too,

This has been discussed before:
http://tolstoy.newcastle.edu.au/R/devel/05/09/2326.html

Then the Core decided to maintain the Mafia style suggestion ("that you
can't refuse"), but later seems to have introduced a new field
"enhances" which to me looks like a suggestion in the meaning of the
word I know: a suggestion that you can refuse.

I think that the R-ext description is somewhat confusing and misleading
for fields "Requires", "Suggests", "Enhances". The R extension manual
"suggests" different situations where the author of the manual thinks
that other people would like to use these fields. However, the manual
does not clearly say what are the practical and real consequences of
selecting a certain entry. It seems that "Requires" means that a package
is always required, "Suggests" means that the package is required in
check (with a threat of error), but only suggested for normal use, and
"Enhances" means that the package only is suggested. It does not matter
whether the package really "enhances" anything, but this is the meaning
of the word in behaviouristic sense. 

cheers, jari oksanen

> Maybe one of the 3 following behaviours would be more appropriate:
> 
>   a) Having the error saying something like:
> 
> Package suggested but not available:
>   Rmpi
> 
>   b) Make this a warning instead of an error.
> 
>   c) Don't do anything at all for suggested packages.
> 
> This issue showed up today while I was checking a new Bioconductor package:
> the package suggests Rmpi but the vignette and the examples don't use it. If 
> I remove
> Rmpi from the Suggests field then 'R CMD check' runs all the examples and 
> re-create
> the vignette with no problem. Most users will not have Rmpi on their machine 
> neither
> will they be interested in getting into the trouble of installing it.
> The package I was checking suggests Rmpi only because it contains 1 function 
> that tries
> to use it if it's installed but will work perfectly fine otherwise.
> In this case it seems reasonable to have Rmpi in the Suggests field but this 
> will
> make 'R CMD check' to fail which is problematic in the context of automated 
> builds :-/
> If 'R CMD check' can't be a little bit more relaxed about this, then I guess 
> we will
> need to remove Rmpi from the Suggests field, but then 'R CMD check' will 
> complain that:
> 
>   * checking for unstated dependencies in R code ... WARNING
>   'library' or 'require' calls not declared from:
> Rmpi

-- 
"Object-oriented programming is an exceptionally bad idea that could
only have been invented in California." -- Edsger Dijkstra

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


Re: [Rd] tilde expansion with install.packages

2007-04-05 Thread Prof Brian Ripley
Looks right, and now committed, thanks.

On Wed, 4 Apr 2007, Roger D. Peng wrote:

> I've noticed recently that 'update.packages' and 'install.packages' seem to 
> not do tilde expansion anymore, i.e. when I run
>
> update.packages("~/R-local/lib")
>
> on R-alpha (r41043) I get the message
>
> /home/rpeng/install/R-alpha/lib64/R/bin/INSTALL: line 304: cd: 
> ~/R-local/lib: No such file or directory
>
> and the package is subsequently installed in the current working directory.
>
> The attached patch solves the problem for me.
>
> -roger
>

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


[Rd] issue with pdf(paper="a4") in 2.5.0 alpha

2007-04-05 Thread J.Oosting
In the latest windows binary (2007-04-03 r41023) pdf() with an argument 
paper="a4" gives an error, this was still ok in (2007-03-18 r40854)

Jan Oosting
 
> pdf("test.pdf",paper="a4")
Error in pdf("test.pdf", paper = "a4") : invalid paper type 'a4' (pdf)
> sessionInfo()
R version 2.5.0 alpha (2007-04-03 r41023) 
i386-pc-mingw32 
locale:
LC_COLLATE=Dutch_Netherlands.1252;LC_CTYPE=Dutch_Netherlands.1252;LC_MONETARY=Dutch_Netherlands.1252;LC_NUMERIC=C;LC_TIME=Dutch_Netherlands.1252
attached base packages:
[1] "stats" "graphics"  "grDevices" "utils" "datasets"  "methods"  
[7] "base" 
> 

 

 



[[alternative HTML version deleted]]

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


[Rd] StructTS

2007-04-05 Thread Roy Mendelssohn
I apologize in advance if I picked the wrong list to post this to.  I  
have made an effort to find the answers to these questions on CRAN,  
but if they are there, I couldn't find them, and I was going to email  
the developer of StructTS directly but could not find who that is.

I have 2 interrelated questions about StructTS

1.  Where can I obtain the source code for StructTS if I wanted to  
produce a similar function with an extended capability?

2.  Would the person who developed StructTS have any interest in  
adding the ability to include an AR term and/or a stochastic cycle?

Thanks in advance,

-Roy M.



**
"The contents of this message do not reflect any position of the U.S.  
Government or NOAA."
**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division 
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097

e-mail: [EMAIL PROTECTED] (Note new e-mail address)
voice: (831)-648-9029
fax: (831)-648-8440
www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."

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


[Rd] is.loaded() and dyn.load()

2007-04-05 Thread Simone Giannerini

Dear all,

I am puzzled at the behaviour of is.loaded() when a dyn.load() call to a a
FORTRAN shared library is included in a file to be sourced.
A reproducible example is the following:

1. the attached fortran subroutine try_it.f90 performs a summation of the
elements of a REAL*8 vector
compile with

gfortran try_it.f90 -shared -s -otry_it.dll

2. create a file to be sourced (see the attached try_it.R) containing the
following commands:

BEGIN try_it.R 
dyn.load("try_it.dll");


try.it <- function(X){
   N <- length(X);
   S <- .Fortran("try_it_",as.double(X),as.integer(N),S=as.double(0))$S
   return(S)
}
END try_it.R 


3. Switch to R


source("try_it.R")
try.it(1:10)

Error in .Fortran("try_it_", as.double(X), as.integer(N), S = as.double(0))
:
   Fortran symbol name "try_it_" not in load table

is.loaded("try_it_")

[1] TRUE

try.it(1:10)

[1] 55



it looks like is.loaded() triggers the loading, inserting
is.loaded("try_it_")in
the file try_it.R does the trick but
is this behaviour expected?

Thank you,

Regards

Simone


R.version

  _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  4.1
year   2006
month  12
day18
svn rev40228
language   R
version.string R version 2.4.1 (2006-12-18)
--
__

Simone Giannerini
Dipartimento di Scienze Statistiche "Paolo Fortunati"
Universita' di Bologna
Via delle belle arti 41 - 40126  Bologna,  ITALY
Tel: +39 051 2098262  Fax: +39 051 232153
__
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] is.loaded() and dyn.load()

2007-04-05 Thread Prof Brian Ripley
Did you read the comments under ?.Fortran about this?  What you are doing 
is quite explicitly said not to be supported.

gfortran is not a supported Fortran compiler for R for Windows 2.4.1.
It behaves differently from the supported g77.
The behaviour is adapted to the compiler used when configure is used, and 
on Windows that is what the maintainers used, not you are using.  If you 
follow the advice not to use underscores in names you are much less likely 
to confuse yourself and produce portable code.

On Thu, 5 Apr 2007, Simone Giannerini wrote:

> Dear all,
>
> I am puzzled at the behaviour of is.loaded() when a dyn.load() call to a a
> FORTRAN shared library is included in a file to be sourced.
> A reproducible example is the following:
>
> 1. the attached fortran subroutine try_it.f90 performs a summation of the
> elements of a REAL*8 vector
> compile with
>
> gfortran try_it.f90 -shared -s -otry_it.dll
>
> 2. create a file to be sourced (see the attached try_it.R) containing the
> following commands:
>
> BEGIN try_it.R 
> dyn.load("try_it.dll");
>
>
> try.it <- function(X){
>   N <- length(X);
>   S <- .Fortran("try_it_",as.double(X),as.integer(N),S=as.double(0))$S
>   return(S)
> }
> END try_it.R 
>
>
> 3. Switch to R
>
>> source("try_it.R")
>> try.it(1:10)
> Error in .Fortran("try_it_", as.double(X), as.integer(N), S = as.double(0))
> :
>   Fortran symbol name "try_it_" not in load table
>> is.loaded("try_it_")
> [1] TRUE
>> try.it(1:10)
> [1] 55
>> 
> it looks like is.loaded() triggers the loading, inserting
> is.loaded("try_it_")in
> the file try_it.R does the trick but
> is this behaviour expected?
>
> Thank you,
>
> Regards
>
> Simone
>
>> R.version
>  _
> platform   i386-pc-mingw32
> arch   i386
> os mingw32
> system i386, mingw32
> status
> major  2
> minor  4.1
> year   2006
> month  12
> day18
> svn rev40228
> language   R
> version.string R version 2.4.1 (2006-12-18)
>

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


[Rd] Implementation of pretty

2007-04-05 Thread hadley wickham
Hi,

I'm trying to track down any references for the implementation of
pretty (or grid.pretty) in R.  Is it original work?

Thanks,

Hadley

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


Re: [Rd] Implementation of pretty

2007-04-05 Thread Martin Maechler
> "hadley" == hadley wickham <[EMAIL PROTECTED]>
> on Thu, 5 Apr 2007 10:43:41 -0500 writes:

hadley> Hi, I'm trying to track down any references for the
hadley> implementation of pretty (or grid.pretty) in R.  Is
hadley> it original work?

Much of it is.  The original version, say R version 0.01, may
have been based on some reference, but we have added quite a few extra tweaks,
where in my case I sat down with a piece of paper, considered
and transformed some inequalities and also did computer
experiments additionally. 
I've even started to make more coherent notes eventually, but
not electronically, and hence no tech.report /  publication / ...

 { Did you really want to know this :-) }

Regards,
Martin

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


[Rd] some SPSS 15 files wont open in R 2.4.0

2007-04-05 Thread Sam Smith

Trying to open some SPSS .sav files (saved with SPSS 15) gives the following:


read.spss('/data/big/unzipped_ukda/seh3767/3767SPSS_570D6A086C9A1B0636F13255F25A58C1/prgrp95.sav')
Error in 
read.spss("/data/big/unzipped_ukda/seh3767/3767SPSS_570D6A086C9A1B0636F13255F25A58C1/prgrp95.sav"):
 
error reading system-file header
In addition: Warning message:

/data/big/unzipped_ukda/seh3767/3767SPSS_570D6A086C9A1B0636F13255F25A58C1/prgrp95.sav:
File-indicated character representation code (Unknown) is not ASCII

Some are fine in R, some are not.


The file opens in SPSS, and googling the error message gives
this mail about PSPP
 
http://www.nabble.com/problem-loading-SPSS-15.0-save-files-t2726500.html
which includes a diff for the PSPP code which opens R files
and throws that exact error message back.

R documentation says that it uses some code based on PSPP,
I can't see it in the R distribution?. Does anyone with more
clue than I know whether the above is likely to fix it, and
where I should be looking for the code to change?


Alternatively, has anyone got any ideas on opening these files?





Thanks

Sam

-- 
[EMAIL PROTECTED] ; www.ccsr.ac.uk

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


Re: [Rd] Problem with S4 inheritance: unexpected re-initialization?

2007-04-05 Thread cstrato
Dear Herve

Thank you once again for taking your time, I appreciate it very much.
I followed your advice and kept only the minimum code, which I believe
is necessary. I have even removed SubClassA, so the inheritance tree is:

   BaseClass <- SubClassB <- SubSubClassB1
 <- SubClassB <- SubSubClassB2

The source code is shown below and the examples are:
 > subsubB1 <- new("SubSubClassB1", filename="MyFileNameB1", 
nameB="MyNameB")
 > subsubB2 <- new("SubSubClassB2", filename="MyFileNameB2", 
nameB="MyNameB")

Although SubSubClassB1 and SubSubClassB2 differ only slightly, the results
for "subsubB1" are correct, while "subsubB2" gives a wrong result, see:
 > subsubB2 <- new("SubSubClassB2", filename="MyFileNameB2", 
nameB="MyNameB")
 > subsubB2
An object of class "SubSubClassB2"
Slot "nameB2":
[1] "MyNameB"

Slot "nameB":
[1] ""

Slot "filename":
[1] "MyFileNameB2"

Only, when adding "nameB2="MyNameB2", I get the correct result, see:
 > subsubB2 <- new("SubSubClassB2", filename="MyFileNameB2", 
nameB="MyNameB",nameB2="MyNameB2")
 > subsubB2
An object of class "SubSubClassB2"
Slot "nameB2":
[1] "MyNameB2"

Slot "nameB":
[1] "MyNameB"

Slot "filename":
[1] "MyFileNameB2"

It is not clear to me why omitting "nameB2" results in the wrong assignemt
of the value for "nameB" to "nameB2"?

When running both examples, the sequence of initialization and validation
method is also completely different.
For "SubSubClassB1" I get the correct and expected sequence of events:
 > subsubB1 <- new("SubSubClassB1", filename="MyFileNameB1", 
nameB="MyNameB")
--initialize:SubSubClassB1
--initialize:SubClassB
--initialize:BaseClass
--setValidity:BaseClass
--setValidity:SubClassB
--setValidity:SubSubClassB1

In contrast, for "SubSubClassB2" I get the following sequence of events:
 > subsubB2 <- new("SubSubClassB2", filename="MyFileNameB2", 
nameB="MyNameB")
--initialize:SubSubClassB2
--initialize:SubClassB
--initialize:BaseClass
--setValidity:BaseClass
--initialize:SubClassB
--initialize:BaseClass
--setValidity:BaseClass
--setValidity:SubClassB
--setValidity:SubClassB
--initialize:SubClassB
--initialize:BaseClass
--setValidity:BaseClass
--setValidity:SubClassB
--setValidity:SubSubClassB2

Furthermore, the slot "filename" is first initialized correctly to
"filename=MyFileNameB2", but then it is twice initialized incorrectly
to "filename=ERROR_FileName", indicating that it may not have been
initialized at all. I do not understand this behavior, why is this so?

I really hope that this time the code below is acceptable to you.
Thank you for your help.
Best regards
Christian

# - - - - - - - - - - - - - - - - BEGIN - - - - - - - - - - - - - - - - 
- - - -
setClass("BaseClass",
   representation(filename = "character", "VIRTUAL"),
   prototype(filename = "DefaultFileName")
)

setClass("SubClassB",
   representation(nameB = "character"),
   contains=c("BaseClass"),
   prototype(nameB = "NameB")
)

setClass("SubSubClassB1",
   contains=c("SubClassB")
)

setClass("SubSubClassB2",
   representation(nameB2 = "character"),
   contains=c("SubClassB"),
   prototype(nameB2 = "NameB2")
)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
setMethod("initialize", "BaseClass",
   function(.Object, filename="",  ...) {
  cat("--initialize:BaseClass--\n")
  cat("BaseClass:init:class(.Object) = ", class(.Object), "\n", sep="")
  if (filename == "" || nchar(filename) == 0) filename <- 
"ERROR_FileName"
  cat("BaseClass:init:filename = ", filename, "\n", sep="")
  .Object <- callNextMethod(.Object, filename=filename, ...)
  [EMAIL PROTECTED] <- filename
  .Object
   }
)

setValidity("BaseClass",
   function(object) {
  cat("--setValidity:BaseClass--\n")
  cat("BaseClass:val:class(.Object) = ", class(object), "\n", sep="")
  msg <- NULL
  if (!(is.character([EMAIL PROTECTED])))
 msg <- cat("missing filename\n")
  cat("BaseClass:val:filename = ",[EMAIL PROTECTED], "\n", sep="")
  if (is.null(msg)) TRUE else msg
   }
)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
setMethod("initialize", "SubClassB",
   function(.Object, nameB="",  ...) {
  cat("--initialize:SubClassB--\n")
  cat("SubClassB:init:class(.Object) = ", class(.Object), "\n", sep="")
  .Object <- callNextMethod(.Object, nameB=nameB, ...)
  [EMAIL PROTECTED] = nameB
  .Object
   }
)

setValidity("SubClassB",
   function(object) {
  cat("--setValidity:SubClassB--\n")
  cat("SubClassB:val:class(object) = ", class(object), "\n", sep="")
  msg <- NULL
  if (!(is.character([EMAIL PROTECTED]) && length([EMAIL PROTECTED]) > 0))
 msg <- cat("missing nameB\n")
  cat("SubClassB:val:nameB = ",[EMAIL PROTECTED], "\n", sep="")
  if (is.null(msg)) TRUE else msg
   }
)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Re: [Rd] some SPSS 15 files wont open in R 2.4.0

2007-04-05 Thread Prof Brian Ripley
On Thu, 5 Apr 2007, Sam Smith wrote:

>
> Trying to open some SPSS .sav files (saved with SPSS 15) gives the following:
>
>   
> read.spss('/data/big/unzipped_ukda/seh3767/3767SPSS_570D6A086C9A1B0636F13255F25A58C1/prgrp95.sav')
>   Error in
> read.spss("/data/big/unzipped_ukda/seh3767/3767SPSS_570D6A086C9A1B0636F13255F25A58C1/prgrp95.sav"):
> error reading system-file header
>   In addition: Warning message:
>   
> /data/big/unzipped_ukda/seh3767/3767SPSS_570D6A086C9A1B0636F13255F25A58C1/prgrp95.sav:
>   File-indicated character representation code (Unknown) is not ASCII
>
> Some are fine in R, some are not.

This is not 'in R', it is in contributed (recommended) package 'foreign', 
so it is that's version that is relevant here. (We do ask for 
sessionInfo() in the R posting guide for good reason.)

> The file opens in SPSS, and googling the error message gives
> this mail about PSPP
> 
> http://www.nabble.com/problem-loading-SPSS-15.0-save-files-t2726500.html
> which includes a diff for the PSPP code which opens R files
> and throws that exact error message back.

'R files'?  Surely, 'SPSS 15 files'!

That just removes a test.  If Ben Pfaff thinks it is no longer needed, I 
suppose we could just remove it, but what happens if SPSS has Latin-1 or 
UTF-8 data?  I think we should give a warning if not an error.

> R documentation says that it uses some code based on PSPP,
> I can't see it in the R distribution?.

Look in the tarball for foreign (in src/library/Recommended).

> Does anyone with more
> clue than I know whether the above is likely to fix it, and
> where I should be looking for the code to change?
>
> Alternatively, has anyone got any ideas on opening these files?

Use SPSS and re-save in an open format?

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


Re: [Rd] Implementation of pretty

2007-04-05 Thread hadley wickham
On 4/5/07, Martin Maechler <[EMAIL PROTECTED]> wrote:
> > "hadley" == hadley wickham <[EMAIL PROTECTED]>
> > on Thu, 5 Apr 2007 10:43:41 -0500 writes:
>
> hadley> Hi, I'm trying to track down any references for the
> hadley> implementation of pretty (or grid.pretty) in R.  Is
> hadley> it original work?
>
> Much of it is.  The original version, say R version 0.01, may
> have been based on some reference, but we have added quite a few extra tweaks,
> where in my case I sat down with a piece of paper, considered
> and transformed some inequalities and also did computer
> experiments additionally.
> I've even started to make more coherent notes eventually, but
> not electronically, and hence no tech.report /  publication / ...
>
>  { Did you really want to know this :-) }

Yes - that's great!  And if you ever do put you notes in electronic
format I'd love to see them.  There's very little written on the
subject of choosing good tick marks.

Hadley

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


Re: [Rd] Implementation of pretty

2007-04-05 Thread Duncan Murdoch
On 4/5/2007 1:41 PM, hadley wickham wrote:
> On 4/5/07, Martin Maechler <[EMAIL PROTECTED]> wrote:
>> > "hadley" == hadley wickham <[EMAIL PROTECTED]>
>> > on Thu, 5 Apr 2007 10:43:41 -0500 writes:
>>
>> hadley> Hi, I'm trying to track down any references for the
>> hadley> implementation of pretty (or grid.pretty) in R.  Is
>> hadley> it original work?
>>
>> Much of it is.  The original version, say R version 0.01, may
>> have been based on some reference, but we have added quite a few extra 
>> tweaks,
>> where in my case I sat down with a piece of paper, considered
>> and transformed some inequalities and also did computer
>> experiments additionally.
>> I've even started to make more coherent notes eventually, but
>> not electronically, and hence no tech.report /  publication / ...
>>
>>  { Did you really want to know this :-) }
> 
> Yes - that's great!  And if you ever do put you notes in electronic
> format I'd love to see them.  There's very little written on the
> subject of choosing good tick marks.

I wrote a little bit on this in a Chance column:

Murdoch, D.J. (2000).  Drawing a scatterplot.  {\em Chance} {\bf 13.3}, 
53--55.

Duncan Murdoch

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


Re: [Rd] Problem with S4 inheritance: unexpected re-initialization?

2007-04-05 Thread Herve Pages
Hi Cristian,

cstrato wrote:
[...]
> Although SubSubClassB1 and SubSubClassB2 differ only slightly, the results
> for "subsubB1" are correct, while "subsubB2" gives a wrong result, see:
>> subsubB2 <- new("SubSubClassB2", filename="MyFileNameB2",
> nameB="MyNameB")
>> subsubB2
> An object of class "SubSubClassB2"
> Slot "nameB2":
> [1] "MyNameB"
> 
> Slot "nameB":
> [1] ""
> 
> Slot "filename":
> [1] "MyFileNameB2"

I think that the problem has to do with the way you use callNextMethod() in your
"initialize" method for SubSubClassB2:

  setMethod("initialize", "SubSubClassB2",
function(.Object, nameB2="MyNameB2", ...) {
   cat("--initialize:SubSubClassB2--\n")
   cat("SubSubClassB2:init:class(.Object) = ", class(.Object), "\n", sep="")
   if (nameB2 == "") nameB2 <- "DefaultNameB2";
   cat("SubSubClassB2:init:nameB2 = ", nameB2, "\n", sep="")
   .Object <- callNextMethod(.Object, nameB2=nameB2, ...)
   [EMAIL PROTECTED] <- nameB2
   .Object
}
  )

As a side note: I don't understand why you want to define a default value for
the 'nameB2' argument since you have defined a prototype for the SubSubClassB2
class (with a different default value for the 'nameB2' slot).

Try this instead:

  setMethod("initialize", "SubSubClassB2",
function(.Object, ...) {
   cat("--initialize:SubSubClassB2--\n")
   cat("SubSubClassB2:init:class(.Object) = ", class(.Object), "\n", sep="")
   .Object <- callNextMethod()
   if ([EMAIL PROTECTED] == "") [EMAIL PROTECTED] <- "DefaultNameB2"
   .Object
}
  )

It gives you what you want:

  > new("SubSubClassB2", filename="MyFileNameB2", nameB="MyNameB")
  --initialize:SubSubClassB2--
  SubSubClassB2:init:class(.Object) = SubSubClassB2
  --initialize:SubClassB--
  SubClassB:init:class(.Object) = SubSubClassB2
  --initialize:BaseClass--
  BaseClass:init:class(.Object) = SubSubClassB2
  BaseClass:init:filename = MyFileNameB2
  An object of class "SubSubClassB2"
  Slot "nameB2":
  [1] "NameB2"

  Slot "nameB":
  [1] "MyNameB"

  Slot "filename":
  [1] "MyFileNameB2"


[...]
> 
> In contrast, for "SubSubClassB2" I get the following sequence of events:
>> subsubB2 <- new("SubSubClassB2", filename="MyFileNameB2",
> nameB="MyNameB")
> --initialize:SubSubClassB2
> --initialize:SubClassB
> --initialize:BaseClass
> --setValidity:BaseClass
> --initialize:SubClassB
> --initialize:BaseClass
> --setValidity:BaseClass
> --setValidity:SubClassB
> --setValidity:SubClassB
> --initialize:SubClassB
> --initialize:BaseClass
> --setValidity:BaseClass
> --setValidity:SubClassB
> --setValidity:SubSubClassB2

I can reproduce this behaviour with a _much_ simple and shorter code:

  setClass("A",
representation(a="character"),
prototype(a="a0")
  )
  setValidity("A",
function(object) {
cat("--setValidity:A--\n")
tmp <- class(object)
TRUE
}
  )
  setMethod("initialize", "A",
function(.Object, ...) {
cat("--initialize:A--\n")
callNextMethod()
}
  )

  setClass("B",
contains="A",
representation(b="character")
  )
  setValidity("B",
function(object) {
cat("--setValidity:B--\n")
TRUE
}
  )
  setMethod("initialize", "B",
function(.Object, ...) {
cat("--initialize:B--\n")
callNextMethod()
}
  )

Then I get this:

  > b <- new("B", b="hello")
  --initialize:B--
  --initialize:A--
  --setValidity:A--
  --initialize:A--
  --setValidity:B--

Why is initialize:A called twice? I have no idea (bug?) but I agree with you 
that
this is unexpected. Note that this line

  tmp <- class(object)

in setValidity:A is what triggers the extra call to initialize:A. If you remove
it, things work as expected. Very strange!

Cheers,
H.


> sessionInfo()
R version 2.5.0 alpha (2007-03-30 r40957)
x86_64-unknown-linux-gnu

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

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



> 
> Furthermore, the slot "filename" is first initialized correctly to
> "filename=MyFileNameB2", but then it is twice initialized incorrectly
> to "filename=ERROR_FileName", indicating that it may not have been
> initialized at all. I do not understand this behavior, why is this so?
> 
> I really hope that this time the code below is acceptable to you.
> Thank you for your help.
> Best regards
> Christian
> 
> # - - - - - - - - - - - - - - - - BEGIN - - - - - - - - - - - - - - - -
> - - - -
> setClass("BaseClass",
>   representation(filename = "character", "VIRTUAL"),
>   prototype(filename = "DefaultFileName")
> )
> 
> setClass("SubClassB",
>   representation(nameB = "char

[Rd] bquote(function(x,y) T) (PR#9602)

2007-04-05 Thread felix
> quote(function(x, y) T)
function(x, y) T

> bquote(function(x, y) T)
function(, y) T

> eval(.Last.value)
Error in eval(expr, envir, enclos) : invalid formal argument list for "function"

> R.version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  4.1
year   2006
month  12
day18
svn rev40228
language   R
version.string R version 2.4.1 (2006-12-18)


-- 
Felix Andrews / 安福立
PhD candidate, The Fenner School of Environment and Society
The Australian National University (Building 48A), ACT 0200
Beijing Bag, Locked Bag 40, Kingston ACT 2604
http://www.neurofractal.org/felix/
voice:+86_1051404394 (in China)
mobile:+86_13522529265 (in China)
mobile:+61_410400963 (in Australia)
xmpp:[EMAIL PROTECTED]
3358 543D AAC6 22C2 D336  80D9 360B 72DD 3E4C F5D8

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