Re: [Rd] paste(character(0), collapse="", recycle0=FALSE) should be ""

2020-05-03 Thread suharto_anggono--- via R-devel
 I was wrong, as I didn't actually try and didn't read the documentation 
carefully. I thought that ' zero-length arguments being recycled to "" ' 
happens when recycle0 = TRUE. It is actually the opposite.

Everywhere in my previous message, recycle0 = FALSE should be recycle0 = TRUE.

I really think that 'paste' with 'collapse' specified (as a character string) 
should always result in a single character string, no matter what value of 
'recycle0'.

paste(character(0), collapse = "", recycle0 = TRUE) # character(0), but should 
be ""

paste(character(0), recycle0 = FALSE)
is the same as
paste(character(0), recycle0 = TRUE) .
'recycle0' doesn't matter there.
Why should
paste(character(0), collapse = "", recycle0 = FALSE)
be different from
paste(character(0), collapse = "", recycle0 = TRUE) ?

paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 =  TRUE) # "4th, 
5th"
paste(c("4"    ), "th", sep = "", collapse = ", ", recycle0 =  TRUE) # "4th"
paste(c(        ), "th", sep = "", collapse = ", ", recycle0 =  TRUE) # 
character(0), but should be ""


On Saturday, 2 May 2020, 10:09:21 pm GMT+7, Martin Maechler 
 wrote:


> suharto anggono--- via R-devel 
>    on Fri, 1 May 2020 03:05:37 + (UTC) writes:

    > Without 'collapse', 'paste' pastes (concatenates) its arguments 
elementwise (separated by 'sep', " " by default). New in R devel and R patched, 
specifying recycle0 = FALSE makes mixing zero-length and nonzero-length 
arguments results in length zero. 

That's not intended.
(It's what should only happen with the new (non-default) recycle0=TRUE )

> The result of paste(n, "th", sep = "", recycle0 = FALSE) always have the same 
> length as 'n'. Previously, the result is still as long as the longest 
> argument, with the zero-length argument like "". If all og the arguments have 
> length zero, 'recycle0' doesn't matter.

    > As far as I understand, 'paste' with 'collapse' as a character string is 
supposed to put together elements of a vector into a single character string. I 
think 'recycle0' shouldn't change it.

Well, not quite:  only  'recycle0=FALSE'  shouldn't change it
.. maybe this is what you meant anyway.

    > In current R devel and R patched, paste(character(0), collapse = "", 
recycle0 = FALSE) is character(0). I think it should be "", like 
paste(character(0), collapse="").

Definitely:  The intent of the new 'recycle0' argument is to 
provide a non-default possibility for paste(, recycle0=TRUE) to behave more
like "arithmetic" functions where the recycling rules ensure that
if one argument has length 0 then the result has length 0:
i.e.,  paste(a,b,c,d,  recycle0=TRUE)      should recycle the same as
              a+b+c+d                      does recycle

Indeed, the default 'recycle0=FALSE'  should correspond to previous (R <= 4.0.0)
behavior entirely.

BUT from all I see, R-devel and R-patched's version of paste()
do behave as they should.  Also what you clim here is not true :

    > paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 = FALSE)
    > is
    > "4th, 5th".
    > paste(c("4"    ), "th", sep = "", collapse = ", ", recycle0 = FALSE)
    > is
    > "4th".
    > I think
    > paste(c(        ), "th", sep = "", collapse = ", ", recycle0 = FALSE)
    > should be
    > "",
    > not character(0).

Rather, what I see is what the comments of the following code
lines claim (according to the intention of 'recycle0', contrary
some of your claims above) :


paste(character(0), collapse = "", recycle0 = FALSE) # is "", like
paste(character(0), collapse = "")
paste(character(0), collapse = "", recycle0 =  TRUE) # is character(0)


paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 = FALSE) # is 
"4th, 5th"
paste(c("4"    ), "th", sep = "", collapse = ", ", recycle0 = FALSE) # is "4th"

paste(c(        ), "th", sep = "", collapse = ", ", recycle0 = FALSE) # is "th"
##
paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 =  TRUE) # is 
"4th, 5th"
paste(c("4"    ), "th", sep = "", collapse = ", ", recycle0 =  TRUE) # is "4th"
paste(c(        ), "th", sep = "", collapse = ", ", recycle0 =  TRUE) # is 
character(0)


There must be a lapsus / misunderstanding somewhere.
I don't see any problem in the new behavior for now.

Best regards,
Martin  
[[alternative HTML version deleted]]

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


[Rd] paste(character(0), collapse="", recycle0=FALSE) should be ""

2020-04-30 Thread suharto_anggono--- via R-devel
Without 'collapse', 'paste' pastes (concatenates) its arguments elementwise 
(separated by 'sep', " " by default). New in R devel and R patched, specifying 
recycle0 = FALSE makes mixing zero-length and nonzero-length arguments results 
in length zero. The result of paste(n, "th", sep = "", recycle0 = FALSE) always 
have the same length as 'n'. Previously, the result is still as long as the 
longest argument, with the zero-length argument like "". If all og the 
arguments have length zero, 'recycle0' doesn't matter.

As far as I understand, 'paste' with 'collapse' as a character string is 
supposed to put together elements of a vector into a single character string. I 
think 'recycle0' shouldn't change it.

In current R devel and R patched, paste(character(0), collapse = "", recycle0 = 
FALSE) is character(0). I think it should be "", like paste(character(0), 
collapse="").

paste(c("4", "5"), "th", sep = "", collapse = ", ", recycle0 = FALSE)
is
"4th, 5th".
paste(c("4" ), "th", sep = "", collapse = ", ", recycle0 = FALSE)
is
"4th".
I think
paste(c(), "th", sep = "", collapse = ", ", recycle0 = FALSE)
should be
"",
not character(0).

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


Re: [Rd] tryCatch without handler in QC.R

2020-03-10 Thread suharto_anggono--- via R-devel
 Sorry, it is already fixed. Currently, it is as follows.
 bad <- tryCatch(check_url_db(udb), error = identity)


On Tuesday, 10 March 2020, 11:53:16 pm GMT+7,  wrote:


The following is among those added by r77792 to src/library/tools/R/QC.R in R 
devel.
                bad <- tryCatch(check_url_db(udb))

The 'tryCatch' has no handler. It does nothing. Error would still stop 
execution.  
[[alternative HTML version deleted]]

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


[Rd] tryCatch without handler in QC.R

2020-03-10 Thread suharto_anggono--- via R-devel
The following is among those added by r77792 to src/library/tools/R/QC.R in R 
devel.
bad <- tryCatch(check_url_db(udb))

The 'tryCatch' has no handler. It does nothing. Error would still stop 
execution.

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


Re: [Rd] round(x, dig) [was "Development version of R fails tests .."]

2020-02-15 Thread suharto_anggono--- via R-devel
I disagree with what is assessed as "correct" in vignette of package 'round'.

With
x <- 9.18665
, what is actually stored in 'x' is a number that is slightly larger than 
9.18665. So, as said in the vignette, it is closer to 9.1867 than 9.1866.

sprintf("%.4f", x)
giving
"9.1867"
is correct, as it is a string representing the _exact_ number 9.1867.

For round(x, 4) , that gives number and cannot return 9.1867 exactly, I still 
think that a binary double precision number closest to 9.1867 should be 
returned. My principles:
- Input number should be read as is, should be treated as exact.
- What counts is what the exact result should be.



> Hugh Parsonage
> on Sat, 8 Feb 2020 21:12:43 +1100 writes:

> The only observation I can make is that the change to
> round() was made in r77727 whereas your R-devel appears to
> be r77715 (so would not exhibit the fixed behaviour).  My
> guess is that there was a perpetual installation failure
> after r77715 but that the test folder was still retrieved
> and used.


> On Sat, 8 Feb 2020 at 19:27, Berwin A Turlach  wrote:
>>
>> G'day all,
>>
>> I have daily scripts running to install the patched version of the
>> current R version and the development version of R on my linux box
>> (Ubuntu 18.04.4 LTS).
>>
>> The last development version that was successfully compiled and
>> installed was "R Under development (unstable) (2020-01-25 r77715)" on
>> 27 January.  Since then the script always fails as a regression test
>> seems to fail.  Specifically, in the tests/ subdirectory of my build
>> directory I have a file reg-tests-1d.Rout.fail which ends with:
>>
>> > ## more than half of the above were rounded *down* in R <= 3.6.x
>> > ## Some "wrong" test cases from CRAN packages (partly relying on wrong 
R <= 3.6.x behavior)
>> > stopifnot(exprs = {
>> + all.equal(round(10.7775, digits=3), 10.778, tolerance = 1e-12) # 
even tol=0, was 10.777
>> + all.equal(round(12345 / 1000,   2), 12.35 , tolerance = 1e-12) # 
even tol=0, was 12.34 in Rd
>> + all.equal(round(9.18665, 4),9.1866, tolerance = 1e-12) # 
even tol=0, was  9.1867
>> + })
>> Error: round(10.7775, digits = 3) and 10.778 are not equal:

>> Mean relative difference: 9.27902e-05
>> Execution halted
>>
>> This happens while the 32bit architecture is installed,  which is a bit
>> surprising as I get the following results for the last installed
>> version of R's development version:
>>
>> R Under development (unstable) (2020-01-25 r77715) -- "Unsuffered 
Consequences"
>> Copyright (C) 2020 The R Foundation for Statistical Computing
>> Platform: x86_64-pc-linux-gnu/32 (32-bit)
>> [...]
>> > round(10.7775, digits=3)
>> [1] 10.778
>>
>> and
>>
>> R Under development (unstable) (2020-01-25 r77715) -- "Unsuffered 
Consequences"
>> Copyright (C) 2020 The R Foundation for Statistical Computing
>> Platform: x86_64-pc-linux-gnu/64 (64-bit)
>> [...]
>> > round(10.7775, digits=3)
>> [1] 10.778
>>
>>
>> On the other hand, the R 3.6.2 version, that I mainly use at the moment,
>> gives the following results:
>>
>> R version 3.6.2 (2019-12-12) -- "Dark and Stormy Night"
>> Copyright (C) 2019 The R Foundation for Statistical Computing
>> Platform: x86_64-pc-linux-gnu/32 (32-bit)
>> [...]
>> > round(10.7775, digits=3)
>> [1] 10.777
>>
>> and
>>
>> R version 3.6.2 (2019-12-12) -- "Dark and Stormy Night"
>> Copyright (C) 2019 The R Foundation for Statistical Computing
>> Platform: x86_64-pc-linux-gnu/64 (64-bit)
>> [...]
>> > round(10.7775, digits=3)
>> [1] 10.777
>>
>>
>> So it seems as if the behaviour of round() has changed between R 3.6.2
>> and the development version.  But I do not understand why this test all
>> of a sudden failed if the results from the last successfully installed
>> development version of R suggest that the test should be passed.
>>
>> Thanks in advance for any insight and tips.
>>
>> Cheers,
>> Berwin

Note that r77727 was the last of a few commits I made related to
dealing with R's bug report PR#17668:
  https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17668

which itself triggered an involved dialogue, mostly online,
visible at the PR's URL above.

It lead me to also write an R package 'round' (in order to
compare R 3.6.x and later's round() versions, comparing them etc)
with a (not entirely polished) package vignette
that explains how rounding to decimal digits is not at all
trivial and why and how I ended (*) improving R's
round(x, digits) algorithm in R-devel.

The CRAN version of the package
https://cran.r-project.org/package=round

install.packages("round")

is not quite current, notably its vignette isn't and so I have
mentioned in the

Re: [Rd] Inappropriate class(o)[!inherits(o,"AsIs")] in get_all_vars

2019-11-29 Thread suharto_anggono--- via R-devel
 
class(o)[!inherits(o,"AsIs")] is still in function 'get_all_vars' in R patched 
(in 
https://svn.r-project.org/R/branches/R-3-6-branch/src/library/stats/R/models.R).
 It was ported to R patched by r77402. On Monday, 18 November 2019, 8:12:10 
PM GMT+7, Martin Maechler  wrote:  
 
 > Martin Maechler 
>    on Mon, 18 Nov 2019 12:15:38 +0100 writes:

> suharto anggono--- via R-devel 
>    on Sun, 17 Nov 2019 10:34:31 + writes:

    >> SVN revision 77401 changes
    >> x[isM] <- lapply(x[isM], function(o) `class<-`(o, class(o)[class(o) != 
"AsIs"]))
    >> to
    >> x[isM] <- lapply(x[isM], function(o) `class<-`(o, 
class(o)[!inherits(o,"AsIs")]))
    >> in function 'get_all_vars' in src/library/stats/R/models.R in R devel.

    >> The change is inappropriate.

    >> class(o)[class(o) != "AsIs"] removes "AsIs" from class(o), giving 
class(o) without "AsIs".

    >> On the other hand, inherits(o,"AsIs") is just a single logical value. If 
"AsIs" is in class(o), inherits(o,"AsIs") is TRUE. In that case, by recycling 
of logical index, class(o)[!inherits(o,"AsIs")] removes all elements of 
class(o), giving character(0).

    > Thank you, Suharto !

    > You are obviously right,  and I'm a bit embarrassed by my
    > overzealousness to follow my own recommendations in the  R Blog

    > http://bit.ly/R_blog_class_think_2x

    > {*wrongly*: The recommendation was to "think again" ...}

    > It's a "shame" that the wrong code did not trigger any checks,
    > so if anybody has time... I'd be grateful for such a regression
    > check.

Once I started thinking, it was easy to modify the previous
reg.check  to trigger in the case of the erronous r77401.

Fixed now in 77435.
Martin
  
[[alternative HTML version deleted]]

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


[Rd] Inappropriate class(o)[!inherits(o,"AsIs")] in get_all_vars

2019-11-17 Thread suharto_anggono--- via R-devel
SVN revision 77401 changes
x[isM] <- lapply(x[isM], function(o) `class<-`(o, class(o)[class(o) != 
"AsIs"]))
to
x[isM] <- lapply(x[isM], function(o) `class<-`(o, 
class(o)[!inherits(o,"AsIs")]))
in function 'get_all_vars' in src/library/stats/R/models.R in R devel.

The change is inappropriate.

class(o)[class(o) != "AsIs"] removes "AsIs" from class(o), giving class(o) 
without "AsIs".

On the other hand, inherits(o,"AsIs") is just a single logical value. If "AsIs" 
is in class(o), inherits(o,"AsIs") is TRUE. In that case, by recycling of 
logical index, class(o)[!inherits(o,"AsIs")] removes all elements of class(o), 
giving character(0).

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


[Rd] Wrong explanation on 'ylab' in hist.Rd

2019-10-06 Thread suharto_anggono--- via R-devel
Description of arguments main, xlab, ylab in hist.Rd in current R devel and R 
patched ends with this.
the default \code{ylab} is \code{"Frequency"} iff \code{probability} is true

In fact, if 'probability' is true, the histogram doesn't represent frequencies.

It should be
the default \code{ylab} is \code{"Frequency"} iff \code{freq} is true

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


[Rd] Strange "no-echo" in place of "slave"

2019-10-06 Thread suharto_anggono--- via R-devel
SVN revision replaces "slave" with "no-echo" in R devel.


In each of the following, "no-echo" is rather strange to me.

- src/gnuwin32/README.Rterm
3) As a no-echo process for ESS mode in NTEmacs with flag --ess.

- src/library/grDevices/src/qdCocoa.m
/* the no-echo thread work until this is NO */

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


[Rd] Wishlist: Function 'difftime' to honor 'tzone' attribute (PR#14182)

2010-01-11 Thread suharto_anggono
Full_Name: Suharto Anggono
Version: 2.8.1
OS: Windows
Submission from: (NULL) (125.165.84.118)


PR#14076 inspired me to write this.

> t1 <- as.POSIXct("1970-01-01 00:00:00", tz="GMT")
> t2 <- as.POSIXlt("1970-01-01 00:00:00", tz="GMT")
> t1 - t2
Time difference of 7 hours

Above, t1 and t2 represent the same time in the same specified timezone.
Therefore, it is reasonable if their difference is zero.

The result is like above because the function '-.POSIXt' calls the function
'difftime', and function 'difftime' does not honor 'tzone' attribute, as can be
seen from this part of the function definition.

function (time1, time2, tz = "", units = c("auto", "secs", "mins",
"hours", "days", "weeks"))
{
time1 <- as.POSIXct(time1, tz = tz)
time2 <- as.POSIXct(time2, tz = tz)
...
}

Function 'difftime' calls 'as.POSIXct' with the value of 'tz' argument. If 'tz'
argument is not supplied, "" (current timezone) is used.

I wish function 'difftime' could honor 'tzone' attribute. The above part of the
function definition can be changed to be like this.

function (time1, time2, tz, units = c("auto", "secs", "mins",
"hours", "days", "weeks"))
{
if (missing(tz)) {
time1 <- as.POSIXct(time1)
time2 <- as.POSIXct(time2)
}
else {
time1 <- as.POSIXct(time1, tz = tz)
time2 <- as.POSIXct(time2, tz = tz)
}
...
}

I see that, if 'tz' argument is not supplied, function 'as.POSIXct.POSIXlt' uses
the value of 'tzone' attribute if present.

> version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  8.1
year   2008
month  12
day22
svn rev47281
language   R
version.string R version 2.8.1 (2008-12-22)
> sessionInfo()
R version 2.8.1 (2008-12-22)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MON
ETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United
States.1252


attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
> Sys.timezone()
[1] "ICT"

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


[Rd] In the documentation of 'Ops.Date', please remove mention about "difftime", like in the documentation of 'DateTimeClasses' (PR#14072)

2009-11-19 Thread suharto_anggono
I am sorry to reply. But I need to clarify things.=0A=0AFrom searching over=
 the internet, I know that, before R 2.5.0, in the documentation of 'DateTi=
meClasses', in 'date + x', in the explanation about 'x', there is also ment=
ion that 'x' can be a 'difftime' object. Now, it has been removed.=0A=0AWhy=
 not doing the same in the documentation of 'Ops.Date'? I have read the doc=
umentation carefully. Also, I have just downloaded http://cran.bic.nus.edu.=
sg/src/base-prerelease/R-latest.tar.gz. In the file Ops.Date.Rd, the phrase=
=0A\emph{or} an object of class=0A\code{"\link{difftime}"}=0Ais still t=
here. This is a snapshot from Ops.Date.Rd.=0A=0A\usage{=0A\special{date + x=
}=0A\special{date - x}=0A\special{date1 lop date2}=0A}=0A\arguments{=0A  \i=
tem{date}{date objects}=0A  \item{date1, date2}{date objects or character v=
ectors.  (Character=0Avectors are converted by \code{\link{as.Date}}.)}=
=0A  \item{x}{a numeric vector (in days) \emph{or} an object of class=0A   =
 \code{"\link{difftime}"}.}=0A  \item{lop}{One of \code{=3D=3D}, \code{!=3D=
}, \code{<}, \code{<=3D}, \code{>}=0Aor \code{>=3D}.}=0A}=0A=0AThe docu=
mentation says that the usage is=0Adate + x=0ASo,=0Adate + x=0Ashould work.=
=0A=0ASo, in the documentation of 'Ops.Date', in the explanation about argu=
ment 'x', please remove the phrase "or an object of class "difftime".". Tha=
t would be in line with the documentation of 'DateTimeClasses', and at leas=
t saves new users.=0A=0AThank you.=0A=0A=0A  New Email addresses availa=
ble on Yahoo!=0AGet the Email name you've always wanted on the new @yma=
il and @rocketmail. =0AHurry before someone else does!=0Ahttp://mail.promot=
ions.yahoo.com/newdomains/aa/

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


[Rd] Wishlist: In documentation, say that `+.Date`(Date, difftime) should be called directly or remove 'or an object of class "difftime"' (PR#14072)

2009-11-19 Thread suharto_anggono
Full_Name: Suharto Anggono
Version: 2.8.1
OS: Windows
Submission from: (NULL) (125.161.134.206)


About PR#14067, now I understand why (Date + difftime) does not use '+.Date'.
But, before I understand, it was surprising. The surprise is also reflected in
the post "Problem with +(POSIXt, difftime) dispatching -- WAS: How to create
sequence of constant time interval" in R-help 2009-02-17.

This is taken from the documentation of Ops.Date.

Usage

date + x
...

Arguments
datedate objects
...
x   a numeric vector (in days) or an object of class "difftime".
...

Reading the documentation above suggests me that I can use (Date + difftime),
which I expect to use date/time arithmetic. PR#13369 also mentions that.

So, the documentation should mention that, to add "Date" with "difftime",
'+.Date' should be called directly, better with example. Alternatively, the
clause 'or an object of class "difftime"' should be removed.

It would be nice if (Date + difftime) could use '+.Date'. But, I think it would
not be easy. One way is making a virtual class that includes "Date", "POSIXct",
and "difftime", say "DateTimeComp", so that the 'class' attribute of
"Date" is c("DateTimeComp", "Date");
"POSIXct" is c("DateTimeComp", "POSIXt", "POSIXct");
"POSIXlt" is c("DateTimeComp", "POSIXt", "POSIXlt");
"difftime" is c("DateTimeComp", "difftime").
Then, define '+.DateTimeComp' or 'Ops.DateTimeComp' that ensures that (Date +
difftime) uses '+.Date'. If it is chosen to define 'Ops.DateTimeComp', the
definition could be like this.

function (e1, e2)
{
if (nargs() == 1)
return(NextMethod(.Generic))
if (.Generic == "+" || .Generic == "-") {
if ((inherits(e1, "Date") && inherits(e2, "POSIXt")) ||
(inherits(e1, "POSIXt") && inherits(e2, "Date")))
stop("binary ", .Generic,
" between Date and POSIXt objects is not defined")
if (inherits(e1, "Date") || inherits(e2, "Date"))
return(do.call(paste(.Generic, "Date", sep = "."), list(e1, e2)))
if (inherits(e1, "POSIXt") || inherits(e2, "POSIXt"))
return(do.call(paste(.Generic, "POSIXt", sep = "."), list(e1, e2)))
}
else {
h1 <- inherits(e1, c("Date", "POSIXt", "difftime"), which = TRUE)
h2 <- inherits(e2, c("Date", "POSIXt", "difftime"), which = TRUE)
if (sum(h1 | h2) > 1)
stop(.Generic, " not defined")
}
NextMethod(.Generic)
}

But, that would require many changes and might break someone's code that access
the 'class' attribute directly.

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


[Rd] (Date + difftime) and (POSIXt + difftime) does not use date/time arithmetics (PR#14067)

2009-11-16 Thread suharto_anggono
Full_Name: Suharto Anggono
Version: 2.8.1
OS: Windows
Submission from: (NULL) (125.165.81.48)


There is already PR#13369. But, the problem is not just the warning.


C:\Program Files\R\R-2.8.1\bin>R --vanilla

R version 2.8.1 (2008-12-22)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> as.Date("2009-09-15") + as.difftime(8, units="weeks")
[1] "2009-09-23"
Warning message:
Incompatible methods ("+.Date", "Ops.difftime") for "+"


I expect to get the date 8 weeks after 2009-09-15, but I get 8 days after
2009-09-15.
To get the date 8 weeks after 2009-09-15, I have to call '+.Date' directly, or
convert weeks to days.


> `+.Date`(as.Date("2009-09-15"), as.difftime(8, units="weeks"))
[1] "2009-11-10"


The problem is the same for class "POSIXt".


> as.POSIXct("2009-09-09 09:09:09") + as.difftime(1, units="hours")
[1] "2009-09-09 09:09:10 ICT"
Warning message:
Incompatible methods ("+.POSIXt", "Ops.difftime") for "+"


I inspect the function definition for '+.Date' and 'Ops.difftime'.


> `+.Date`
function (e1, e2)
{
coerceTimeUnit <- function(x) {
round(switch(attr(x, "units"), secs = x/86400, mins = x/1440,
hours = x/24, days = x, weeks = 7 * x))
}
if (nargs() == 1)
return(e1)
if (inherits(e1, "Date") && inherits(e2, "Date"))
stop("binary + is not defined for Date objects")
if (inherits(e1, "difftime"))
e1 <- coerceTimeUnit(e1)
if (inherits(e2, "difftime"))
e2 <- coerceTimeUnit(e2)
structure(unclass(e1) + unclass(e2), class = "Date")
}

> Ops.difftime
function (e1, e2)
{
coerceTimeUnit <- function(x) {
switch(attr(x, "units"), secs = x, mins = 60 * x, hours = 60 *
60 * x, days = 60 * 60 * 24 * x, weeks = 60 * 60 *
24 * 7 * x)
}
if (nargs() == 1) {
switch(.Generic, `+` = {
}, `-` = {
e1[] <- -unclass(e1)
}, stop(gettextf("unary '%s' not defined for \"difftime\" objects",
.Generic), domain = NA, call. = FALSE))
return(e1)
}
boolean <- switch(.Generic, `<` = , `>` = , `==` = , `!=` = ,
`<=` = , `>=` = TRUE, FALSE)
if (boolean) {
if (inherits(e1, "difftime") && inherits(e2, "difftime")) {
e1 <- coerceTimeUnit(e1)
e2 <- coerceTimeUnit(e2)
}
NextMethod(.Generic)
}
else if (.Generic == "+" || .Generic == "-") {
if (inherits(e1, "difftime") && !inherits(e2, "difftime"))
return(structure(NextMethod(.Generic), units = attr(e1,
"units"), class = "difftime"))
if (!inherits(e1, "difftime") && inherits(e2, "difftime"))
return(structure(NextMethod(.Generic), units = attr(e2,
"units"), class = "difftime"))
u1 <- attr(e1, "units")
if (attr(e2, "units") == u1) {
structure(NextMethod(.Generic), units = u1, class = "difftime")
}
else {
e1 <- coerceTimeUnit(e1)
e2 <- coerceTimeUnit(e2)
structure(NextMethod(.Generic), units = "secs", class = "difftime")
}
}
else {
stop(gettextf("'%s' not defined for \"difftime\" objects",
.Generic), domain = NA)
}
}



I can see the conflict. In '+.Date', the result of operating "Date" and
"difftime" is of class "Date". In 'Ops.difftime', the result of '+' when one of
its operand is "difftime" is of class "difftime". So, maybe, both are not used;
what is used is the usual '+'.

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


[Rd] A fix that for 'bquote' that may work (PR#14031)

2009-11-05 Thread suharto_anggono
This is a fix for 'bquote' that may work.

function (expr, where =3D parent.frame())=20
{
unquote <- function(e) {
if (length(e) <=3D 1 || !is.language(e))=20
e
else if (e[[1]] =3D=3D as.name("."))=20
eval(e[[2]], where)
else as.call(lapply(e, unquote))
}
unquote(substitute(expr))
}
=0A=0A=0A  Get your preferred Email name!=0ANow you can @ymail.com and =
@rocketmail.com. =0Ahttp://mail.promotions.yahoo.com/newdomains/aa/

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


[Rd] In the result of applying 'bquote' to function definition with 2 or more arguments, first function argument disappears (PR#14031)

2009-10-29 Thread suharto_anggono
Full_Name: Suharto Anggono
Version: 2.8.1
OS: Windows
Submission from: (NULL) (125.165.81.124)


Sorry for repost. There is already PR#9602, but the problem is still there.
There is also a post "Re: [R] using bquote to construct function" in R-help
2008-10-02.

This illustrates the problem.


C:\Program Files\R\R-2.8.1\bin>R --vanilla

R version 2.8.1 (2008-12-22)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> h1 <- bquote(function(x, y) {
+ })
> h1
function(, y) {
}
> print(h1, useSource=FALSE)
function(, y) {
}
> eval(h1)
Error in eval(expr, envir, enclos) :
  invalid formal argument list for "function"
> h2 <- bquote(function(x, y) {})
> h2
function(x, y) {}

> print(h2, useSource=FALSE)
function(, y) {
}
> eval(h2)
Error in eval(expr, envir, enclos) :
  invalid formal argument list for "function"
> eval(bquote(function(x) {}))
function(x) {}
> eval(bquote(function() {}))
function() {}
> eval(bquote(function(...) {}))
function(...) {}
> eval(bquote(function(x, y, z) {}))
Error in eval(expr, envir, enclos) :
  invalid formal argument list for "function"
> version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  8.1
year   2008
month  12
day22
svn rev47281
language   R
version.string R version 2.8.1 (2008-12-22)
> sessionInfo()
R version 2.8.1 (2008-12-22)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MON
ETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United
States.1252


attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
>


R was installed from binary.

Above, h1 and h2 are results of applying 'bquote' to function definition with 2
arguments. Apparently, h1 and h2 are actually the same, just printed
differently. They are printed identically when useSource=FALSE. The first
argument disappears, error when 'eval'-ed.

But, apparently, if the function has one or zero argument, applying 'bquote'
results fine.


I try to debug. In the definition of 'bquote', there is 'unquote' function.


> bquote
function (expr, where = parent.frame())
{
unquote <- function(e) {
if (length(e) <= 1)
e
else if (e[[1]] == as.name("."))
eval(e[[2]], where)
else as.call(lapply(e, unquote))
}
unquote(substitute(expr))
}

> unquote <- function(e) {
+ if (length(e) <= 1) e
+ else if (e[[1]] == as.name(".")) eval(e[[2]])
+ else as.call(lapply(e, unquote))
+ }
> h1e <- substitute(function(x, y) {
+ })
> unquote(h1e)
function(, y) {
}
> length(h1e)
[1] 4
> lapply(h1e, unquote)
[[1]]
`function`

[[2]]
``(y = )

[[3]]
{
}

[[4]]
"function(x, y) {"("}")

> as.call(.Last.value)
function(, y) {
}
> h1e[[2]]
$x


$y


> unquote(h1e[[2]])
``(y = )
> length(h1e[[2]])
[1] 2
> lapply(h1e[[2]], unquote)
$x


$y


> as.call(.Last.value)
``(y = )
>


After seeing the above result and reading the documentation of 'as.call', I
conclude that the first function argument (i.e. x) is missing because of
'as.call'. It should not be applied to the result for h1e[[2]]. However, it
should be applied to the result for h1e.


I don't know if this is worth to be fixed. But, if not, the documentation should
mention that 'bquote' is not to be applied to expression containing function
definition with two or more formal arguments.

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