[Rd] indexing by character with identical names

2008-09-19 Thread Jake Michaelson
Hi all,

I've been using R for a while, but was puzzled when I just barely
noticed this behavior:

 x - 1:10
 names(x) - c(a,b,a,letters[1:7])
 x
 a  b  a  a  b  c  d  e  f  g 
 1  2  3  4  5  6  7  8  9 10 

 x[a]
a 
1 

... that is, if a vector has identical (and therefore ambiguous) names,
it only returns the first match when the vector is indexed by a
non-unique name.  From my perspective, a more sensible behavior would be
to return *all* elements which carry the non-unique name (e.g.
x[names(x)==a] ), since it's ambiguous as to which element the user
actually wanted to extract.  It just seems safer than quietly returning
only the first matched element with no warning or other indication as to
what's actually happening.

I couldn't find that this behavior is explicitly documented in the help
file for '[' or 'names'.

I also couldn't find any prior discussion of this behavior.  Is this
something that could be addressed in an upcoming release of R? 

Thanks,

jake

R version 2.7.2 (2008-08-25) 
x86_64-unknown-linux-gnu

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


Re: [Rd] indexing by character with identical names

2008-09-19 Thread Barry Rowlingson
2008/9/19 Jake Michaelson [EMAIL PROTECTED]

 ... that is, if a vector has identical (and therefore ambiguous) names,
 it only returns the first match when the vector is indexed by a
 non-unique name.  From my perspective, a more sensible behavior would be
 to return *all* elements which carry the non-unique name (e.g.
 x[names(x)==a] ), since it's ambiguous as to which element the user
 actually wanted to extract.  It just seems safer than quietly returning
 only the first matched element with no warning or other indication as to
 what's actually happening.

 Some people may think it sensible that indexing a vector with an
index of length N returns a vector of length N:

  x[c(a,b,a)]
 a b a
 1 2 1

 I also couldn't find any prior discussion of this behavior.  Is this
 something that could be addressed in an upcoming release of R?

 Changing this would probably (no, definitely!) break stuff. Breaking
stuff is a bad thing. Perhaps the upcoming R version Aleph-null
release would be the right place for it...

 R is not like other programming languages, so your perspective of
sensibility of minimal use here. You will get bitten by these gotchas.
I bet everyone on this mailing list has done a X[1,] and got bitten by
not having drop=FALSE

 Ouch. Writing tests on edge cases is a good thing, since it catches
these problems (if you write your tests well!).

Barry

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


[Rd] family=mono does not work (PR#12931)

2008-09-19 Thread jaanvajakas
Full_Name: Jaan Vajakas
Version: 2.7.2
OS: Windows XP
Submission from: (NULL) (193.40.5.245)


When I execute the following code in the R GUI, the text mono is printed in
monotype font in the first plot, but in normal (sans-serif) font in the
remaining three plots:

op=par(mfrow=c(2,2))
for (i in 1:4) {
 hist(1:10,xlab=)
 mtext(normal,side=1,line=2)
 mtext(mono,side=1,line=3,family=mono)
}
par(op)

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


[Rd] R spec file change for building on CentOS 5.2 (PR#12939)

2008-09-19 Thread agajania

--GZVR6ND4mMseVXL/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


I built R 2.7.2 on CentOS 5.2 today.  I used the R.spec file posted
on the web site, but I had to change one line to get it to work.
I have attached the diffs from my spec file to the original.
(Otherwise, the build went fine.)

-- 
Aram J. Agajanian
Computer Science/UNIX Support
Academic Computing
State University of New York at New Paltz

Support the Free Software Foundation - www.fsf.org

--GZVR6ND4mMseVXL/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=specfile.diffs

49c49
 %if %(rpmquery centos-release | grep -v 'not installed$' | grep -c -e 
'-[0-9]-[0-9].el[0-9]')
---
 %if %(rpmquery centos-release | grep -v 'not installed$' | grep -c -e 
 '-[0-9]-[0-9].[0-9]')
128c128
 Version: 2.7.2
---
 Version: 2.7.1
131c131
 Source0: R-%{version}.tar.gz
---
 Source0: ftp://cran.r-project.org/pub/R/src/base/R-2/R-%{version}.tar.gz

--GZVR6ND4mMseVXL/--

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


Re: [Rd] Extract method for a new class

2008-09-19 Thread Martin Morgan
Coster, Albart [EMAIL PROTECTED] writes:

 Dear list,

 I am trying to write a package for simulating meioses in R. We defined
 a class 'haplotype' which contains the basic units of our simulation:

 setClass(haplotype,representation(snp = numeric,qtl = list, hID
 = numeric,phID0 = numeric,phID1 = numeric), prototype = list(hID
 = 0,phID0 = NaN,phID1 = NaN))

 In addition, we define a class 'haploList', which is just a list of
 haplotypes:

 setClass(haploList,contains = list,representation(genDist =
 numeric,roundDec = integer))

 Most things work fine, but when subsetting a haploList object an
 object of class list is returned. I realize that I need to write a
 function for subsetting this new object, and tried to find the code
 for '[.listof' or something similar could not find it, probably due to
 a suboptimal understanding of how it is organized.

 My question is, how could I define a extraction function for my new
 class that uses all the existing functionality of the Extract function
 for list?

You can find out what the generic looks like

 getGeneric([)
standardGeneric for [ defined from package base

function (x, i, j, ..., drop = TRUE) 
standardGeneric([, .Primitive([))
environment: 0xfc17a8
Methods may be defined for arguments: x, i, j, drop
Use  showMethods([)  for currently available ones.

and then write method(s) for your class:

setMethod([,
  signature=signature(x=haploList, i=ANY, j=missing),
  function(x, i, j, ..., drop=TRUE) {
  ## update and return x
  [EMAIL PROTECTED] - [EMAIL PROTECTED], drop=drop]
  x
  })

Note though that extending 'list' has hazards, e.g.,

 hlst - new(haploList, list(a=1,b=2))
 names(hlst)
[1] a b
 names(hlst[2])
[1] a

where the names have been confused! You'll want to manage the names
yourself (as a separate slot) or make sure that they're removed
entirely when you create / update your object.

(Here's a variant that I like

setMethod([,
  signature=signature(x=haploList, i=ANY, j=missing),
  function(x, i, j, ..., drop=TRUE) {
  ## feed updated values to 'initialize'
  initialize(x, [EMAIL PROTECTED])
  })

because the initialize call will [provided any initialize methods
defined on contained classes don't interfer] minimize copying. You'll
also likely want methods for $ and [[, and assignment methods [-
etc.)
  
Hope that helps,

Martin

 Thanks in advance,

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

-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M2 B169
Phone: (206) 667-2793

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


[Rd] readRegistry function (PR#12937)

2008-09-19 Thread zivan . karaman
Full_Name: Zivan Karaman
Version: 2.7.2
OS: Windows XP
Submission from: (NULL) (195.6.68.214)


I'm puzzled by the readRegistry function.

Shouldn't the hive argument be something like 
c(HLM, HCR, HCU, HU, HCC, HPD) rather than 
c(HLM, HCR, HCU, HU, HCC, HPD).

For example,
 readRegistry(Test,  HCC, HPD)
Error in readRegistry(Test, HCC, HPD) : invalid 'hive' value

Please note also that only the first character of the 'key' argument value is
printed in case of error (key not found).

 readRegistry(SOFTWARE\\DummyTest,  HLM)
Error in readRegistry(SOFTWARE\\DummyTest, HLM) : 
  Registry key 'S' not found

 sessionInfo()
R version 2.7.2 (2008-08-25) 
i386-pc-mingw32 

locale:
LC_COLLATE=French_France.1252;LC_CTYPE=French_France.1252;LC_MONETARY=French_France.1252;LC_NUMERIC=C;LC_TIME=French_France.1252

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

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


Re: [Rd] readRegistry function (PR#12937)

2008-09-19 Thread Duncan Murdoch

On 9/19/2008 1:25 PM, [EMAIL PROTECTED] wrote:

Full_Name: Zivan Karaman
Version: 2.7.2
OS: Windows XP
Submission from: (NULL) (195.6.68.214)


I'm puzzled by the readRegistry function.

Shouldn't the hive argument be something like 
c(HLM, HCR, HCU, HU, HCC, HPD) rather than 
c(HLM, HCR, HCU, HU, HCC, HPD).


Yes, that's a typo.  I'll fix it.


For example,

readRegistry(Test,  HCC, HPD)

Error in readRegistry(Test, HCC, HPD) : invalid 'hive' value

Please note also that only the first character of the 'key' argument value is
printed in case of error (key not found).


readRegistry(SOFTWARE\\DummyTest,  HLM)
Error in readRegistry(SOFTWARE\\DummyTest, HLM) : 
  Registry key 'S' not found


I'll also fix that.  Thanks for the report!

Duncan Murdoch


sessionInfo()
R version 2.7.2 (2008-08-25) 
i386-pc-mingw32 


locale:
LC_COLLATE=French_France.1252;LC_CTYPE=French_France.1252;LC_MONETARY=French_France.1252;LC_NUMERIC=C;LC_TIME=French_France.1252

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

__
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