From earo.wang at gmail.com  Wed Oct 18 10:34:14 2017
From: earo.wang at gmail.com (Earo Wang)
Date: Wed, 18 Oct 2017 08:34:14 +0000
Subject: [Rd] A wrapper of seq.Date() encounters an issue
Message-ID: <CALRQZVmweHhkb56FrnrwMLx29SZjBf9XTk1JN+a_+ASLP2s++Q@mail.gmail.com>

Hello,

I?ve tried to have a wrapper function of seq.Date(), saying seq_date(). The
seq_date() function takes exactly the same arguments and the defaults as
seq.Date(). The seq_date() is expected to return the same results as
seq.Date(), but it triggers an error in seq.Date(). The little reproducible
example shows below:

seq_date <- function(from, to, by, length.out = NULL, along.with = NULL) {
  seq.Date(
    from = from, to = to, by = by,
    length.out = length.out, along.with = along.with
  )
}
start <- as.Date("2017-10-01")
end <- as.Date("2017-10-18")
seq_date(from = start, to = end, by = 1)#> Error in seq.Date(from =
from, to = to, by = by, length.out = length.out, : exactly two of
'to', 'by' and 'length.out' / 'along.with' must be specified
seq.Date(from = start, to = end, by = 1)#>  [1] "2017-10-01"
"2017-10-02" "2017-10-03" "2017-10-04" "2017-10-05"#>  [6]
"2017-10-06" "2017-10-07" "2017-10-08" "2017-10-09" "2017-10-10"#>
[11] "2017-10-11" "2017-10-12" "2017-10-13" "2017-10-14"
"2017-10-15"#> [16] "2017-10-16" "2017-10-17" "2017-10-18"

I think that the unexpected issue arises from missing(along.with) inside
the seq.Date() function. The documentation of missing() explains that it
can only be used in the immediate body of the function, not in the body of
a nested function. This is probably the reason that the wrapper seq_date()
fails. It would fix the issue by using is.null(along.with) instead of
missing(along.with). I?ve also attached the associated patch. Below shows
the R version.

R.version#>                _                           #> platform
  x86_64-apple-darwin15.6.0   #> arch           x86_64
     #> os             darwin15.6.0                #> system
x86_64, darwin15.6.0        #> status
   #> major          3                           #> minor          4.2
                        #> year           2017
#> month          09                          #> day            28
                     #> svn rev        73368                       #>
language       R                           #> version.string R version
3.4.2 (2017-09-28)#> nickname       Short Summer

Thanks for your time.

Kind regards,
Earo
?
-- 
https://earo.me


[Rd] A wrapper of seq.Date() encounters an issue
Earo Wang