[Rd] pmin/pmax issue with ordered factors

2016-11-30 Thread Erwan Le Pennec

Dear all,

pmin/pmax used to work with ordered factors but fail now since this 
summer when those functions have tried to handle more cases.


A simple way to trigger the issue is:

> min(ordered(c(1,5,6)))
[1] 1
Levels: 1 < 5 < 6
> pmin(ordered(c(1,5,6)), ordered(c(1,5,6)))
Error in `mostattributes<-`(`*tmp*`, value = attributes(elts[[1L]])) :
  adding class "factor" to an invalid object

A simple fix is to explicitly test for the ordered class and use the 
internal method in that case as proposed in the attached patch.


Yours,

Erwan

Index: src/library/base/R/pmax.R
===
--- src/library/base/R/pmax.R	(revision 71694)
+++ src/library/base/R/pmax.R	(working copy)
@@ -24,7 +24,7 @@
 elts <- list(...)
 if(length(elts) == 0L) stop("no arguments")
 i4 <- isS4(elts[[1L]])
-if(!i4 && all(vapply(elts, function(x) is.atomic(x) && !is.object(x), NA))) {
+if(!i4 && all(vapply(elts, function(x) is.atomic(x) && (!is.object(x) || is.ordered(x)), NA))) {
 	## NB: NULL passes is.atomic
 	mmm <- .Internal(pmax(na.rm, ...))
 } else {
@@ -68,7 +68,7 @@
 elts <- list(...)
 if(length(elts) == 0L) stop("no arguments")
 i4 <- isS4(elts[[1L]])
-if(!i4 && all(vapply(elts, function(x) is.atomic(x) && !is.object(x), NA))) {
+if(!i4 && all(vapply(elts, function(x) is.atomic(x) && (!is.object(x) || is.ordered(x)), NA))) {
 	mmm <- .Internal(pmin(na.rm, ...))
 } else {
 	mmm <- as.vector(elts[[1L]]) # attr(mmm, "dim") <- NULL  # dim<- would drop names
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Re: [Rd] problem with normalizePath()

2016-11-30 Thread Laviolette, Michael
In researching another issue, I discovered a workaround: the network drive 
folder needs to be mapped to the local PC.

setwd("//Hzndhhsvf2/data/OCPH/EPI/BHSDM/Group/Michael Laviolette/Stat tools")
df1 <- readxl::read_excel("addrlist-4-MikeL.xls", 2)
# fails, throws same error
df2 <- readxl::read_excel("Z:/Stat tools/addrlist-4-MikeL.xls", 2)  # works

-Original Message-
From: Martin Maechler [mailto:maech...@stat.math.ethz.ch] 
Sent: Friday, November 18, 2016 3:37 PM
To: Evan Cortens
Cc: Laviolette, Michael; r-devel@r-project.org
Subject: Re: [Rd] problem with normalizePath()

> Evan Cortens 
> on Thu, 17 Nov 2016 15:51:03 -0700 writes:

> I wonder if this could be related to the issue that I
> submitted to bugzilla about two months ago? (
> https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17159)

> That is to say, could it be that it's treating the first
> path after the single backslash as an actual directory,
> rather than as the name of the share?

> -- 
> Evan Cortens, PhD Institutional Analyst - Office of
> Institutional Analysis Mount Royal University 403-440-6529

Could well be.  Thank you, Evan, also for your bug report including patch 
proposal.

In such situations we (R core) would be really happy if Microsoft showed 
another facet of their investment into R:
Ideally there should be enough staff who can judge and test such bugs and bug 
fixes? 

--> I'm BCC'ing this to one place at least.

Best,
Martin Maechler  ETH Zurich

> On Thu, Nov 17, 2016 at 2:28 PM, Laviolette, Michael <
> michael.laviole...@dhhs.nh.gov> wrote:

>> The packages "readxl" and "haven" (and possibly others)
>> no longer access files on shared network drives. The
>> problem appears to be in the normalizePath()
>> function. The file can be read from a local drive or by
>> functions that don't call normalizePath(). The error
>> thrown is
>> 
>> Error:
>> path[1]="\\Hzndhhsvf2/data/OCPH/EPI/BHSDM/Group/17.xls":
>> The system cannot find the file specified
>> 
>> Here's my session:
>> 
>> library(readxl) library(XLConnect)
>> 
>> # attempting to read file from network drive df1 <-
>> read_excel("//Hzndhhsvf2/data/OCPH/EPI/BHSDM/Group/17.xls")
>> # pathname is fully qualified, but error thrown as above
>> 
>> cat(normalizePath("//Hzndhhsvf2/data/OCPH/EPI/BHSDM/Group/17.xls"))
>> # throws same error
>> 
>> # reading same file with different function df2 <-
>> readWorksheetFromFile("//Hzndhhsvf2/data/OCPH/EPI/BHSDM/Group/17.xls",
>> 1) # completes successfully
>> 
>> # reading same file from local drive df3 <-
>> read_excel("C:/17.xls") # completes successfully
>> 
>> sessionInfo() R version 3.3.2 (2016-10-31) Platform:
>> x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7
>> x64 (build 7601) Service Pack 1
>> 
>> locale: [1] LC_COLLATE=English_United States.1252
>> LC_CTYPE=English_United States.1252 [3]
>> LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5]
>> LC_TIME=English_United States.1252
>> 
>> attached base packages: [1] stats graphics grDevices
>> utils datasets methods base
>> 
>> other attached packages: [1] readxl_0.1.1 dplyr_0.5.0
>> XLConnect_0.2-12 [4] XLConnectJars_0.2-12 ROracle_1.2-1
>> DBI_0.5-1
>> 
>> loaded via a namespace (and not attached): [1]
>> magrittr_1.5 R6_2.2.0 assertthat_0.1 tools_3.3.2
>> haven_1.0.0 [6] tibble_1.2 Rcpp_0.12.7 rJava_0.9-8
>> 
>> Please advise.  Thanks,
>> 
>> Michael Laviolette PhD MPH Public Health Statistician
>> Bureau of Public Health Statistics and Informatics New
>> Hampshire Division of Public Health Services 29 Hazen
>> Drive Concord, NH 03301-6504 Phone: 603-271-5688 Fax:
>> 603-271-7623 Email: michael.laviole...@dhhs.nh.gov
>> 
>> 
>> 
>> [[alternative HTML version deleted]]
>> 
>> __
>> 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

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


Re: [Rd] problem with normalizePath()

2016-11-30 Thread Evan Cortens
I found this as well. At our institution, our home directories are on
network shares that are mapped to local drives. The default, it appears, is
to set the location for libraries (etc) to the network share name
(//computer//share/director/a/b/user) rather than the local drive mapping
(H:/). Given the issue with dir.create(), this means it's impossible to
install packages (since it tries to "create" the share, not the highest
directory). This can be fixed in the same way Michael found, namely, set
the environment variables to use the local mapping rather than the network
share. But ideally, the fix would be to treat Windows network paths
correctly.

Best,

Evan

On Wed, Nov 30, 2016 at 7:16 AM, Laviolette, Michael <
michael.laviole...@dhhs.nh.gov> wrote:

> In researching another issue, I discovered a workaround: the network drive
> folder needs to be mapped to the local PC.
>
> setwd("//Hzndhhsvf2/data/OCPH/EPI/BHSDM/Group/Michael Laviolette/Stat
> tools")
> df1 <- readxl::read_excel("addrlist-4-MikeL.xls", 2)
>   # fails, throws same error
> df2 <- readxl::read_excel("Z:/Stat tools/addrlist-4-MikeL.xls", 2)  #
> works
>
> -Original Message-
> From: Martin Maechler [mailto:maech...@stat.math.ethz.ch]
> Sent: Friday, November 18, 2016 3:37 PM
> To: Evan Cortens
> Cc: Laviolette, Michael; r-devel@r-project.org
> Subject: Re: [Rd] problem with normalizePath()
>
> > Evan Cortens 
> > on Thu, 17 Nov 2016 15:51:03 -0700 writes:
>
> > I wonder if this could be related to the issue that I
> > submitted to bugzilla about two months ago? (
> > https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17159)
>
> > That is to say, could it be that it's treating the first
> > path after the single backslash as an actual directory,
> > rather than as the name of the share?
>
> > --
> > Evan Cortens, PhD Institutional Analyst - Office of
> > Institutional Analysis Mount Royal University 403-440-6529
>
> Could well be.  Thank you, Evan, also for your bug report including patch
> proposal.
>
> In such situations we (R core) would be really happy if Microsoft showed
> another facet of their investment into R:
> Ideally there should be enough staff who can judge and test such bugs and
> bug fixes?
>
> --> I'm BCC'ing this to one place at least.
>
> Best,
> Martin Maechler  ETH Zurich
>
> > On Thu, Nov 17, 2016 at 2:28 PM, Laviolette, Michael <
> > michael.laviole...@dhhs.nh.gov> wrote:
>
> >> The packages "readxl" and "haven" (and possibly others)
> >> no longer access files on shared network drives. The
> >> problem appears to be in the normalizePath()
> >> function. The file can be read from a local drive or by
> >> functions that don't call normalizePath(). The error
> >> thrown is
> >>
> >> Error:
> >> path[1]="\\Hzndhhsvf2/data/OCPH/EPI/BHSDM/Group/17.xls":
> >> The system cannot find the file specified
> >>
> >> Here's my session:
> >>
> >> library(readxl) library(XLConnect)
> >>
> >> # attempting to read file from network drive df1 <-
> >> read_excel("//Hzndhhsvf2/data/OCPH/EPI/BHSDM/Group/17.xls")
> >> # pathname is fully qualified, but error thrown as above
> >>
> >> cat(normalizePath("//Hzndhhsvf2/data/OCPH/EPI/BHSDM/Group/17.xls"))
> >> # throws same error
> >>
> >> # reading same file with different function df2 <-
> >> readWorksheetFromFile("//Hzndhhsvf2/data/OCPH/EPI/
> BHSDM/Group/17.xls",
> >> 1) # completes successfully
> >>
> >> # reading same file from local drive df3 <-
> >> read_excel("C:/17.xls") # completes successfully
> >>
> >> sessionInfo() R version 3.3.2 (2016-10-31) Platform:
> >> x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7
> >> x64 (build 7601) Service Pack 1
> >>
> >> locale: [1] LC_COLLATE=English_United States.1252
> >> LC_CTYPE=English_United States.1252 [3]
> >> LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5]
> >> LC_TIME=English_United States.1252
> >>
> >> attached base packages: [1] stats graphics grDevices
> >> utils datasets methods base
> >>
> >> other attached packages: [1] readxl_0.1.1 dplyr_0.5.0
> >> XLConnect_0.2-12 [4] XLConnectJars_0.2-12 ROracle_1.2-1
> >> DBI_0.5-1
> >>
> >> loaded via a namespace (and not attached): [1]
> >> magrittr_1.5 R6_2.2.0 assertthat_0.1 tools_3.3.2
> >> haven_1.0.0 [6] tibble_1.2 Rcpp_0.12.7 rJava_0.9-8
> >>
> >> Please advise.  Thanks,
> >>
> >> Michael Laviolette PhD MPH Public Health Statistician
> >> Bureau of Public Health Statistics and Informatics New
> >> Hampshire Division of Public Health Services 29 Hazen
> >> Drive Concord, NH 03301-6504 Phone: 603-271-5688 Fax:
> >> 603-271-7623 Email: michael.laviole...@dhhs.nh.gov
> >>
> >>
> >>
> >> [[alternative HTML version deleted]]
> >>
> >> _

[Rd] Different results for cos,sin,tan and cospi,sinpi,tanpi

2016-11-30 Thread Ei-ji Nakama
Hi,

i try sin, cos, and tan.

> sapply(c(cos,sin,tan),function(x,y)x(y),1.23e45*pi)
[1] 0.5444181 0.8388140 1.5407532

However, *pi results the following

> sapply(c(cospi,sinpi,tanpi),function(x,y)x(y),1.23e45)
[1] 1 0 0

Please try whether the following becomes all right.

diff -ruN R-3.3.2.orig/src/nmath/cospi.c R-3.3.2/src/nmath/cospi.c
--- R-3.3.2.orig/src/nmath/cospi.c  2016-09-15 07:15:31.0 +0900
+++ R-3.3.2/src/nmath/cospi.c   2016-12-01 13:54:38.863357149 +0900
@@ -35,7 +35,11 @@
 #endif
 if(!R_FINITE(x)) ML_ERR_return_NAN;

-x = fmod(fabs(x), 2.);// cos() symmetric; cos(pi(x + 2k)) ==
cos(pi x) for all integer k
+x = fabs(x);
+if ( x > 9007199254740991 ) /* 2^53-1 */
+return cos(M_PI * x);
+
+x = fmod(x, 2.);// cos() symmetric; cos(pi(x + 2k)) == cos(pi x)
for all integer k
 if(fmod(x, 1.) == 0.5) return 0.;
 if( x == 1.)   return -1.;
 if( x == 0.)   return  1.;
@@ -57,6 +61,9 @@
 #endif
 if(!R_FINITE(x)) ML_ERR_return_NAN;

+if (( x >  9007199254740991 )||  /*  2^53-1 */
+( x < -9007199254740991 )  ) /* -2^53-1 */
+return sin(M_PI * x);
 x = fmod(x, 2.); // sin(pi(x + 2k)) == sin(pi x)  for all integer k
 // map (-2,2) --> (-1,1] :
 if(x <= -1) x += 2.; else if (x > 1.) x -= 2.;
@@ -81,6 +88,10 @@
 #endif
 if(!R_FINITE(x)) ML_ERR_return_NAN;

+if (( x >  9007199254740991 )||  /*  2^53-1 */
+( x < -9007199254740991 )  ) /* -2^53-1 */
+return tan(M_PI * x);
+
 x = fmod(x, 1.); // tan(pi(x + k)) == tan(pi x)  for all integer k
 // map (-1,1) --> (-1/2, 1/2] :
 if(x <= -0.5) x++; else if(x > 0.5) x--;

-- 
Best Regards,
--
Eiji NAKAMA 
"\u4e2d\u9593\u6804\u6cbb"  

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