Re: [Rd] length of `...`

2018-05-08 Thread Hervé Pagès

Thanks Martin for the clarifications.  H.

On 05/04/2018 06:02 AM, Martin Maechler wrote:

Hervé Pagès 
 on Thu, 3 May 2018 08:55:20 -0700 writes:


 > Hi,
 > It would be great if one of the experts could comment on the
 > difference between Hadley's dotlength and ...length? The fact
 > that someone bothered to implement a new primitive for that
 > when there seems to be a very simple and straightforward R-only
 > solution suggests that there might be some gotchas/pitfalls with
 > the R-only solution.

Namely


dotlength <- function(...) nargs()



(This is subtly different from calling nargs() directly as it will
only count the elements in ...)



Hadley



Well,  I was the "someone".  In the past I had seen (and used myself)

length(list(...))

and of course that was not usable.
I knew of some substitute() / match.call() tricks [but I think
did not know Bill's cute substitute(...()) !] at the time, but
found them too esoteric.

Aditionally and importantly,  ...length()  and  ..elt(n)  were
developed  "synchronously",  and the R-substitutes for ..elt()
definitely are less trivial (I did not find one at the time), as
Duncan's example to Bill's proposal has shown, so I had looked
at .Primitive() solutions of both.

In hindsight I should have asked here for advice,  but may at
the time I had been a bit frustrated by the results of some of
my RFCs ((nothing specific in mind !))

But __if__ there's really no example where current (3.5.0 and newer)

   ...length()

differs from Hadley's  dotlength()
I'd vert happy to replace ...length 's C based definition by
Hadley's beautiful minimal solution.

Martin


 > On 05/03/2018 08:34 AM, Hadley Wickham wrote:
 >> On Thu, May 3, 2018 at 8:18 AM, Duncan Murdoch 
 wrote:
 >>> On 03/05/2018 11:01 AM, William Dunlap via R-devel wrote:
 
  In R-3.5.0 you can use ...length():
  > f <- function(..., n) ...length()
  > f(stop("one"), stop("two"), stop("three"), n=7)
  [1] 3
 
  Prior to that substitute() is the way to go
  > g <- function(..., n) length(substitute(...()))
  > g(stop("one"), stop("two"), stop("three"), n=7)
  [1] 3
 
  R-3.5.0 also has the ...elt(n) function, which returns
  the evaluated n'th entry in ... , without evaluating the
  other ... entries.
  > fn <- function(..., n) ...elt(n)
  > fn(stop("one"), 3*5, stop("three"), n=2)
  [1] 15
 
  Prior to 3.5.0, eval the appropriate component of the output
  of substitute() in the appropriate environment:
  > gn <- function(..., n) {
  +   nthExpr <- substitute(...())[[n]]
  +   eval(nthExpr, envir=parent.frame())
  + }
  > gn(stop("one"), environment(), stop("two"), n=2)
  
 
 >>>
 >>> Bill, the last of these doesn't quite work, because ... can be passed 
down
 >>> through a string of callers.  You don't necessarily want to evaluate 
it in
 >>> the parent.frame().  For example:
 >>>
 >>> x <- "global"
 >>> f <- function(...) {
 >>> x <- "f"
 >>> g(...)
 >>> }
 >>> g <- function(...) {
 >>> firstExpr <- substitute(...())[[1]]
 >>> c(list(...)[[1]], eval(firstExpr, envir = parent.frame()))
 >>> }
 >>>
 >>> Calling g(x) correctly prints "global" twice, but calling f(x) 
incorrectly
 >>> prints
 >>>
 >>> [1] "global" "f"
 >>>
 >>> You can get the first element of ... without evaluating the rest using 
..1,
 >>> but I don't know a way to do this for general n in pre-3.5.0 base R.
 >>
 >> If you don't mind using a package:
 >>
 >> # works with R 3.1 and up
 >> library(rlang)
 >>
 >> x <- "global"
 >> f <- function(...) {
 >> x <- "f"
 >> g(...)
 >> }
 >> g <- function(...) {
 >> dots <- enquos(...)
 >> eval_tidy(dots[[1]])
 >> }
 >>
 >> f(x, stop("!"))
 >> #> [1] "global"
 >> g(x, stop("!"))
 >> #> [1] "global"
 >>
 >> Hadley
 >>

 > --
 > Hervé Pagès

 > Program in Computational Biology
 > Division of Public Health Sciences
 > Fred Hutchinson Cancer Research Center
 > 1100 Fairview Ave. N, M1-B514
 > P.O. Box 19024
 > Seattle, WA 98109-1024

 > E-mail: hpa...@fredhutch.org
 > Phone:  (206) 667-5791
 > Fax:(206) 667-1319

 > __
 > R-devel@r-project.org mailing list
 > 
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Ddevel&d=DwIDAw&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=BGlRjScM4h5whbLQ891iVxeMRA4PY37vwG3cnC5kuDI&s=_XZhh9pIVv0VBjUYXBgW39dss7YCGQE3XCArLMDfvDo&e=



--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M

Re: [Rd] length of `...`

2018-05-06 Thread Suharto Anggono Suharto Anggono via R-devel
Does anyone notice r-devel thread "stopifnot() does not stop at first non-TRUE 
argument" starting with 
https://stat.ethz.ch/pipermail/r-devel/2017-May/074179.html ?

I have mentioned
(function(...)nargs())(...)
in https://stat.ethz.ch/pipermail/r-devel/2017-May/074294.html .

Something like ..elt(n) is switch(n, ...) . I have mentioned it in 
https://stat.ethz.ch/pipermail/r-devel/2017-May/074270.html . See also response 
in https://stat.ethz.ch/pipermail/r-devel/2017-May/074282.html .

By the way, because 'stopifnot' in R 3.5.0 contains argument other than '...', 
it might be better to use
match.call(expand.dots=FALSE)$...
instead of
match.call()[-1L] .

---
> Joris Meys 
> on Fri, 4 May 2018 15:37:27 +0200 writes:

> The one difference I see, is the necessity to pass the dots to the 
function
> dotlength :

> dotlength <- function(...) nargs()

> myfun <- function(..., someArg = 1){
> n1 <- ...length()
> n2 <- dotlength()
> n3 <- dotlength(...)
> return(c(n1, n2, n3))
> }

> myfun(stop("A"), stop("B"), someArg = stop("c"))

> I don't really see immediately how one can replace the C definition with
> Hadley's solution without changing how the function has to be used.

Yes, of course:  nargs() can only be applied to the function inside
which it is used, and hence  n2 <- dotlength()  must therefore be 0.
Thank you, Joris

> Personally, I have no preference over the use, but changing it now would
> break code dependent upon ...length() imho. Unless I'm overlooking
> something of course.

Yes.  OTOH, as it's been very new, one could consider
deprecating it, and advertize say,  .length(...) instead of ...length()
[yes, in spite of the fact that the pure-R solution is slower
 than a primitive; both are fast enough for all purposes]

But such a deprecation cycle typically entails time more writing
etc, not something I've time for just these days.

Martin


> On Fri, May 4, 2018 at 3:02 PM, Martin Maechler 
> wrote:

>> > Hervé Pagès 
>> > on Thu, 3 May 2018 08:55:20 -0700 writes:
>> 
>> > Hi,
>> > It would be great if one of the experts could comment on the
>> > difference between Hadley's dotlength and ...length? The fact
>> > that someone bothered to implement a new primitive for that
>> > when there seems to be a very simple and straightforward R-only
>> > solution suggests that there might be some gotchas/pitfalls with
>> > the R-only solution.
>> 
>> Namely
>> 
>> > dotlength <- function(...) nargs()
>> 
>> > (This is subtly different from calling nargs() directly as it will
>> > only count the elements in ...)
>> 
>> > Hadley
>> 
>> 
>> Well,  I was the "someone".  In the past I had seen (and used myself)
>> 
>> length(list(...))
>> 
>> and of course that was not usable.
>> I knew of some substitute() / match.call() tricks [but I think
>> did not know Bill's cute substitute(...()) !] at the time, but
>> found them too esoteric.
>> 
>> Aditionally and importantly,  ...length()  and  ..elt(n)  were
>> developed  "synchronously",  and the R-substitutes for ..elt()
>> definitely are less trivial (I did not find one at the time), as
>> Duncan's example to Bill's proposal has shown, so I had looked
>> at .Primitive() solutions of both.
>> 
>> In hindsight I should have asked here for advice,  but may at
>> the time I had been a bit frustrated by the results of some of
>> my RFCs ((nothing specific in mind !))
>> 
>> But __if__ there's really no example where current (3.5.0 and newer)
>> 
>> ...length()
>> 
>> differs from Hadley's  dotlength()
>> I'd vert happy to replace ...length 's C based definition by
>> Hadley's beautiful minimal solution.
>> 
>> Martin

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


Re: [Rd] length of `...`

2018-05-04 Thread Martin Maechler
> Joris Meys 
> on Fri, 4 May 2018 15:37:27 +0200 writes:

> The one difference I see, is the necessity to pass the dots to the 
function
> dotlength :

> dotlength <- function(...) nargs()

> myfun <- function(..., someArg = 1){
> n1 <- ...length()
> n2 <- dotlength()
> n3 <- dotlength(...)
> return(c(n1, n2, n3))
> }

> myfun(stop("A"), stop("B"), someArg = stop("c"))

> I don't really see immediately how one can replace the C definition with
> Hadley's solution without changing how the function has to be used.

Yes, of course:  nargs() can only be applied to the function inside
which it is used, and hence  n2 <- dotlength()  must therefore be 0.
Thank you, Joris

> Personally, I have no preference over the use, but changing it now would
> break code dependent upon ...length() imho. Unless I'm overlooking
> something of course.

Yes.  OTOH, as it's been very new, one could consider
deprecating it, and advertize say,  .length(...) instead of ...length()
[yes, in spite of the fact that the pure-R solution is slower
 than a primitive; both are fast enough for all purposes]
 
But such a deprecation cycle typically entails time more writing
etc, not something I've time for just these days.

Martin


> On Fri, May 4, 2018 at 3:02 PM, Martin Maechler 

> wrote:

>> > Hervé Pagès 
>> > on Thu, 3 May 2018 08:55:20 -0700 writes:
>> 
>> > Hi,
>> > It would be great if one of the experts could comment on the
>> > difference between Hadley's dotlength and ...length? The fact
>> > that someone bothered to implement a new primitive for that
>> > when there seems to be a very simple and straightforward R-only
>> > solution suggests that there might be some gotchas/pitfalls with
>> > the R-only solution.
>> 
>> Namely
>> 
>> > dotlength <- function(...) nargs()
>> 
>> > (This is subtly different from calling nargs() directly as it will
>> > only count the elements in ...)
>> 
>> > Hadley
>> 
>> 
>> Well,  I was the "someone".  In the past I had seen (and used myself)
>> 
>> length(list(...))
>> 
>> and of course that was not usable.
>> I knew of some substitute() / match.call() tricks [but I think
>> did not know Bill's cute substitute(...()) !] at the time, but
>> found them too esoteric.
>> 
>> Aditionally and importantly,  ...length()  and  ..elt(n)  were
>> developed  "synchronously",  and the R-substitutes for ..elt()
>> definitely are less trivial (I did not find one at the time), as
>> Duncan's example to Bill's proposal has shown, so I had looked
>> at .Primitive() solutions of both.
>> 
>> In hindsight I should have asked here for advice,  but may at
>> the time I had been a bit frustrated by the results of some of
>> my RFCs ((nothing specific in mind !))
>> 
>> But __if__ there's really no example where current (3.5.0 and newer)
>> 
>> ...length()
>> 
>> differs from Hadley's  dotlength()
>> I'd vert happy to replace ...length 's C based definition by
>> Hadley's beautiful minimal solution.
>> 
>> Martin

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


Re: [Rd] length of `...`

2018-05-04 Thread Joris Meys
The one difference I see, is the necessity to pass the dots to the function
dotlength :

dotlength <- function(...) nargs()

myfun <- function(..., someArg = 1){
  n1 <- ...length()
  n2 <- dotlength()
  n3 <- dotlength(...)
  return(c(n1, n2, n3))
}

myfun(stop("A"), stop("B"), someArg = stop("c"))

I don't really see immediately how one can replace the C definition with
Hadley's solution without changing how the function has to be used.
Personally, I have no preference over the use, but changing it now would
break code dependent upon ...length() imho. Unless I'm overlooking
something of course.

Cheers
Joris


On Fri, May 4, 2018 at 3:02 PM, Martin Maechler 
wrote:

> > Hervé Pagès 
> > on Thu, 3 May 2018 08:55:20 -0700 writes:
>
> > Hi,
> > It would be great if one of the experts could comment on the
> > difference between Hadley's dotlength and ...length? The fact
> > that someone bothered to implement a new primitive for that
> > when there seems to be a very simple and straightforward R-only
> > solution suggests that there might be some gotchas/pitfalls with
> > the R-only solution.
>
> Namely
>
> > dotlength <- function(...) nargs()
>
> > (This is subtly different from calling nargs() directly as it will
> > only count the elements in ...)
>
> > Hadley
>
>
> Well,  I was the "someone".  In the past I had seen (and used myself)
>
>length(list(...))
>
> and of course that was not usable.
> I knew of some substitute() / match.call() tricks [but I think
> did not know Bill's cute substitute(...()) !] at the time, but
> found them too esoteric.
>
> Aditionally and importantly,  ...length()  and  ..elt(n)  were
> developed  "synchronously",  and the R-substitutes for ..elt()
> definitely are less trivial (I did not find one at the time), as
> Duncan's example to Bill's proposal has shown, so I had looked
> at .Primitive() solutions of both.
>
> In hindsight I should have asked here for advice,  but may at
> the time I had been a bit frustrated by the results of some of
> my RFCs ((nothing specific in mind !))
>
> But __if__ there's really no example where current (3.5.0 and newer)
>
>   ...length()
>
> differs from Hadley's  dotlength()
> I'd vert happy to replace ...length 's C based definition by
> Hadley's beautiful minimal solution.
>
> Martin
>
>
> > On 05/03/2018 08:34 AM, Hadley Wickham wrote:
> >> On Thu, May 3, 2018 at 8:18 AM, Duncan Murdoch <
> murdoch.dun...@gmail.com> wrote:
> >>> On 03/05/2018 11:01 AM, William Dunlap via R-devel wrote:
> 
>  In R-3.5.0 you can use ...length():
>  > f <- function(..., n) ...length()
>  > f(stop("one"), stop("two"), stop("three"), n=7)
>  [1] 3
> 
>  Prior to that substitute() is the way to go
>  > g <- function(..., n) length(substitute(...()))
>  > g(stop("one"), stop("two"), stop("three"), n=7)
>  [1] 3
> 
>  R-3.5.0 also has the ...elt(n) function, which returns
>  the evaluated n'th entry in ... , without evaluating the
>  other ... entries.
>  > fn <- function(..., n) ...elt(n)
>  > fn(stop("one"), 3*5, stop("three"), n=2)
>  [1] 15
> 
>  Prior to 3.5.0, eval the appropriate component of the output
>  of substitute() in the appropriate environment:
>  > gn <- function(..., n) {
>  +   nthExpr <- substitute(...())[[n]]
>  +   eval(nthExpr, envir=parent.frame())
>  + }
>  > gn(stop("one"), environment(), stop("two"), n=2)
>  
> 
> >>>
> >>> Bill, the last of these doesn't quite work, because ... can be
> passed down
> >>> through a string of callers.  You don't necessarily want to
> evaluate it in
> >>> the parent.frame().  For example:
> >>>
> >>> x <- "global"
> >>> f <- function(...) {
> >>> x <- "f"
> >>> g(...)
> >>> }
> >>> g <- function(...) {
> >>> firstExpr <- substitute(...())[[1]]
> >>> c(list(...)[[1]], eval(firstExpr, envir = parent.frame()))
> >>> }
> >>>
> >>> Calling g(x) correctly prints "global" twice, but calling f(x)
> incorrectly
> >>> prints
> >>>
> >>> [1] "global" "f"
> >>>
> >>> You can get the first element of ... without evaluating the rest
> using ..1,
> >>> but I don't know a way to do this for general n in pre-3.5.0 base
> R.
> >>
> >> If you don't mind using a package:
> >>
> >> # works with R 3.1 and up
> >> library(rlang)
> >>
> >> x <- "global"
> >> f <- function(...) {
> >> x <- "f"
> >> g(...)
> >> }
> >> g <- function(...) {
> >> dots <- enquos(...)
> >> eval_tidy(dots[[1]])
> >> }
> >>
> >> f(x, stop("!"))
> >> #> [1] "global"
> >> g(x, stop("!"))
> >> #> [1] "global"
> >>
> >> Hadley
> >>
>
> > --
> > Hervé Pagès
>
> > Program in Computational Biology
> > D

Re: [Rd] length of `...`

2018-05-04 Thread Martin Maechler
> Hervé Pagès 
> on Thu, 3 May 2018 08:55:20 -0700 writes:

> Hi,
> It would be great if one of the experts could comment on the
> difference between Hadley's dotlength and ...length? The fact
> that someone bothered to implement a new primitive for that
> when there seems to be a very simple and straightforward R-only
> solution suggests that there might be some gotchas/pitfalls with
> the R-only solution.

Namely

> dotlength <- function(...) nargs()

> (This is subtly different from calling nargs() directly as it will
> only count the elements in ...)

> Hadley


Well,  I was the "someone".  In the past I had seen (and used myself)

   length(list(...))   

and of course that was not usable.
I knew of some substitute() / match.call() tricks [but I think
did not know Bill's cute substitute(...()) !] at the time, but
found them too esoteric.

Aditionally and importantly,  ...length()  and  ..elt(n)  were
developed  "synchronously",  and the R-substitutes for ..elt()
definitely are less trivial (I did not find one at the time), as
Duncan's example to Bill's proposal has shown, so I had looked
at .Primitive() solutions of both.

In hindsight I should have asked here for advice,  but may at
the time I had been a bit frustrated by the results of some of
my RFCs ((nothing specific in mind !))

But __if__ there's really no example where current (3.5.0 and newer)

  ...length()

differs from Hadley's  dotlength()
I'd vert happy to replace ...length 's C based definition by
Hadley's beautiful minimal solution.

Martin


> On 05/03/2018 08:34 AM, Hadley Wickham wrote:
>> On Thu, May 3, 2018 at 8:18 AM, Duncan Murdoch 
 wrote:
>>> On 03/05/2018 11:01 AM, William Dunlap via R-devel wrote:
 
 In R-3.5.0 you can use ...length():
 > f <- function(..., n) ...length()
 > f(stop("one"), stop("two"), stop("three"), n=7)
 [1] 3
 
 Prior to that substitute() is the way to go
 > g <- function(..., n) length(substitute(...()))
 > g(stop("one"), stop("two"), stop("three"), n=7)
 [1] 3
 
 R-3.5.0 also has the ...elt(n) function, which returns
 the evaluated n'th entry in ... , without evaluating the
 other ... entries.
 > fn <- function(..., n) ...elt(n)
 > fn(stop("one"), 3*5, stop("three"), n=2)
 [1] 15
 
 Prior to 3.5.0, eval the appropriate component of the output
 of substitute() in the appropriate environment:
 > gn <- function(..., n) {
 +   nthExpr <- substitute(...())[[n]]
 +   eval(nthExpr, envir=parent.frame())
 + }
 > gn(stop("one"), environment(), stop("two"), n=2)
 
 
>>> 
>>> Bill, the last of these doesn't quite work, because ... can be passed 
down
>>> through a string of callers.  You don't necessarily want to evaluate it 
in
>>> the parent.frame().  For example:
>>> 
>>> x <- "global"
>>> f <- function(...) {
>>> x <- "f"
>>> g(...)
>>> }
>>> g <- function(...) {
>>> firstExpr <- substitute(...())[[1]]
>>> c(list(...)[[1]], eval(firstExpr, envir = parent.frame()))
>>> }
>>> 
>>> Calling g(x) correctly prints "global" twice, but calling f(x) 
incorrectly
>>> prints
>>> 
>>> [1] "global" "f"
>>> 
>>> You can get the first element of ... without evaluating the rest using 
..1,
>>> but I don't know a way to do this for general n in pre-3.5.0 base R.
>> 
>> If you don't mind using a package:
>> 
>> # works with R 3.1 and up
>> library(rlang)
>> 
>> x <- "global"
>> f <- function(...) {
>> x <- "f"
>> g(...)
>> }
>> g <- function(...) {
>> dots <- enquos(...)
>> eval_tidy(dots[[1]])
>> }
>> 
>> f(x, stop("!"))
>> #> [1] "global"
>> g(x, stop("!"))
>> #> [1] "global"
>> 
>> Hadley
>> 

> -- 
> Hervé Pagès

> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024

> E-mail: hpa...@fredhutch.org
> Phone:  (206) 667-5791
> Fax:(206) 667-1319

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


Re: [Rd] length of `...`

2018-05-03 Thread Michel Lang
FWIW, there is also a backport of `...length()` for R versions >3.0.0
in my package backports (shameless self promotion):
.


2018-05-03 19:41 GMT+02:00 peter dalgaard :
>
>
>> On 3 May 2018, at 19:23 , Hadley Wickham  wrote:
>>
>> Maybe just get(paste0("..", n)) ?
>>
>> Hadley
>
> Maybe not. These things are slippery.
>
>> f <- function(...) get("..1")
>> f(2)
> Error in get("..1") : object '..1' not found
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
> __
> 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


Re: [Rd] length of `...`

2018-05-03 Thread peter dalgaard


> On 3 May 2018, at 19:23 , Hadley Wickham  wrote:
> 
> Maybe just get(paste0("..", n)) ?
> 
> Hadley

Maybe not. These things are slippery.

> f <- function(...) get("..1")
> f(2)
Error in get("..1") : object '..1' not found

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [Rd] length of `...`

2018-05-03 Thread Hadley Wickham
On Thu, May 3, 2018 at 9:50 AM, Duncan Murdoch  wrote:
> On 03/05/2018 11:18 AM, Duncan Murdoch wrote:
>>
>> On 03/05/2018 11:01 AM, William Dunlap via R-devel wrote:
>>>
>>> In R-3.5.0 you can use ...length():
>>> > f <- function(..., n) ...length()
>>> > f(stop("one"), stop("two"), stop("three"), n=7)
>>> [1] 3
>>>
>>> Prior to that substitute() is the way to go
>>> > g <- function(..., n) length(substitute(...()))
>>> > g(stop("one"), stop("two"), stop("three"), n=7)
>>> [1] 3
>>>
>>> R-3.5.0 also has the ...elt(n) function, which returns
>>> the evaluated n'th entry in ... , without evaluating the
>>> other ... entries.
>>> > fn <- function(..., n) ...elt(n)
>>> > fn(stop("one"), 3*5, stop("three"), n=2)
>>> [1] 15
>>>
>>> Prior to 3.5.0, eval the appropriate component of the output
>>> of substitute() in the appropriate environment:
>>> > gn <- function(..., n) {
>>> +   nthExpr <- substitute(...())[[n]]
>>> +   eval(nthExpr, envir=parent.frame())
>>> + }
>>> > gn(stop("one"), environment(), stop("two"), n=2)
>>> 
>>>
>>
>> Bill, the last of these doesn't quite work, because ... can be passed
>> down through a string of callers.  You don't necessarily want to
>> evaluate it in the parent.frame().  For example:
>>
>> x <- "global"
>> f <- function(...) {
>> x <- "f"
>> g(...)
>> }
>> g <- function(...) {
>> firstExpr <- substitute(...())[[1]]
>> c(list(...)[[1]], eval(firstExpr, envir = parent.frame()))
>> }
>>
>> Calling g(x) correctly prints "global" twice, but calling f(x)
>> incorrectly prints
>>
>> [1] "global" "f"
>>
>> You can get the first element of ... without evaluating the rest using
>> ..1, but I don't know a way to do this for general n in pre-3.5.0 base R.
>
>
> Here's a way to do that:
>
> eval(as.name(paste0("..", n)))
>
> I was surprised this worked for n > 9, but it does.  Looking at the source,
> I think the largest legal value for n is huge; you'd hit other limits long
> before n was too big.

Maybe just get(paste0("..", n)) ?

Hadley

-- 
http://hadley.nz

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


Re: [Rd] length of `...`

2018-05-03 Thread Duncan Murdoch

On 03/05/2018 11:18 AM, Duncan Murdoch wrote:

On 03/05/2018 11:01 AM, William Dunlap via R-devel wrote:

In R-3.5.0 you can use ...length():
> f <- function(..., n) ...length()
> f(stop("one"), stop("two"), stop("three"), n=7)
[1] 3

Prior to that substitute() is the way to go
> g <- function(..., n) length(substitute(...()))
> g(stop("one"), stop("two"), stop("three"), n=7)
[1] 3

R-3.5.0 also has the ...elt(n) function, which returns
the evaluated n'th entry in ... , without evaluating the
other ... entries.
> fn <- function(..., n) ...elt(n)
> fn(stop("one"), 3*5, stop("three"), n=2)
[1] 15

Prior to 3.5.0, eval the appropriate component of the output
of substitute() in the appropriate environment:
> gn <- function(..., n) {
+   nthExpr <- substitute(...())[[n]]
+   eval(nthExpr, envir=parent.frame())
+ }
> gn(stop("one"), environment(), stop("two"), n=2)




Bill, the last of these doesn't quite work, because ... can be passed
down through a string of callers.  You don't necessarily want to
evaluate it in the parent.frame().  For example:

x <- "global"
f <- function(...) {
x <- "f"
g(...)
}
g <- function(...) {
firstExpr <- substitute(...())[[1]]
c(list(...)[[1]], eval(firstExpr, envir = parent.frame()))
}

Calling g(x) correctly prints "global" twice, but calling f(x)
incorrectly prints

[1] "global" "f"

You can get the first element of ... without evaluating the rest using
..1, but I don't know a way to do this for general n in pre-3.5.0 base R.


Here's a way to do that:

eval(as.name(paste0("..", n)))

I was surprised this worked for n > 9, but it does.  Looking at the 
source, I think the largest legal value for n is huge; you'd hit other 
limits long before n was too big.


Duncan Murdoch

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


Re: [Rd] length of `...`

2018-05-03 Thread Hervé Pagès

Hi,

It would be great if one of the experts could comment on the
difference between Hadley's dotlength and ...length? The fact
that someone bothered to implement a new primitive for that
when there seems to be a very simple and straightforward R-only
solution suggests that there might be some gotchas/pitfalls with
the R-only solution.

Thanks,
H.


On 05/03/2018 08:34 AM, Hadley Wickham wrote:

On Thu, May 3, 2018 at 8:18 AM, Duncan Murdoch  wrote:

On 03/05/2018 11:01 AM, William Dunlap via R-devel wrote:


In R-3.5.0 you can use ...length():
> f <- function(..., n) ...length()
> f(stop("one"), stop("two"), stop("three"), n=7)
[1] 3

Prior to that substitute() is the way to go
> g <- function(..., n) length(substitute(...()))
> g(stop("one"), stop("two"), stop("three"), n=7)
[1] 3

R-3.5.0 also has the ...elt(n) function, which returns
the evaluated n'th entry in ... , without evaluating the
other ... entries.
> fn <- function(..., n) ...elt(n)
> fn(stop("one"), 3*5, stop("three"), n=2)
[1] 15

Prior to 3.5.0, eval the appropriate component of the output
of substitute() in the appropriate environment:
> gn <- function(..., n) {
+   nthExpr <- substitute(...())[[n]]
+   eval(nthExpr, envir=parent.frame())
+ }
> gn(stop("one"), environment(), stop("two"), n=2)




Bill, the last of these doesn't quite work, because ... can be passed down
through a string of callers.  You don't necessarily want to evaluate it in
the parent.frame().  For example:

x <- "global"
f <- function(...) {
   x <- "f"
   g(...)
}
g <- function(...) {
   firstExpr <- substitute(...())[[1]]
   c(list(...)[[1]], eval(firstExpr, envir = parent.frame()))
}

Calling g(x) correctly prints "global" twice, but calling f(x) incorrectly
prints

[1] "global" "f"

You can get the first element of ... without evaluating the rest using ..1,
but I don't know a way to do this for general n in pre-3.5.0 base R.


If you don't mind using a package:

# works with R 3.1 and up
library(rlang)

x <- "global"
f <- function(...) {
   x <- "f"
   g(...)
}
g <- function(...) {
   dots <- enquos(...)
   eval_tidy(dots[[1]])
}

f(x, stop("!"))
#> [1] "global"
g(x, stop("!"))
#> [1] "global"

Hadley



--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fredhutch.org
Phone:  (206) 667-5791
Fax:(206) 667-1319

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


Re: [Rd] length of `...`

2018-05-03 Thread Hadley Wickham
On Thu, May 3, 2018 at 8:28 AM, Hadley Wickham  wrote:
> On Thu, May 3, 2018 at 8:00 AM, Gabe Becker  wrote:
>> As of 3.5.0 the ...length() function does exactly what you are asking for.
>> Before that, I don't know of an easy way to get the length without
>> evaluation via R code. There may be one I'm not thinking of though, I
>> haven't needed to do this myself.
>
> dotlength <- function(...) length(nargs())
>
> ?

Oops, I got a bit overzealous there: I mean

dotlength <- function(...) nargs()

(This is subtly different from calling nargs() directly as it will
only count the elements in ...)

Hadley

-- 
http://hadley.nz

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


Re: [Rd] length of `...`

2018-05-03 Thread Hadley Wickham
On Thu, May 3, 2018 at 8:18 AM, Duncan Murdoch  wrote:
> On 03/05/2018 11:01 AM, William Dunlap via R-devel wrote:
>>
>> In R-3.5.0 you can use ...length():
>>> f <- function(..., n) ...length()
>>> f(stop("one"), stop("two"), stop("three"), n=7)
>>[1] 3
>>
>> Prior to that substitute() is the way to go
>>> g <- function(..., n) length(substitute(...()))
>>> g(stop("one"), stop("two"), stop("three"), n=7)
>>[1] 3
>>
>> R-3.5.0 also has the ...elt(n) function, which returns
>> the evaluated n'th entry in ... , without evaluating the
>> other ... entries.
>>> fn <- function(..., n) ...elt(n)
>>> fn(stop("one"), 3*5, stop("three"), n=2)
>>[1] 15
>>
>> Prior to 3.5.0, eval the appropriate component of the output
>> of substitute() in the appropriate environment:
>>> gn <- function(..., n) {
>>+   nthExpr <- substitute(...())[[n]]
>>+   eval(nthExpr, envir=parent.frame())
>>+ }
>>> gn(stop("one"), environment(), stop("two"), n=2)
>>
>>
>
> Bill, the last of these doesn't quite work, because ... can be passed down
> through a string of callers.  You don't necessarily want to evaluate it in
> the parent.frame().  For example:
>
> x <- "global"
> f <- function(...) {
>   x <- "f"
>   g(...)
> }
> g <- function(...) {
>   firstExpr <- substitute(...())[[1]]
>   c(list(...)[[1]], eval(firstExpr, envir = parent.frame()))
> }
>
> Calling g(x) correctly prints "global" twice, but calling f(x) incorrectly
> prints
>
> [1] "global" "f"
>
> You can get the first element of ... without evaluating the rest using ..1,
> but I don't know a way to do this for general n in pre-3.5.0 base R.

If you don't mind using a package:

# works with R 3.1 and up
library(rlang)

x <- "global"
f <- function(...) {
  x <- "f"
  g(...)
}
g <- function(...) {
  dots <- enquos(...)
  eval_tidy(dots[[1]])
}

f(x, stop("!"))
#> [1] "global"
g(x, stop("!"))
#> [1] "global"

Hadley

-- 
http://hadley.nz

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


Re: [Rd] length of `...`

2018-05-03 Thread Hadley Wickham
On Thu, May 3, 2018 at 8:00 AM, Gabe Becker  wrote:
> As of 3.5.0 the ...length() function does exactly what you are asking for.
> Before that, I don't know of an easy way to get the length without
> evaluation via R code. There may be one I'm not thinking of though, I
> haven't needed to do this myself.

dotlength <- function(...) length(nargs())

?

Hadley

-- 
http://hadley.nz

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


Re: [Rd] length of `...`

2018-05-03 Thread Martin Morgan

nargs() provides the number of arguments without evaluating them

> f = function(x, ..., y) nargs()
> f()
[1] 0
> f(a=1, b=2)
[1] 2
> f(1, a=1, b=2)
[1] 3
> f(x=1, a=1, b=2)
[1] 3
> f(stop())
[1] 1


On 05/03/2018 11:01 AM, William Dunlap via R-devel wrote:

In R-3.5.0 you can use ...length():
   > f <- function(..., n) ...length()
   > f(stop("one"), stop("two"), stop("three"), n=7)
   [1] 3

Prior to that substitute() is the way to go
   > g <- function(..., n) length(substitute(...()))
   > g(stop("one"), stop("two"), stop("three"), n=7)
   [1] 3

R-3.5.0 also has the ...elt(n) function, which returns
the evaluated n'th entry in ... , without evaluating the
other ... entries.
   > fn <- function(..., n) ...elt(n)
   > fn(stop("one"), 3*5, stop("three"), n=2)
   [1] 15

Prior to 3.5.0, eval the appropriate component of the output
of substitute() in the appropriate environment:
   > gn <- function(..., n) {
   +   nthExpr <- substitute(...())[[n]]
   +   eval(nthExpr, envir=parent.frame())
   + }
   > gn(stop("one"), environment(), stop("two"), n=2)
   




Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, May 3, 2018 at 7:29 AM, Dénes Tóth  wrote:


Hi,


In some cases the number of arguments passed as ... must be determined
inside a function, without evaluating the arguments themselves. I use the
following construct:

dotlength <- function(...) length(substitute(expression(...))) - 1L

# Usage (returns 3):
dotlength(1, 4, something = undefined)

How can I define a method for length() which could be called directly on
`...`? Or is it an intention to extend the base length() function to accept
ellipses?


Regards,
Denes

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



[[alternative HTML version deleted]]

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




This email message may contain legally privileged and/or...{{dropped:2}}

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


Re: [Rd] length of `...`

2018-05-03 Thread peter dalgaard


> On 3 May 2018, at 16:52 , Mark van der Loo  wrote:
> 
> This question is better aimed at the r-help mailinglist as it is not about
> developing R itself.

Um, no... People there might well send you back here.

As for the original question, there are also variations over

dddlen <- function(...)length(match.call(expand.dots=FALSE)$...)



-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [Rd] length of `...`

2018-05-03 Thread Duncan Murdoch

On 03/05/2018 11:01 AM, William Dunlap via R-devel wrote:

In R-3.5.0 you can use ...length():
   > f <- function(..., n) ...length()
   > f(stop("one"), stop("two"), stop("three"), n=7)
   [1] 3

Prior to that substitute() is the way to go
   > g <- function(..., n) length(substitute(...()))
   > g(stop("one"), stop("two"), stop("three"), n=7)
   [1] 3

R-3.5.0 also has the ...elt(n) function, which returns
the evaluated n'th entry in ... , without evaluating the
other ... entries.
   > fn <- function(..., n) ...elt(n)
   > fn(stop("one"), 3*5, stop("three"), n=2)
   [1] 15

Prior to 3.5.0, eval the appropriate component of the output
of substitute() in the appropriate environment:
   > gn <- function(..., n) {
   +   nthExpr <- substitute(...())[[n]]
   +   eval(nthExpr, envir=parent.frame())
   + }
   > gn(stop("one"), environment(), stop("two"), n=2)
   



Bill, the last of these doesn't quite work, because ... can be passed 
down through a string of callers.  You don't necessarily want to 
evaluate it in the parent.frame().  For example:


x <- "global"
f <- function(...) {
  x <- "f"
  g(...)
}
g <- function(...) {
  firstExpr <- substitute(...())[[1]]
  c(list(...)[[1]], eval(firstExpr, envir = parent.frame()))
}

Calling g(x) correctly prints "global" twice, but calling f(x) 
incorrectly prints


[1] "global" "f"

You can get the first element of ... without evaluating the rest using 
..1, but I don't know a way to do this for general n in pre-3.5.0 base R.


Duncan Murdoch

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


Re: [Rd] length of `...`

2018-05-03 Thread Tóth Dénes
Thank you Bill (and the R-Core Team), this is even more than what I 
thought of. I somehow missed this in the NEWS.


BTW, substitue(...()) is beautiful.


On 05/03/2018 05:01 PM, William Dunlap wrote:

In R-3.5.0 you can use ...length():
   > f <- function(..., n) ...length()
   > f(stop("one"), stop("two"), stop("three"), n=7)
   [1] 3

Prior to that substitute() is the way to go
   > g <- function(..., n) length(substitute(...()))
   > g(stop("one"), stop("two"), stop("three"), n=7)
   [1] 3

R-3.5.0 also has the ...elt(n) function, which returns
the evaluated n'th entry in ... , without evaluating the
other ... entries.
   > fn <- function(..., n) ...elt(n)
   > fn(stop("one"), 3*5, stop("three"), n=2)
   [1] 15

Prior to 3.5.0, eval the appropriate component of the output
of substitute() in the appropriate environment:
   > gn <- function(..., n) {
   +   nthExpr <- substitute(...())[[n]]
   +   eval(nthExpr, envir=parent.frame())
   + }
   > gn(stop("one"), environment(), stop("two"), n=2)
   




Bill Dunlap
TIBCO Software
wdunlap tibco.com 

On Thu, May 3, 2018 at 7:29 AM, Dénes Tóth > wrote:


Hi,


In some cases the number of arguments passed as ... must be
determined inside a function, without evaluating the arguments
themselves. I use the following construct:

dotlength <- function(...) length(substitute(expression(...))) - 1L

# Usage (returns 3):
dotlength(1, 4, something = undefined)

How can I define a method for length() which could be called
directly on `...`? Or is it an intention to extend the base length()
function to accept ellipses?


Regards,
Denes

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





--
Dr. Tóth Dénes ügyvezető
Kogentum Kft.
Tel.: 06-30-2583723
Web: www.kogentum.hu

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


Re: [Rd] length of `...`

2018-05-03 Thread Gabe Becker
As of 3.5.0 the ...length() function does exactly what you are asking for.
Before that, I don't know of an easy way to get the length without
evaluation via R code. There may be one I'm not thinking of though, I
haven't needed to do this myself.

Hope that helps.

~G

On Thu, May 3, 2018 at 7:52 AM, Mark van der Loo 
wrote:

> This question is better aimed at the r-help mailinglist as it is not about
> developing R itself.
>
>
> having said that,
>
> I can only gues why you want to do this, but why not do something like
> this:
>
>
> f <- function(...){
>L <- list(...)
>len <- length()
>   # you can stll pass the ... as follows:
>   do.call(someotherfunction, L)
>
> }
>
>
> -Mark
>
> Op do 3 mei 2018 om 16:29 schreef Dénes Tóth :
>
> > Hi,
> >
> >
> > In some cases the number of arguments passed as ... must be determined
> > inside a function, without evaluating the arguments themselves. I use
> > the following construct:
> >
> > dotlength <- function(...) length(substitute(expression(...))) - 1L
> >
> > # Usage (returns 3):
> > dotlength(1, 4, something = undefined)
> >
> > How can I define a method for length() which could be called directly on
> > `...`? Or is it an intention to extend the base length() function to
> > accept ellipses?
> >
> >
> > Regards,
> > Denes
> >
> > __
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
> [[alternative HTML version deleted]]
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Gabriel Becker, Ph.D
Scientist
Bioinformatics and Computational Biology
Genentech Research

[[alternative HTML version deleted]]

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


Re: [Rd] length of `...`

2018-05-03 Thread William Dunlap via R-devel
In R-3.5.0 you can use ...length():
  > f <- function(..., n) ...length()
  > f(stop("one"), stop("two"), stop("three"), n=7)
  [1] 3

Prior to that substitute() is the way to go
  > g <- function(..., n) length(substitute(...()))
  > g(stop("one"), stop("two"), stop("three"), n=7)
  [1] 3

R-3.5.0 also has the ...elt(n) function, which returns
the evaluated n'th entry in ... , without evaluating the
other ... entries.
  > fn <- function(..., n) ...elt(n)
  > fn(stop("one"), 3*5, stop("three"), n=2)
  [1] 15

Prior to 3.5.0, eval the appropriate component of the output
of substitute() in the appropriate environment:
  > gn <- function(..., n) {
  +   nthExpr <- substitute(...())[[n]]
  +   eval(nthExpr, envir=parent.frame())
  + }
  > gn(stop("one"), environment(), stop("two"), n=2)
  




Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, May 3, 2018 at 7:29 AM, Dénes Tóth  wrote:

> Hi,
>
>
> In some cases the number of arguments passed as ... must be determined
> inside a function, without evaluating the arguments themselves. I use the
> following construct:
>
> dotlength <- function(...) length(substitute(expression(...))) - 1L
>
> # Usage (returns 3):
> dotlength(1, 4, something = undefined)
>
> How can I define a method for length() which could be called directly on
> `...`? Or is it an intention to extend the base length() function to accept
> ellipses?
>
>
> Regards,
> Denes
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

[[alternative HTML version deleted]]

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


Re: [Rd] length of `...`

2018-05-03 Thread Mark van der Loo
This question is better aimed at the r-help mailinglist as it is not about
developing R itself.


having said that,

I can only gues why you want to do this, but why not do something like this:


f <- function(...){
   L <- list(...)
   len <- length()
  # you can stll pass the ... as follows:
  do.call(someotherfunction, L)

}


-Mark

Op do 3 mei 2018 om 16:29 schreef Dénes Tóth :

> Hi,
>
>
> In some cases the number of arguments passed as ... must be determined
> inside a function, without evaluating the arguments themselves. I use
> the following construct:
>
> dotlength <- function(...) length(substitute(expression(...))) - 1L
>
> # Usage (returns 3):
> dotlength(1, 4, something = undefined)
>
> How can I define a method for length() which could be called directly on
> `...`? Or is it an intention to extend the base length() function to
> accept ellipses?
>
>
> Regards,
> Denes
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

[[alternative HTML version deleted]]

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


[Rd] length of `...`

2018-05-03 Thread Dénes Tóth

Hi,


In some cases the number of arguments passed as ... must be determined 
inside a function, without evaluating the arguments themselves. I use 
the following construct:


dotlength <- function(...) length(substitute(expression(...))) - 1L

# Usage (returns 3):
dotlength(1, 4, something = undefined)

How can I define a method for length() which could be called directly on 
`...`? Or is it an intention to extend the base length() function to 
accept ellipses?



Regards,
Denes

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


Re: [Rd] Length of seed for l'Ecuyer-CMRG

2013-01-22 Thread Marius Hofert
I'm sorry, I must have overlooked the "... as given by .Random.seed".

Thanks for helping.

Marius

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


Re: [Rd] Length of seed for l'Ecuyer-CMRG

2013-01-22 Thread Prof Brian Ripley

On 22/01/2013 23:22, Marius Hofert wrote:

Dear expeRts,

./src/library/base/man/Random.Rd says that L'Ecuyer requires a seed of length 6.

./src/library/parallel/man/RngStream.Rd also mentions this, but only in the text
part; In the "Arguments"-part, it says that "seed" has to be of length 7

Also:

,
| > RNGkind("L'Ecuyer-CMRG")
| > length(.Random.seed)
| [1] 7
`

Is the docu old? Some clarification on the two .Rd files would be great.

Cheers,

Marius

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


What the help page actually says is

seed: An integer vector of length 7 as given by ‘.Random.seed’ when
  the ‘"L'Ecuyer-CMRG"’ RNG is in use.  See ‘RNG’ for the valid
  values.

.Random.seed is not the seed per se, it is an indicator of the random 
number generators in use, followed by the seed.  So for a generator with 
seed of length 6, .Random.seed is indeed of length 7.


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
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] Length of seed for l'Ecuyer-CMRG

2013-01-22 Thread Marius Hofert
Dear expeRts,

./src/library/base/man/Random.Rd says that L'Ecuyer requires a seed of length 6.

./src/library/parallel/man/RngStream.Rd also mentions this, but only in the text
part; In the "Arguments"-part, it says that "seed" has to be of length 7

Also:

,
| > RNGkind("L'Ecuyer-CMRG")
| > length(.Random.seed)
| [1] 7
`

Is the docu old? Some clarification on the two .Rd files would be great. 

Cheers,

Marius

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


Re: [Rd] length of POSIXlt object (PR#13482)

2009-01-30 Thread Patrick Burns

'The R Inferno' page 93 and page 99.


Patrick Burns
patr...@burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of "The R Inferno" and "A Guide for the Unwilling S User")

twoutop...@gmail.com wrote:

The length() of a POSIXlt object is given as 9 regardless of the actual
length. For example:

  

make.date.time


function (year=c(2006,2006),month=c(8,8),day=2:5,hour=13,minute=45)
{# convert year, etc., into POSIXlt object
#
d=as.character(make.date(year,month,day))
t=paste(hour,minute,sep=":")
as.POSIXlt(paste(d,t))
}
  

t=make.date.time()
t


[1] "2006-08-02 13:45:00" "2006-08-03 13:45:00" "2006-08-04 13:45:00"
[4] "2006-08-05 13:45:00"
  

length(t)


[1] 9
  

t[1]


[1] "2006-08-02 13:45:00"
  

length(t[1])


[1] 9






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


Re: [Rd] length of POSIXlt object (PR#13482)

2009-01-29 Thread Jeff Ryan
Read the docs. POSIXlt is a list of 9 elements. Each element length is
what you think it should be returning.  That is not correct.

?POSIXlt

Details:

 There are two basic classes of date/times.  Class '"POSIXct"'
 represents the (signed) number of seconds since the beginning of
 1970 as a numeric vector.  Class '"POSIXlt"' is a named list of
 vectors representing

> unclass(as.POSIXlt(as.POSIXlt('2007-01-01')+1:11))
$sec
 [1]  1  2  3  4  5  6  7  8  9 10 11

$min
 [1] 0 0 0 0 0 0 0 0 0 0 0

$hour
 [1] 0 0 0 0 0 0 0 0 0 0 0

$mday
 [1] 1 1 1 1 1 1 1 1 1 1 1

$mon
 [1] 0 0 0 0 0 0 0 0 0 0 0

$year
 [1] 107 107 107 107 107 107 107 107 107 107 107

$wday
 [1] 1 1 1 1 1 1 1 1 1 1 1

$yday
 [1] 0 0 0 0 0 0 0 0 0 0 0

$isdst
 [1] 0 0 0 0 0 0 0 0 0 0 0

attr(,"tzone")
[1] """CST" "CDT"


Jeff


On Wed, Jan 28, 2009 at 4:15 PM,   wrote:
> The length() of a POSIXlt object is given as 9 regardless of the actual
> length. For example:
>
>> make.date.time
> function (year=c(2006,2006),month=c(8,8),day=2:5,hour=13,minute=45)
> {# convert year, etc., into POSIXlt object
> #
> d=as.character(make.date(year,month,day))
> t=paste(hour,minute,sep=":")
> as.POSIXlt(paste(d,t))
> }
>> t=make.date.time()
>> t
> [1] "2006-08-02 13:45:00" "2006-08-03 13:45:00" "2006-08-04 13:45:00"
> [4] "2006-08-05 13:45:00"
>> length(t)
> [1] 9
>> t[1]
> [1] "2006-08-02 13:45:00"
>> length(t[1])
> [1] 9
>
>
>
> --
> blog.sethroberts.net
> www.shangriladiet.com
> boards.shangriladiet.com
> cell phone 510 418 7753 (Berkeley)
>
>[[alternative HTML version deleted]]
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Jeffrey Ryan
jeffrey.r...@insightalgo.com

ia: insight algorithmics
www.insightalgo.com

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


[Rd] length of POSIXlt object (PR#13482)

2009-01-29 Thread twoutopias
The length() of a POSIXlt object is given as 9 regardless of the actual
length. For example:

> make.date.time
function (year=c(2006,2006),month=c(8,8),day=2:5,hour=13,minute=45)
{# convert year, etc., into POSIXlt object
#
d=as.character(make.date(year,month,day))
t=paste(hour,minute,sep=":")
as.POSIXlt(paste(d,t))
}
> t=make.date.time()
> t
[1] "2006-08-02 13:45:00" "2006-08-03 13:45:00" "2006-08-04 13:45:00"
[4] "2006-08-05 13:45:00"
> length(t)
[1] 9
> t[1]
[1] "2006-08-02 13:45:00"
> length(t[1])
[1] 9



-- 
blog.sethroberts.net
www.shangriladiet.com
boards.shangriladiet.com
cell phone 510 418 7753 (Berkeley)

[[alternative HTML version deleted]]

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