Bill.Venables | 1 May 2005 04:28
Picon
Picon
Favicon

[Rd] RE: as.numeric method for objects of class "difftime"

I had a couple of private replies to the message below, all very
supportive of the idea.  I see that where I should have looked first is
at the function difftime, the constructor (which will hardly ever be
used except by people who know about its separate existence from
Ops.POSIXt).

Thus encouraged I formally propose that a method for as.numeric be
provided that will not break existing code, but will issue a warning if
people convert from difftime to numeric without specifying a time unit
to which the resulting numerical quantity will implicitly refer.

This is the simplest acceptable solution I could think of.  The code I
propose is as follows:

###
### S3 method for objects of class 'difftime'
###
as.double.difftime <- function(x, units = attr(x, "units"), ...) {
  if(missing(units)) {
    warning('No time units specified for conversion to numeric.\n"',
             units, '" has been assumed.')
    return(as.vector(x))
  }
  cfToSecs <- cumprod(c(secs = 1, mins = 60, hours = 60, days = 24,
weeks = 7))
  if(!is.element(units, names(cfToSecs)))
    stop("Unknown time units. Acceptable time units are\n\t",
         paste('"', names(cfToSecs), '", ', sep = "", collapse = ""),
         "only.")
  as.vector(x) * (cfToSecs[attr(x, "units")]/cfToSecs[units])
(Continue reading)

Bill.Venables | 1 May 2005 04:39
Picon
Picon
Favicon

[Rd] heads and tails

Using head and tail recently, it occurred to me that it 
would be very handy to have the unix convention more 
fully, namely to allow negative values for "n" to 
signify omission of lines rather than inclusion.

Thus head(X, -1) would mean "all but the last line" and
	tail(X, -1) would mean "all but the first line".

Private correspondence has made me aware that this idea 
is not new, and that there is no organised opposition to 
it.  Moreover the code changes needed are trivial (and 
I am happy to supply them if people want...) and no 
presently working code would be broken.

Has the time for this admittedly minor but harmless 
convenience feature come at last?

Bill Venables, 
CMIS, CSIRO Laboratories, 
PO Box 120, Cleveland, Qld. 4163
AUSTRALIA
Phone:  +61 7 3826 7251  
Fax:    +61 7 3826 7304
Mobile: +61 4 1963 4642
Home:   +61 7 3286 7700
mailto:Bill.Venables <at> csiro.au
http://www.cmis.csiro.au/bill.venables/

______________________________________________
R-devel <at> stat.math.ethz.ch mailing list
(Continue reading)

Prof Brian Ripley | 1 May 2005 06:40
Picon
Picon
Favicon

Re: [Rd] RE: as.numeric method for objects of class "difftime"

I am very surprised that people would expect as.numeric to do something 
meaningful on time differences (or times, come to that).  Perhaps the best 
thing is to stop it altogether.

The selection of "auto" was the best for the original purpose: people in 
general do not want a difference of 3 days expressed in seconds.  The 
problems only arise if the result is unclassed, and I still do not 
understand why that is a reasonable thing to do.

On Sun, 1 May 2005 Bill.Venables <at> csiro.au wrote:

> I had a couple of private replies to the message below, all very
> supportive of the idea.  I see that where I should have looked first is
> at the function difftime, the constructor (which will hardly ever be
> used except by people who know about its separate existence from
> Ops.POSIXt).
>
> Thus encouraged I formally propose that a method for as.numeric be
> provided that will not break existing code, but will issue a warning if
> people convert from difftime to numeric without specifying a time unit
> to which the resulting numerical quantity will implicitly refer.
>
> This is the simplest acceptable solution I could think of.  The code I
> propose is as follows:
>
> ###
> ### S3 method for objects of class 'difftime'
> ###
> as.double.difftime <- function(x, units = attr(x, "units"), ...) {
>  if(missing(units)) {
(Continue reading)

Bill.Venables | 1 May 2005 08:32
Picon
Picon
Favicon

RE: [Rd] RE: as.numeric method for objects of class "difftime"

Brian,

: -----Original Message-----
: From: Prof Brian Ripley [mailto:ripley <at> stats.ox.ac.uk] 
: Sent: Sunday, 1 May 2005 2:41 PM
: To: Venables, Bill (CMIS, Cleveland)
: Cc: r-devel <at> stat.math.ethz.ch
: Subject: Re: [Rd] RE: as.numeric method for objects of class 
: "difftime"
: 
: 
: I am very surprised that people would expect as.numeric to do 
: something 
: meaningful on time differences (or times, come to that).  
: Perhaps the best 
: thing is to stop it altogether.

This would enforce one particular interpretation that may 
inhibit legitimate but unanticipated alternative uses.

: 
: The selection of "auto" was the best for the original 
: purpose: people in 
: general do not want a difference of 3 days expressed in seconds.  The 
: problems only arise if the result is unclassed, and I still do not 
: understand why that is a reasonable thing to do.

No, they may not want the answer in seconds, but if they have
a vector of time differences that includes zero they'll get
them all in seconds anyway.
(Continue reading)

Ted.Harding | 1 May 2005 09:07
Picon
Picon

RE: [Rd] heads and tails

On 01-May-05 Bill.Venables <at> csiro.au wrote:
> Using head and tail recently, it occurred to me that it 
> would be very handy to have the unix convention more 
> fully, namely to allow negative values for "n" to 
> signify omission of lines rather than inclusion.
> 
> Thus head(X, -1) would mean "all but the last line" and
>       tail(X, -1) would mean "all but the first line".
> 
> Private correspondence has made me aware that this idea 
> is not new, and that there is no organised opposition to 
> it.  Moreover the code changes needed are trivial (and 
> I am happy to supply them if people want...) and no 
> presently working code would be broken.
> 
> Has the time for this admittedly minor but harmless 
> convenience feature come at last?

I would agree that this seems desirable! As well as the
"trivial code changes needed", it also needs a probably
trivial switch of viewpoint from

  "n: size for the resulting object"

to

  "n: <whatever best encapsulates the above>"

Best wishes,
Ted.
(Continue reading)

Patrick Burns | 1 May 2005 13:24
Picon

Re: [Rd] formals assignment now strips attributres

Peter Dalgaard wrote:

>Patrick Burns <pburns <at> pburns.seanet.com> writes:
>
>  
>
>>But the buglet gets more aggressive if you edit the function:
>>
>> > fjj <- function() x
>> > formals(fjj) <- list(x=c(a=2, b=4))
>> > fjj
>>function (x = c(2, 4))
>>x
>> > fjj()
>>a b
>>2 4
>> > fix(fjj) # do nothing but save
>> > fjj()
>>[1] 2 4
>>
>>I'm quite sure that I wouldn't have noticed if my real function were
>>not broken.
>>
>>Now I know that my functions will work if I assign the formals after I
>>edit the
>>function -- even though they look like they shouldn't work.
>>    
>>
>
>You did invite trouble by creating and subsequently a function that
(Continue reading)

Peter Dalgaard | 1 May 2005 20:51
Picon
Favicon

Re: [Rd] formals assignment now strips attributres

Patrick Burns <pburns <at> pburns.seanet.com> writes:

> Peter Dalgaard wrote:
...
> >>fjj <- function() x
> >>formals(fjj) <- list(x=quote(c(a=2, b=4)))
> >>fjj()
> >>
> >a b
> >2 4
> >
> >>fix(fjj)
> >>fjj()
> >>
> >a b
> >2 4
> >
> 
> But the point of using 'formals' in the first place is to get a
> function that is self-contained.  The real application is more
> like:
> 
> formals(fjj) <- list(x = an_object)
> 
> I want 'fjj' to work even when 'an_object' is nowhere to be
> found.
> 
> 'formals' worked as (I) expected in versions 1.8.0
> through 1.9.1 at least. Pat

(Continue reading)

Dan Davison | 1 May 2005 22:22
Favicon

[Rd] dll symbol loading: possible bug

Dear R-devel,

I think the following describes a bug in R. It seems to be associated with 
dyn.load() and/or something that happens at start-up. I have not filed a 
bug report yet (because I doubt my ability to rule out other explanations) 
but would happily do so if requested.

Observation:

If two dlls are loaded as a result of dyn.load() calls in .Rprofile, 
subsequent calls to dyn.load() issued at the R prompt result in loss of 
symbol names in the other dll (although not until one tries 
re-dyn.load()ing the second dll; re-dyn.load()ing just one of them works 
OK). This has occurred only since installing R 2.1.0.

Example:

Contents of file dummy1.c:
---------------------------
#include <R.h>
#include <Rdefines.h>
SEXP dummy1() {
     Rprintf("this is dummy1() in C\n") ;
     return R_NilValue ;
}
---------------------------

Contents of file dummy2.c
-------------------------
#include <R.h>
(Continue reading)

difusiometer | 1 May 2005 23:07

[Rd] Help me! (PR#7828)

This is a multi-part message in MIME format.

------=_NextPart_000_0000_EEA7162E.AC0B6770
Content-Type: multipart/alternative;
    boundary="----=_NextPart_001_0001_0C6163AA.F6422C7C"

------=_NextPart_001_0001_0C6163AA.F6422C7C
Content-Type: text/plain;
    charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

  Hola, Alejandra!  your board sunburned important. where collar held her
tenderly? lazily paper stood this bit of voice. we bethought her material
lip of horse. gracefully. his wide space around cause, which forbore round,
yellow cough. Nikhil misthought that bitter plate. it dighted Brycen when
meant them Nicole! i begot loud basket, that beset merrily... excepting
cushion met receipt, tongue unsaid behind your size but necessary garden:
 she spent her past crack to their wrong cloth, who withdrew unexpectedly.
my complex decision prepaid as our pin; thick, rough neck. low dictionary
chief overate, he ran not, merrily, violently. my short prison shook before
your mist; natural, simple wheel. it typecast some private net beyond my
loose paint, who overleaped madly. he foretold her good. he rose beautiful
dollar, which leaped doubtfully...  stuck our clean color,
Jenifer DAVIDSON.  

------=_NextPart_001_0001_0C6163AA.F6422C7C
Content-Type: text/html;
    charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

(Continue reading)

D0c | 2 May 2005 08:55
Picon

[Rd] Re: Calling R functions from Java

Hey guys thanks for the help. I found Rserve to be a solution i can
work with. i'll just use the JRClient to connect to Rserve. However i
have another problem. How can i get a nice graph from Rserve using
JRCLient using the plot() function?
Or for that matter a simple summary() of a dataset to be printed on
screen (eg JOptionPane)?

All this is using a java front end btw.

On 4/29/05, D0c <kanglin <at> gmail.com> wrote:
> Hey guys,
> I got a java gui app which loads up data into a table. How can i use R
> to perform statistical functions on the data in the table?
> 
> P.S My question is not particularly geared towards Java coding, but
> more towards allowing R functionality within Java.
>

______________________________________________
R-devel <at> stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Gmane