[R] string syntactic sugar in R? - long post

2005-05-07 Thread charles loboz
Currently in R, constructing a string containing
values of variables is done using 'paste' and can be
an error-prone and traumatic experience. For example,
when constructing a db query we have to write,
  paste(SELECT  value  FROM table  where
date =',cdate,')
we are getting null result from it, because without
(forgotten...) sep=  we get
 SELECT value FROM table where date='
2005-05-05 '
instead of
SELECT value FROM table where date='2005-05-05'
Adding sep= as a habit results in other errors, like
column names joined with keywords - because of
forgotten spaces. Not to mention mixing up or
unbalancing quote marks etc. The approach used by
paste is similar to that of many other languages (like
early Java, VB etc) and is inherently error-prone
because of poor visualization. There is a way to
improve it.

In the Java world gstrings were introduced
specifically for this purpose. A gstring is a string
with variable names embedded and replaced by values
(converted to strings, lazy eval) before use. An
example in R-syntax would be:

alpha - 8; beta=xyz
gstr - the result is ${alpha} with the comment
${beta}
cat(gstr)
  the result is 8 with the comment xyz

This syntactic sugar reduces significantly the number
of mistakes made with normal string concatenations.
Gstrings are used in ant and groovy - (for details see
http://groovy.codehaus.org/Strings, jump to GStrings).
They are particularly useful for creating readable and
error-free SQL statements, but obviously the simplify
'normal' string+value handling in all situations. [ps:
gstrings are not nestable]

I was wondering how difficult it would be to add such
syntactic sugar to R and would that create some
language problems? May be it is possible that it could
be done as some gpaste function, parsing the argument
for ${var}, extracting variables from the environment,
evaluating them and producing the final string?

I admit my bias - using ant for years and groovy for
months and having to do a lot of SQL queries does not
put me in the mainstream of R users - so it may be
that this idea is not usable to a wider group of
users.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] string syntactic sugar in R? - long post

2005-05-07 Thread Robert Gentleman
Hi,
 In Bioconductor, we have something called copySubstitute, which does  
what you want, I believe,

 x=select @var1@ from @tab1@
 copySubstitute(textConnection(x), symbolValues= list(var1=Race,  
tab1=ReallyBigTable), dest=stdout())

yields
select Race from ReallyBigTable
you can read in from any connection and write out to any connection,  
change the delimiter, etc.
We use it to autogenerate manual pages and other documentation for  
packages that have lots of similar structure, as well as for things  
like what you want to do.

Best wishes,
 Robert

On May 7, 2005, at 1:36 AM, charles loboz wrote:
Currently in R, constructing a string containing
values of variables is done using 'paste' and can be
an error-prone and traumatic experience. For example,
when constructing a db query we have to write,
  paste(SELECT  value  FROM table  where
date =',cdate,')
we are getting null result from it, because without
(forgotten...) sep=  we get
 SELECT value FROM table where date='
2005-05-05 '
instead of
SELECT value FROM table where date='2005-05-05'
Adding sep= as a habit results in other errors, like
column names joined with keywords - because of
forgotten spaces. Not to mention mixing up or
unbalancing quote marks etc. The approach used by
paste is similar to that of many other languages (like
early Java, VB etc) and is inherently error-prone
because of poor visualization. There is a way to
improve it.
In the Java world gstrings were introduced
specifically for this purpose. A gstring is a string
with variable names embedded and replaced by values
(converted to strings, lazy eval) before use. An
example in R-syntax would be:
alpha - 8; beta=xyz
gstr - the result is ${alpha} with the comment
${beta}
cat(gstr)
  the result is 8 with the comment xyz
This syntactic sugar reduces significantly the number
of mistakes made with normal string concatenations.
Gstrings are used in ant and groovy - (for details see
http://groovy.codehaus.org/Strings, jump to GStrings).
They are particularly useful for creating readable and
error-free SQL statements, but obviously the simplify
'normal' string+value handling in all situations. [ps:
gstrings are not nestable]
I was wondering how difficult it would be to add such
syntactic sugar to R and would that create some
language problems? May be it is possible that it could
be done as some gpaste function, parsing the argument
for ${var}, extracting variables from the environment,
evaluating them and producing the final string?
I admit my bias - using ant for years and groovy for
months and having to do a lot of SQL queries does not
put me in the mainstream of R users - so it may be
that this idea is not usable to a wider group of
users.
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!  
http://www.R-project.org/posting-guide.html


+--- 
+
| Robert Gentleman  phone: (206) 667-7700
 |
| Head, Program in Computational Biology   fax:  (206) 667-1319   |
| Division of Public Health Sciences   office: M2-B865   
  |
| Fred Hutchinson Cancer Research Center 
 |
| email: [EMAIL PROTECTED]  
 |
+--- 
+

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] string syntactic sugar in R? - long post

2005-05-07 Thread James Bullard
The other thing to use is 'sprintf', which would be fantastic in R if it 
imputed types based on the format string.
As it is now, for your query you would do:
sprintf(SELECT %s FROM table WHERE date = '%s', column, 2005-10-12)
[1] SELECT column FROM table WHERE date = '2005-10-12'
Which, in my opinion is nicer than the corresponding paste, and about as nice 
as gstring. The issue that I always have with sprintf is when I use numbers, 
specifically integers. As the function is just a wrapper for the C function  
and because numbers are implicitly doubles the following doesnt work:
 sprintf(SELECT %s FROM table WHERE age = %d, column, 1)
Error in sprintf(SELECT %s FROM table WHERE age = %d, column, 1) : 
   use format %f, %e or %g for numeric objects

It does work however if you do
sprintf(SELECT %s FROM table WHERE age = %d, column, as.integer(1))
[1] SELECT column FROM table WHERE age = 1
This however, is not so nice - are there reasons why this has to be like this? This might be naive but I would think it would be pretty simple in R to do this automatically. Thanks for any insight. 

jim

charles loboz wrote:
Currently in R, constructing a string containing
values of variables is done using 'paste' and can be
an error-prone and traumatic experience. For example,
when constructing a db query we have to write,
 paste(SELECT  value  FROM table  where
date =',cdate,')
we are getting null result from it, because without
(forgotten...) sep=  we get
SELECT value FROM table where date='
2005-05-05 '
instead of
SELECT value FROM table where date='2005-05-05'
Adding sep= as a habit results in other errors, like
column names joined with keywords - because of
forgotten spaces. Not to mention mixing up or
unbalancing quote marks etc. The approach used by
paste is similar to that of many other languages (like
early Java, VB etc) and is inherently error-prone
because of poor visualization. There is a way to
improve it.
In the Java world gstrings were introduced
specifically for this purpose. A gstring is a string
with variable names embedded and replaced by values
(converted to strings, lazy eval) before use. An
example in R-syntax would be:
 

alpha - 8; beta=xyz
gstr - the result is ${alpha} with the comment
   

${beta}
 

cat(gstr)
   

 the result is 8 with the comment xyz
This syntactic sugar reduces significantly the number
of mistakes made with normal string concatenations.
Gstrings are used in ant and groovy - (for details see
http://groovy.codehaus.org/Strings, jump to GStrings).
They are particularly useful for creating readable and
error-free SQL statements, but obviously the simplify
'normal' string+value handling in all situations. [ps:
gstrings are not nestable]
I was wondering how difficult it would be to add such
syntactic sugar to R and would that create some
language problems? May be it is possible that it could
be done as some gpaste function, parsing the argument
for ${var}, extracting variables from the environment,
evaluating them and producing the final string?
I admit my bias - using ant for years and groovy for
months and having to do a lot of SQL queries does not
put me in the mainstream of R users - so it may be
that this idea is not usable to a wider group of
users.
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 


--
James Bullard
[EMAIL PROTECTED]
760.267.0986
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] ScieViews installer

2005-05-07 Thread Erich Neuwirth
I tried to install SciViews in R 2.1.0 (on Windows)
and on all machines I get:

bundle 'SciViews' successfully unpacked and MD5 sums checked
Error in sprintf(gettext(unable to move temp installation '%d' to
'%s'),  :
use format %s for character objects

how can I solve this problem?



-- 
Erich Neuwirth, University of Vienna
Faculty of Computer Science
Didactic Center for Computer Science
Visit our SunSITE at http://sunsite.univie.ac.at
Phone: +43-1-4277-39464 Fax: +43-1-4277-39459

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] string syntactic sugar in R? - long post

2005-05-07 Thread Ted Harding
On 07-May-05 James Bullard wrote:
 The other thing to use is 'sprintf', which would be fantastic in R if
 it imputed types based on the format string.
 
 As it is now, for your query you would do:
 
 sprintf(SELECT %s FROM table WHERE date = '%s', column,
 2005-10-12)
 [1] SELECT column FROM table WHERE date = '2005-10-12'
 
 Which, in my opinion is nicer than the corresponding paste, and about
 as nice as gstring. The issue that I always have with sprintf is when I
 use numbers, specifically integers. As the function is just a wrapper
 for the C function  and because numbers are implicitly doubles the
 following doesnt work:
 
  sprintf(SELECT %s FROM table WHERE age = %d, column, 1)
 Error in sprintf(SELECT %s FROM table WHERE age = %d, column, 1) : 
 use format %f, %e or %g for numeric objects
 
 It does work however if you do
 
 sprintf(SELECT %s FROM table WHERE age = %d, column,
 as.integer(1))
 [1] SELECT column FROM table WHERE age = 1
 
 This however, is not so nice - are there reasons why this has to be
 like this? This might be naive but I would think it would be pretty
 simple in R to do this automatically. Thanks for any insight. 

You can force integer format using %f if you use it as %.0f:

  sprintf(SELECT %s FROM table WHERE age = %.0f, column, 1)
  ## [1] SELECT column FROM table WHERE age = 1

The rule (as in C) is that %a.bf outputs a format for the
floating-point number in a minimum width of 'a' characters
(field width, left-padded with space), with 'b' digits following
the decimal point (and no decimal point is printed if b=0);
if either 'a' or 'b' is missing then no corresponding restriction
is imposed.

Best wishes,
Ted.



E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 07-May-05   Time: 11:05:06
-- XFMail --

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] scrivete a ...

2005-05-07 Thread messaggio automatico
Si segnala di rivolgersi per 
 tasse e pagamenti a [EMAIL PROTECTED]
 di contattare la propria segreteria studenti agli indirizzi:
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 per informazioni generali:
 [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Test on mu with multivariate normal distribution

2005-05-07 Thread Telse Henschel
Dear WizaRds,

I am sorry to bother you with a newbie question, but although I tried to solve 
my problem using the various .pdf files (Introduction, help pages etc.), I have 
come to a complete stop. Please be so kind as to guide me a little bit along my 
way of exploring multivariate analysis in R.

I want to test wether the means-vector mu1 of  X, consisting of the means per 
column of that matrix , and mu2, i.e. the means per column of Y,  are 
distributed equally  under the assumption of a multivariate normal 
distribution. I thought “simtest” could be the right function to get the 
p-value, but I fail to use R correctly. Here is what I tried to do:

f1  - factor(c(8, 10, 12, 14))

X   - matrix(1:16, ncol=4)
colnames(X) - c(Obj1,Obj2,Obj3,Obj4)
X.frame - data.frame(f1,X)

Y   - matrix(1:12, ncol=4)
colnames(Y) - c(Obj1,Obj2,Obj3,Obj4)
Y.frame - data.frame(f1,Y)
XY  - data.frame(X.frame, Y.frame) # won’t work, because of 
different nr of rows

test.stat   - lm(XY ~ f1)  # ???

# simtest(test.stat, XY, type=Tukey)

creates errors already by just staring at it. I apologize.


Thank you so much for your support,
Telse

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Peter Moser ist =?iso-8859-1?q?au=DFer_Haus=2E?=

2005-05-07 Thread peter . moser
Ich werde ab  04.05.2005 nicht im Büro sein. Ich kehre zurück am
16.05.2005.

Ich werde Ihre Nachricht nach meiner Rückkehr beantworten.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] string syntactic sugar in R? - long post

2005-05-07 Thread Prof Brian Ripley
On Sat, 7 May 2005, James Bullard wrote:
The other thing to use is 'sprintf', which would be fantastic in R if it 
imputed types based on the format string.
But it does in 2.1.0, the current version.
As it is now, for your query you would do:
sprintf(SELECT %s FROM table WHERE date = '%s', column, 2005-10-12)
[1] SELECT column FROM table WHERE date = '2005-10-12'
Which, in my opinion is nicer than the corresponding paste, and about as nice 
as gstring. The issue that I always have with sprintf is when I use numbers, 
specifically integers. As the function is just a wrapper for the C function
It is not `just a wrapper': someone put a lot of working into writing an 
intelligent wrapper.

and because numbers are implicitly doubles the following doesnt work:
 sprintf(SELECT %s FROM table WHERE age = %d, column, 1)
Error in sprintf(SELECT %s FROM table WHERE age = %d, column, 1) : 
use format %f, %e or %g for numeric objects

It does work however if you do
sprintf(SELECT %s FROM table WHERE age = %d, column, as.integer(1))
[1] SELECT column FROM table WHERE age = 1
This however, is not so nice - are there reasons why this has to be like 
this? This might be naive but I would think it would be pretty simple in R to 
do this automatically. Thanks for any insight.
In R 2.1.0:
 sprintf(SELECT %s FROM table WHERE age = %d, column, 1)
[1] SELECT column FROM table WHERE age = 1
!
--
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-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] string syntactic sugar in R? - long post

2005-05-07 Thread Gabor Grothendieck
On 5/7/05, charles loboz [EMAIL PROTECTED] wrote:
 Currently in R, constructing a string containing
 values of variables is done using 'paste' and can be
 an error-prone and traumatic experience. For example,
 when constructing a db query we have to write,
  paste(SELECT  value  FROM table  where
 date =',cdate,')
 we are getting null result from it, because without
 (forgotten...) sep=  we get
 SELECT value FROM table where date='
 2005-05-05 '
 instead of
SELECT value FROM table where date='2005-05-05'
 Adding sep= as a habit results in other errors, like
 column names joined with keywords - because of
 forgotten spaces. Not to mention mixing up or
 unbalancing quote marks etc. The approach used by
 paste is similar to that of many other languages (like
 early Java, VB etc) and is inherently error-prone
 because of poor visualization. There is a way to
 improve it.
 
 In the Java world gstrings were introduced
 specifically for this purpose. A gstring is a string
 with variable names embedded and replaced by values
 (converted to strings, lazy eval) before use. An
 example in R-syntax would be:
 
 alpha - 8; beta=xyz
 gstr - the result is ${alpha} with the comment
 ${beta}
 cat(gstr)
  the result is 8 with the comment xyz
 
 This syntactic sugar reduces significantly the number
 of mistakes made with normal string concatenations.
 Gstrings are used in ant and groovy - (for details see
 http://groovy.codehaus.org/Strings, jump to GStrings).
 They are particularly useful for creating readable and
 error-free SQL statements, but obviously the simplify
 'normal' string+value handling in all situations. [ps:
 gstrings are not nestable]
 
 I was wondering how difficult it would be to add such
 syntactic sugar to R and would that create some
 language problems? May be it is possible that it could
 be done as some gpaste function, parsing the argument
 for ${var}, extracting variables from the environment,
 evaluating them and producing the final string?
 
 I admit my bias - using ant for years and groovy for
 months and having to do a lot of SQL queries does not
 put me in the mainstream of R users - so it may be
 that this idea is not usable to a wider group of
 users.

Here is one attempt.  It eliminates the necessity to quote the
elements altogether but in exchange requires that the
argument be a valid R expression.  It is based on the 
R bquote function.  

gpaste - function(expr, where = parent.frame()) {
  dequote - function(e) as.name(noquote(as.character(e)))
  unquote - function(e) {
  if (length(e) = 1) 
  dequote(e)
  else if (e[[1]] == as.name(.)) 
  dequote(eval(e[[2]], where))
  else as.call(lapply(e, unquote))
  }
  rval - paste(unquote(substitute(expr)), collapse =  )
  rval - gsub(+ , , rval, fix = TRUE)
  gsub(`, , rval)
}   

# test
var - myvar
gpaste( select + .(var) + from + table + where + 
date + = + .(sQuote(Sys.Date())) )

When you run it you get this:

 gpaste( select + .(var) + from + table + where + 
+   date + = + .(sQuote(Sys.Date())) )
[1] select myvar from table where date  = '2005-05-07'

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] ScieViews installer

2005-05-07 Thread Prof Brian Ripley
On Sat, 7 May 2005, Erich Neuwirth wrote:
I tried to install SciViews in R 2.1.0 (on Windows)
and on all machines I get:
bundle 'SciViews' successfully unpacked and MD5 sums checked
Error in sprintf(gettext(unable to move temp installation '%d' to
'%s'),  :
   use format %s for character objects
how can I solve this problem?
Well, use R-patched where that exact problem goes away, but that is not 
the problem that needs solving.

The underlying cause is a problem on your Windows file system.  Do you 
have a version of SciViews left over that Windows cannot remove?

I've just tested this, and it works for me even in 2.1.0.
--
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-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] converting NA/non-NA's to a binary variable

2005-05-07 Thread Gillian Rutherford
Dear R colleagues,
I am trying to create a new column in a data frame, which converts values 
and NA's from another column into binary format. Essentially I need the 
NA's to become 1 and the rest to be 0. The code I wrote is returning the 
following error message:

Error in if (mort[i, 4] != NA) mort[i, 8] - 0 else if (mort[i, 4] ==  :
missing value where TRUE/FALSE needed
The code is as follows:
for(i in 1:length(mort[,4]))
{
if(mort[i,4] != NA) mort[i,8] - 0
else if(mort[i,4] == NA) mort[i,8] - 1
}
I'd appreciate any advice or recommendations as to a better way of 
achieving this.

Thanks
Gillian
-
Gillian Rutherford
Eidg. Forschungsanstalt für Wald, Schnee und Landschaft
Swiss Federal Research Institute WSL
Economy Section, Forest Division
Zürcherstrasse 111
CH - 8903 Birmensdorf
Phone: ++ 41 1 739 26 65
E-mail: [EMAIL PROTECTED]
http://www.wsl.ch/staff/gillian.rutherford/
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] converting NA/non-NA's to a binary variable

2005-05-07 Thread Gabor Grothendieck
See ?is.na

On 5/7/05, Gillian Rutherford [EMAIL PROTECTED] wrote:
 Dear R colleagues,
 
 I am trying to create a new column in a data frame, which converts values
 and NA's from another column into binary format. Essentially I need the
 NA's to become 1 and the rest to be 0. The code I wrote is returning the
 following error message:
 
 Error in if (mort[i, 4] != NA) mort[i, 8] - 0 else if (mort[i, 4] ==  :
 missing value where TRUE/FALSE needed
 
 The code is as follows:
 
 for(i in 1:length(mort[,4]))
{
if(mort[i,4] != NA) mort[i,8] - 0
else if(mort[i,4] == NA) mort[i,8] - 1
}
 
 I'd appreciate any advice or recommendations as to a better way of
 achieving this.
 
 Thanks
 Gillian
 -
 Gillian Rutherford
 Eidg. Forschungsanstalt für Wald, Schnee und Landschaft
 Swiss Federal Research Institute WSL
 Economy Section, Forest Division
 Zürcherstrasse 111
 CH - 8903 Birmensdorf
 Phone: ++ 41 1 739 26 65
 E-mail: [EMAIL PROTECTED]
 http://www.wsl.ch/staff/gillian.rutherford/
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] converting NA/non-NA's to a binary variable

2005-05-07 Thread Prof Brian Ripley
mort[8] - is.na(mort[4])
(If you really want 1/0, add  '+ 0' to this expression.)
Testing (in)equality with NA always gives NA.  This is discussed in all 
good books on S/R, e.g. in MASS (see the FAQ).

On Sat, 7 May 2005, Gillian Rutherford wrote:
Dear R colleagues,
I am trying to create a new column in a data frame, which converts values and 
NA's from another column into binary format. Essentially I need the NA's to 
become 1 and the rest to be 0. The code I wrote is returning the following 
error message:

Error in if (mort[i, 4] != NA) mort[i, 8] - 0 else if (mort[i, 4] ==  :
   missing value where TRUE/FALSE needed
The code is as follows:
for(i in 1:length(mort[,4]))
{
if(mort[i,4] != NA) mort[i,8] - 0
else if(mort[i,4] == NA) mort[i,8] - 1
}
I'd appreciate any advice or recommendations as to a better way of achieving 
this.
--
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-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] converting NA/non-NA's to a binary variable

2005-05-07 Thread Ted Harding
On 07-May-05 Gillian Rutherford wrote:
 Dear R colleagues,
 
 I am trying to create a new column in a data frame, which
 converts values and NA's from another column into binary format.
 Essentially I need the NA's to become 1 and the rest to be 0.
 The code I wrote is returning the  following error message:
 
 Error in if (mort[i, 4] != NA) mort[i, 8] - 0 else if (mort[i, 4] == 
:
  missing value where TRUE/FALSE needed
 
 The code is as follows:
 
 for(i in 1:length(mort[,4]))
   {
   if(mort[i,4] != NA) mort[i,8] - 0
   else if(mort[i,4] == NA) mort[i,8] - 1
   }
 
 I'd appreciate any advice or recommendations as to a better way of 
 achieving this.
 
 Thanks
 Gillian

I think the following should do what you want, provided the column
mort[,8] exists:

  mort[,8] - 0
  mort[is.na(mort[,4]),8] - 1

Incidentally, tests like == NA or != NA can produce unexpected
results! Use is.na() instead:

  tmp-NA
  ## [1] NA
  tmp==NA
  ## [1] NA
  tmp!=NA
  ## [1] NA
  if(tmp==NA) 1 else 2
  ## Error in if (tmp == NA) 1 else 2 :
  ## missing value where TRUE/FALSE needed

  if(TRUE) 1 else 2
  ## [1] 1
  is.na(tmp)
  ## [1] TRUE

  if(is.na(tmp)) 1 else 2
  ## [1] 1
  if(!is.na(tmp)) 1 else 2
  ## [1] 2

Best wishes,
Ted.



E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 07-May-05   Time: 14:46:19
-- XFMail --

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Incorrect libxml2.2.dylib version on Tiger install

2005-05-07 Thread Steven Boker
Hi all,
I have just installed OSX Server 10.4 and R comes up with the 
incompatible libxml library message reported by Dan Kelley a few 
messages ago.  Xcode 2 does not ship with Tiger Server.  I installed 
the X-Windows code.  I can report that the version of libxml2.2 that is 
installed in this case is the version 8.0.0 dylib.

[EMAIL PROTECTED]:/usr/lib % ls -l libxml2.2*
-rwxr-xr-x   1 root  wheel  1061704 Apr 15 23:44 libxml2.2.6.16.dylib*
-rwxr-xr-x   1 root  wheel  1061804 May  6 14:15 libxml2.2.dylib*
I'm working on getting a copy of the Xcode 2 CD.  I was surprised it 
wasn't in the 10.4 server CD set.  I have a production problem today, 
though, if anyone can help me with a copy of this library.

Best,
Steve Boker
On May 6, 2005, at 12:39 PM, Dan Kelley wrote:

 Error in dyn.load(x, as.logical(local), as.logical(now)) :
 unable to load shared library '/Library/Frameworks/
 R.framework/Resources/library/grDevices/libs/grDevices.so':
 dlopen(/Library/Frameworks/R.framework/Resources/library/grDevices/
 libs/grDevices.so, 6): Library not loaded: /usr/lib/libxml2.2.dylib
 Referenced from: /System/Library/Frameworks/AppKit.framework/
 Versions/C/AppKit
 Reason: Incompatible library version: AppKit requires version
 9.0.0 or later, but libxml2.2.dylib provides version 8.0.0
-
 Steven M. Boker574-339-0735 (cell/page/message)
 [EMAIL PROTECTED]  574-631-4941 (office)
 http://www.nd.edu/~sboker/ 574-631-8883 (fax)
 Dept. of Psychology, University of Notre Dame, Notre Dame, IN 46556
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] undebug all

2005-05-07 Thread Fernando Saldanha
Is there a fast way to undebug() all functions that are currently
being debugged in all environments?

Thanks.

FS

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] undebug all

2005-05-07 Thread Prof Brian Ripley
On Sat, 7 May 2005, Fernando Saldanha wrote:
Is there a fast way to undebug() all functions that are currently
being debugged in all environments?
I guess you mean `marked for debugging' and not `currently being executed 
under a browser started by being marked for debug'?

Debugging is a property of a function object (a bit in the sxpinfo) 
and so you would have to traverse all reachable objects (as gc does) to 
find them all.

AFAIK once a function has been entered you cannot turn off debugging for 
it.

--
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-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] ScieViews installer

2005-05-07 Thread Erich Neuwirth
Thank you for your help.
The library directory contained some very strangely named
subdirectories, file3132 and similarly.
After removing these and vereything related to SciViews
I was able to install SciViews.
Looking back I seem to remember that form time to time
these strange directories appear and I do not understand
where they come from.
Could it be a timing issue, i.e. Windows trying to remove
a directory too early? I remember similar problems with
temporary files not being deletable by Excel.



Prof Brian Ripley wrote:
 On Sat, 7 May 2005, Erich Neuwirth wrote:
 bundle 'SciViews' successfully unpacked and MD5 sums checked
 Error in sprintf(gettext(unable to move temp installation '%d' to
 '%s'),  :
use format %s for character objects

 how can I solve this problem?
 
 
 Well, use R-patched where that exact problem goes away, but that is not
 the problem that needs solving.
 
 The underlying cause is a problem on your Windows file system.  Do you
 have a version of SciViews left over that Windows cannot remove?
 
 I've just tested this, and it works for me even in 2.1.0.
 

-- 
Erich Neuwirth, University of Vienna
Faculty of Computer Science
Didactic Center for Computer Science
Visit our SunSITE at http://sunsite.univie.ac.at
Phone: +43-1-4277-39464 Fax: +43-1-4277-39459

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] ScieViews installer

2005-05-07 Thread Prof Brian Ripley
On Sat, 7 May 2005, Erich Neuwirth wrote:
Thank you for your help.
The library directory contained some very strangely named
subdirectories, file3132 and similarly.
After removing these and vereything related to SciViews
I was able to install SciViews.
Looking back I seem to remember that form time to time
these strange directories appear and I do not understand
where they come from.
Could it be a timing issue, i.e. Windows trying to remove
a directory too early? I remember similar problems with
temporary files not being deletable by Excel.
No, on NT a Windows atomic file rename is used.  Neither Duncan nor I have 
ever encountered these: they seem to result from a Windows OS bug.


Prof Brian Ripley wrote:
On Sat, 7 May 2005, Erich Neuwirth wrote:
bundle 'SciViews' successfully unpacked and MD5 sums checked
Error in sprintf(gettext(unable to move temp installation '%d' to
'%s'),  :
   use format %s for character objects
how can I solve this problem?

Well, use R-patched where that exact problem goes away, but that is not
the problem that needs solving.
The underlying cause is a problem on your Windows file system.  Do you
have a version of SciViews left over that Windows cannot remove?
I've just tested this, and it works for me even in 2.1.0.
--
Erich Neuwirth, University of Vienna
Faculty of Computer Science
Didactic Center for Computer Science
Visit our SunSITE at http://sunsite.univie.ac.at
Phone: +43-1-4277-39464 Fax: +43-1-4277-39459

--
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-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] General Question re R vs S-Plus

2005-05-07 Thread Jonathan Q.
Coming up to speed on both R and S-Plus.  My access to S-Plus will end
soon so I want to get up to speed on R. The big initial difference
seems that R has only the command editor where S-Plus also has a
windows interface.

My preference is to learn the language and the windows interface
doesn't really do the trick.  My question is, if one uses the windows
interface for some functions, is there a way to see what the
equivalent code would be?  I have checked the manuals, help etc and
can't seem to find a way.

Thanks



-- 
Jonathan
[EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] help for bootstrap of backward stepwise logistic regression

2005-05-07 Thread Giuseppe Biondi Zoccai
I would like to perform a bootstrap validation of a backward stepwise
logistic regression analysis, but I am a beginner with R and I am not
sure of how to do it.
Is there anyone that can send me a sample file in tab format (that I
can modify in Excel by pasting my data) and the pertinent R algorithm?
Many thanks
Giuseppe 

-- 

^^^

Dr. Giuseppe Biondi Zoccai
Interventional Cardiology Unit
St Raffaele Hospital
via Olgettina 60
20132 Milan ITALY
Phone: +39-3408626829
Fax: +39-0226437339
Email: [EMAIL PROTECTED]

^^^

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Vectorize a bootstrapped calculation

2005-05-07 Thread Fernando Saldanha
I would like to vectorize a calculation that is bootstrapped, in the
sense that each step uses the results of the previous steps. For
example:

x - rep(NA, 5)
y - rnorm(5)
for (i in 1:5) {
x[i] - max(y[i], ifelse(i  0, min(x[1:i-1], 0)))
}

(the functions max and min are used just as an example, I would like
to do something like this for arbitrary functions f and g).

It would be nice to be able to write something like:

x - cumsapply(y, max, min)

where the first function, max in this example, would be applied to the
i-th element of y, and the second function, min in the example, would
be applied to the vector x[1:i-1].

Of course one can program such a function, the issue is can it be done
efficiently, and not just as a wrapping of the for loop above?

FS

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Incorrect libxml2.2.dylib version on Tiger install

2005-05-07 Thread Steven Boker
Sorry to reply to my own post, but I have more info.  This probably 
needs to come to the attention of the Mac R developers.

Xcode 2.0 does not have a more recent libxml2.2.dylib.
The problem only manifests itself when running R 2.1.0 from the command 
line, not within the Aqua GUI.

Thanks for your patience.
On May 7, 2005, at 9:30 AM, Steven Boker wrote:
Hi all,
I have just installed OSX Server 10.4 and R comes up with the 
incompatible libxml library message reported by Dan Kelley a few 
messages ago.  Xcode 2 does not ship with Tiger Server.  I installed 
the X-Windows code.  I can report that the version of libxml2.2 that 
is installed in this case is the version 8.0.0 dylib.

[EMAIL PROTECTED]:/usr/lib % ls -l libxml2.2*
-rwxr-xr-x   1 root  wheel  1061704 Apr 15 23:44 libxml2.2.6.16.dylib*
-rwxr-xr-x   1 root  wheel  1061804 May  6 14:15 libxml2.2.dylib*
I'm working on getting a copy of the Xcode 2 CD.  I was surprised it 
wasn't in the 10.4 server CD set.  I have a production problem today, 
though, if anyone can help me with a copy of this library.

Best,
Steve Boker
On May 6, 2005, at 12:39 PM, Dan Kelley wrote:

 Error in dyn.load(x, as.logical(local), as.logical(now)) :
 unable to load shared library '/Library/Frameworks/
 R.framework/Resources/library/grDevices/libs/grDevices.so':
 dlopen(/Library/Frameworks/R.framework/Resources/library/grDevices/
 libs/grDevices.so, 6): Library not loaded: /usr/lib/libxml2.2.dylib
 Referenced from: /System/Library/Frameworks/AppKit.framework/
 Versions/C/AppKit
 Reason: Incompatible library version: AppKit requires version
 9.0.0 or later, but libxml2.2.dylib provides version 8.0.0
-
 Steven M. Boker574-339-0735 (cell/page/message)
 [EMAIL PROTECTED]  574-631-4941 (office)
 http://www.nd.edu/~sboker/ 574-631-8883 (fax)
 Dept. of Psychology, University of Notre Dame, Notre Dame, IN 46556
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html

-
 Steven M. Boker574-339-0735 (cell/page/message)
 [EMAIL PROTECTED]  574-631-4941 (office)
 http://www.nd.edu/~sboker/ 574-631-8883 (fax)
 Dept. of Psychology, University of Notre Dame, Notre Dame, IN 46556
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] [R-pkgs] updated package eba 1.4-0

2005-05-07 Thread Florian Wickelmaier
Dear all,

There is an updated version of the eba package for
elimination-by-aspects (EBA) choice models available on CRAN.

It features new functions for extracting and plotting
the residuals, for testing hypotheses on the parameters
(wald.test), and for comparing sub-samples (group.test).
The documentation has also been updated.
Any feedback is welcome.

Happy modeling!

Florian Wickelmaier

___
R-packages mailing list
[EMAIL PROTECTED]
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] General Question re R vs S-Plus

2005-05-07 Thread Liaw, Andy
 From: Jonathan Q.
 
 Coming up to speed on both R and S-Plus.  My access to S-Plus will end
 soon so I want to get up to speed on R. The big initial difference
 seems that R has only the command editor where S-Plus also has a
 windows interface.

What exactly do you mean by this?  What would you call Rgui.exe?
 
 My preference is to learn the language and the windows interface
 doesn't really do the trick.  My question is, if one uses the windows
 interface for some functions, is there a way to see what the
 equivalent code would be?  I have checked the manuals, help etc and
 can't seem to find a way.

That sounds more like a question for S-news than R-help...  In any case, my
impression is that commands linked to the S-PLUS GUI menus and buttons are
functions written for that.  You're not likely to learn much that will carry
over to R.

Andy

 
 Thanks
 
 
 
 -- 
 Jonathan
 [EMAIL PROTECTED]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 
 


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] help for bootstrap of backward stepwise logistic regression

2005-05-07 Thread Frank E Harrell Jr
Giuseppe Biondi Zoccai wrote:
I would like to perform a bootstrap validation of a backward stepwise
logistic regression analysis, but I am a beginner with R and I am not
sure of how to do it.
Is there anyone that can send me a sample file in tab format (that I
can modify in Excel by pasting my data) and the pertinent R algorithm?
Many thanks
Giuseppe 

You are asking for a lot and not saying that you are willing to read 
background material or help files.

To get you started, install the Design and Hmisc packages and look at 
help files for the following in Design: fastbw, lrm, validate.lrm, 
calibrate.lrm

Frank
--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html