Re: [R] Error in str(its-object)

2006-11-14 Thread Armstrong, Whit
I'll update ITS to include that signature.

Right now, the only signature for Arith is:
signature(e1=its,e2=its).

Thx,
Whit


 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Martin Maechler
 Sent: Tuesday, November 14, 2006 11:24 AM
 To: Stefan Albrecht
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] Error in str(its-object)
 
  StAl == Albrecht, Dr Stefan (AZ Private Equity 
 Partner) [EMAIL PROTECTED]
  on Tue, 14 Nov 2006 15:36:45 +0100 writes:
 
 StAl Dear all, on my Windows XP R 2.4.0 version with
 StAl Package its version 1.1.4 I have a problem with str()
 StAl applied on an its-object after a simple matrix
 StAl manipulation on the its object (see below).  I am not
 StAl sure, whether this a problem with my application, its
 StAl or str().
  
 I'd say mainly with its, and then with R internal arithmetic.
 str() actually reveals that the object you produce is not 
 ``valid'' anymore in a certain sense (see below).
 
 StAl .. But its object should be able to handle 
 simple matrix
 StAl multiplications, even if the result is a matrix.  Any
 StAl help is greatly appreciated.
  
 / 1 is not a simple multiplication. 
 But I agree that package
 its (which you failed to mention) should make sure that
   ' itsObj / 1 '
 
 should work -- which it does not.  Here is a reproducible 
 example script - extended from your transcript :
 
 --
 
 
 (mat - matrix(1:6, 2,3,

 dimnames=list(c(2003-01-01,2003-01-04),letters[1:3])))
 library(its)
 (im - its(mat))
 str(im)
 
 isS4(im)# TRUE, of course,  but ..
 isS4(im / 1)# FALSE !!!
 
 ## even though
 class(im / 1)
 ## shows
 ## [1] its
 ## attr(,package)
 ## [1] its
 
 ## and the reason comes from
 selectMethod(/, signature(e1 = its, e2 = numeric)) ## 
 - .Primitive(/)
 
 --
 
 
 So what happens is that the builtin arithmetic *does* work on 
 the .Data slot automatically -- as it should IIRC the green 
 book on this topic.
 
 What the builtin arithmetic *fails* to do, is keeping the 
 S4-object bit.
 -- I'll post a version of this to R-devel, since I think we
 should consider improving the current behavior here.
 
 For the current version of R, the maintainer of its should 
 really define Arith methods for signature(its, numeric) 
 and signature(numeric, its).
 
 Martin Maechler, ETH Zurich
 
 __
 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
 and provide commented, minimal, self-contained, reproducible code.
 




This e-mail message is intended only for the named recipient(s) above. It may 
contain confidential information. If you are not the intended recipient you are 
hereby notified that any dissemination, distribution or copying of this e-mail 
and any attachment(s) is strictly prohibited. If you have received this e-mail 
in error, please immediately notify the sender by replying to this e-mail and 
delete the message and any attachment(s) from your system. Thank you.

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] RODBC sqlQuery insert slow

2006-10-13 Thread Armstrong, Whit
Is there a reason why the data have to be inserted 1 row at a time?

Is it possible to insert the entire table at once?

sqlSave perhaps.



 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Bill Szkotnicki
 Sent: Friday, October 13, 2006 9:09 AM
 To: [EMAIL PROTECTED]
 Subject: [R] RODBC sqlQuery insert slow
 
 Hello,
 I am trying to insert a lot of data into a table using 
 windows R (2.3.1) and a mysql database via RODBC.
 First I read a file with read.csv and then form sql insert 
 statements for each row and execute the insert query one row 
 at a time. See the loop below.
 This turns out to be very slow.
 Can anyone please suggest a way to speed it up?
 
 Thanks, Bill
 
 # R code
 ntry=dim(ti)[1]
 date()
 nbefore=sqlQuery(channel,SELECT COUNT(*) FROM logger) for 
 (i in 1:ntry) { sql=INSERT INTO logger 
 (time,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10) VALUES(
 d1=strptime(ti[i,2],%d/%m/%y %H:%M:%S %p) 
 sql=paste(sql,',d1,' ) sql=paste(sql,,,ti[i,3] ) 
 sql=paste(sql,,,ti[i,4] ) sql=paste(sql,,,ti[i,5] ) 
 sql=paste(sql,,,ti[i,6] ) sql=paste(sql,,,ti[i,7] ) 
 sql=paste(sql,,,ti[i,8] ) sql=paste(sql,,,ti[i,9] )
 sql=paste(sql,,,ti[i,10])
 sql=paste(sql,,,ti[i,11])
 sql=paste(sql,,,ti[i,12])
 sql=paste(sql,) )
 #print(sql)
 sqlQuery(channel, sql)
 }
 nafter=sqlQuery(channel,SELECT COUNT(*) FROM logger) 
 nadded=nafter-nbefore;nadded
 date()
 
 __
 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
 and provide commented, minimal, self-contained, reproducible code.
 




This e-mail message is intended only for the named recipient(s) above. It may 
contain confidential information. If you are not the intended recipient you are 
hereby notified that any dissemination, distribution or copying of this e-mail 
and any attachment(s) is strictly prohibited. If you have received this e-mail 
in error, please immediately notify the sender by replying to this e-mail and 
delete the message and any attachment(s) from your system. Thank you.

__
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
and provide commented, minimal, self-contained, reproducible code.


[R] behavior of [-.foo

2006-09-22 Thread Armstrong, Whit
Can someone help me understand the following behavior of [- ?

If I define a simple class based on a matrix, the [- operation only
inserts into the first column:


 x - matrix(rnorm(10),nrow=5,ncol=2)
  class(x) - foo
 [-.foo - function(x, i, j, value) {
+ if(missing(i)) i - 1:nrow(x)
+ if(missing(j)) j - 1:ncol(x)
+ 
+ x - unclass(x)
+ x - NextMethod(.Generic)
+ class(x) - foo
+ x
+ }
 
 x[] - 100.0
 x
 [,1]   [,2]
[1,]  100 -0.1465296
[2,]  100 -0.2615796
[3,]  100 -0.8882629
[4,]  100 -0.2886357
[5,]  100 -0.9565273
attr(,class)
[1] foo

Based on the behavior of [- for a matrix, I would have thought that the
data for the whole object would be replaced.

for instance:


 y - matrix(rnorm(10),nrow=5,ncol=2)
 y
[,1]   [,2]
[1,] -0.55297049 -1.1896488
[2,]  0.06157438 -0.6628254
[3,] -0.28184208 -2.5260177
[4,]  0.61204398 -0.3492488
[5,]  0.43971216  1.8990789
 y[] - 100
 y
 [,1] [,2]
[1,]  100  100
[2,]  100  100
[3,]  100  100
[4,]  100  100
[5,]  100  100
 


Thanks,
Whit


code for above:

x - matrix(rnorm(10),nrow=5,ncol=2)
x
 class(x) - foo
[-.foo - function(x, i, j, value) {
if(missing(i)) i - 1:nrow(x)
if(missing(j)) j - 1:ncol(x)
x - unclass(x)
x - NextMethod(.Generic)
class(x) - foo
x
}
x[] - 100.0
x

 R.Version()
$platform
[1] i686-pc-linux-gnu

$arch
[1] i686

$os
[1] linux-gnu

$system
[1] i686, linux-gnu

$status
[1] 

$major
[1] 2

$minor
[1] 3.1

$year
[1] 2006

$month
[1] 06

$day
[1] 01

$`svn rev`
[1] 38247

$language
[1] R

$version.string
[1] Version 2.3.1 (2006-06-01)




This e-mail message is intended only for the named recipient(s) above. It may 
contain confidential information. If you are not the intended recipient you are 
hereby notified that any dissemination, distribution or copying of this e-mail 
and any attachment(s) is strictly prohibited. If you have received this e-mail 
in error, please immediately notify the sender by replying to this e-mail and 
delete the message and any attachment(s) from your system. Thank you.

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] RODBC on linux

2006-07-27 Thread Armstrong, Whit
Thanks, everyone.

I'll give freeTDS a try.

Cheers,
Whit


-Original Message-
From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 27, 2006 1:17 AM
To: Marc Schwartz
Cc: Armstrong, Whit; r-help@stat.math.ethz.ch
Subject: Re: [R] RODBC on linux

On Wed, 26 Jul 2006, Marc Schwartz wrote:

 On Wed, 2006-07-26 at 17:52 -0400, Armstrong, Whit wrote:
  Anyone out there using Linux RODBC and unixODBC to connect to a 
  Microsoft SQL server?
  
  If possible can someone post a sample .odbc.ini file?
  
  I saw a few discussions on the archives a few years ago, but no 
  config file details were available.
  
  Thanks,
  Whit
 
 Whit,
 
 Do you have a Linux ODBC driver for SQL Server?  unixODBC is simply 
 the driver manager, not the driver itself.
 
 MS does not offer (not surprisingly) an ODBC driver for Unix/Linux.
 There are resources available however and these might be helpful:
 
 http://www.sommarskog.se/mssql/unix.html
 
 Note that Easysoft provides (at a cost) an ODBC-ODBC bridge for 
 Unix/Linux platforms which supports ODBC connections to SQL Server:
 
 http://www.easysoft.com/products/data_access/odbc_odbc_bridge/index.ht
 ml

Several people have successfully used that, from the earliest days of
RODBC: I believe it was part of Michael Lapsley's motivation to write
RODBC.

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




This e-mail message is intended only for the named recipient(s) above. It may 
contain confidential information. If you are not the intended recipient you are 
hereby notified that any dissemination, distribution or copying of this e-mail 
and any attachment(s) is strictly prohibited. If you have received this e-mail 
in error, please immediately notify the sender by replying to this e-mail and 
delete the message and any attachment(s) from your system. Thank you.

__
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
and provide commented, minimal, self-contained, reproducible code.


[R] deparse(substitute(foo))

2006-07-27 Thread Armstrong, Whit
I see that plot.default uses deparse(substitute(x)) to extract the
character name of an argument and put it on the vertical axis.

Hence:
foo - 1:10
plot( foo )

will put the label foo on the vertical axis.

However, for a function that takes a ... list as an input, I can only
extract the first argument name:

x - 1:10
y - 10:20

foo - function(...) {
  print(deparse(substitute(...)))
}

foo(x,y)

returns: 

 foo(x,y) 
[1] x
 

and when I try to convert the list to a local variable and then extract
names, that doesn't work either:

x - 1:10 
y - 10:20 
 
foo - function(...) { 
 
x - list(...) 
print(deparse(substitute(names(x 
} 
 
foo(x,y) 

returns:

 foo(x,y)
[1] names(list(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), c(10, 11, 12, 13, 
[2] 14, 15, 16, 17, 18, 19, 20)))  
 


Can someone suggest a way to extract the variable names when they are
passed as a list via ... ?

Thanks,
Whit




This e-mail message is intended only for the named recipient(s) above. It may 
contain confidential information. If you are not the intended recipient you are 
hereby notified that any dissemination, distribution or copying of this e-mail 
and any attachment(s) is strictly prohibited. If you have received this e-mail 
in error, please immediately notify the sender by replying to this e-mail and 
delete the message and any attachment(s) from your system. Thank you.

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] deparse(substitute(foo))

2006-07-27 Thread Armstrong, Whit
That works perfectly.

Thanks,
Whit
 

-Original Message-
From: Marc Schwartz [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 27, 2006 8:41 AM
To: Armstrong, Whit
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] deparse(substitute(foo))

On Thu, 2006-07-27 at 08:18 -0400, Armstrong, Whit wrote:
 I see that plot.default uses deparse(substitute(x)) to extract the 
 character name of an argument and put it on the vertical axis.
 
 Hence:
 foo - 1:10
 plot( foo )
 
 will put the label foo on the vertical axis.
 
 However, for a function that takes a ... list as an input, I can 
 only extract the first argument name:
 
 x - 1:10
 y - 10:20
 
 foo - function(...) {
   print(deparse(substitute(...)))
 }
 
 foo(x,y)
 
 returns: 
 
  foo(x,y)
 [1] x
  
 
 and when I try to convert the list to a local variable and then 
 extract names, that doesn't work either:
 
 x - 1:10
 y - 10:20
  
 foo - function(...) {
  
 x - list(...) 
 print(deparse(substitute(names(x
 }
  
 foo(x,y)
 
 returns:
 
  foo(x,y)
 [1] names(list(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), c(10, 11, 12, 13, 
 [2] 14, 15, 16, 17, 18, 19, 20)))  
  
 
 
 Can someone suggest a way to extract the variable names when they are 
 passed as a list via ... ?
 
 Thanks,
 Whit

Try this:

x - 1:10
y - 10:20 
 
foo - function(...) { 
   sapply(match.call()[-1], deparse)
} 


 foo(x, y)
[1] x y


HTH,

Marc Schwartz





This e-mail message is intended only for the named recipient(s) above. It may 
contain confidential information. If you are not the intended recipient you are 
hereby notified that any dissemination, distribution or copying of this e-mail 
and any attachment(s) is strictly prohibited. If you have received this e-mail 
in error, please immediately notify the sender by replying to this e-mail and 
delete the message and any attachment(s) from your system. Thank you.

__
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
and provide commented, minimal, self-contained, reproducible code.


[R] FW: RODBC on linux

2006-07-27 Thread Armstrong, Whit
Thanks again for everyone's help.  I have a successful configuration.

I used the ODBC-combined configuration which is documented here:
http://freetds.org/userguide/odbcombo.htm

here are the config files residing in my home dir:

-bash-2.05b$ cat .freetds.conf
[global]
tds version = 7.0

[QAI]
host = Mqa3.xxx.yyy.com
port = 1433
-bash-2.05b$ 


-bash-2.05b$ cat .odbc.ini
[ODBC Data Sources]
 QAIdsn = QAI database

[QAIdsn]
Driver  = /usr/local/freetds-0.64/lib/libtdsodbc.so
Description = QAI database
Trace   = No
Servername  = QAI
Database= qai

[Default]
Driver  = /usr/local/freetds-0.64/lib/libtdsodbc.so

-bash-2.05b$ 


Cheers,
Whit




This e-mail message is intended only for the named recipient(s) above. It may 
contain confidential information. If you are not the intended recipient you are 
hereby notified that any dissemination, distribution or copying of this e-mail 
and any attachment(s) is strictly prohibited. If you have received this e-mail 
in error, please immediately notify the sender by replying to this e-mail and 
delete the message and any attachment(s) from your system. Thank you.

__
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
and provide commented, minimal, self-contained, reproducible code.


[R] RODBC on linux

2006-07-26 Thread Armstrong, Whit
Anyone out there using Linux RODBC and unixODBC to connect to a
Microsoft SQL server?

If possible can someone post a sample .odbc.ini file?

I saw a few discussions on the archives a few years ago, but no config
file details were available.

Thanks,
Whit





This e-mail message is intended only for the named recipient(s) above. It may 
contain confidential information. If you are not the intended recipient you are 
hereby notified that any dissemination, distribution or copying of this e-mail 
and any attachment(s) is strictly prohibited. If you have received this e-mail 
in error, please immediately notify the sender by replying to this e-mail and 
delete the message and any attachment(s) from your system. Thank you.


[[alternative HTML version deleted]]

__
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
and provide commented, minimal, self-contained, reproducible code.