Re: [Rd] stopifnot

2019-05-30 Thread Suharto Anggono Suharto Anggono via R-devel
Here is a patch to function 'stopifnot' that adds 'evaluated' argument and 
makes 'exprs' argument in 'stopifnot' like 'exprs' argument in 'withAutoprint'.

--- stop.R  2019-05-30 14:01:15.282197286 +
+++ stop_new.R  2019-05-30 14:01:51.372187466 +
@@ -31,7 +31,7 @@
 .Internal(stop(call., .makeMessage(..., domain = domain)))
 }
 
-stopifnot <- function(..., exprs, local = TRUE)
+stopifnot <- function(..., exprs, evaluated = FALSE, local = TRUE)
 {
 n <- ...length()
 if(!missing(exprs)) {
@@ -41,21 +41,19 @@
 else if(isFALSE(local)) .GlobalEnv
 else if (is.environment(local)) local
 else stop("'local' must be TRUE, FALSE or an environment")
-   exprs <- substitute(exprs) # protect from evaluation
-   E1 <- if(is.call(exprs)) exprs[[1]]
+   E1 <- if(!evaluated && is.call(exprs <- substitute(exprs))) exprs[[1]]
cl <- if(is.symbol(E1) &&
-(E1 == quote(`{`) || E1 == quote(expression))) {
+E1 == quote(`{`)) {
  exprs[[1]] <- quote(stopifnot) ## --> stopifnot(*, *, ..., *) 
:
  exprs
  }
  else
  as.call(c(quote(stopifnot),
-   if(is.null(E1) && is.symbol(exprs) &&
-  is.expression(E1 <- eval(exprs))) # the *name* 
of an expression
-   as.list(E1)
+   if(is.expression(exprs))
+   exprs
else
as.expression(exprs)
-   )) # or fail ..
+   ))
 names(cl) <- NULL
return(eval(cl, envir=envir))
 }




 Subject: Re: [Rd] stopifnot
 To: "Martin Maechler" 
 Cc: r-devel@r-project.org
 Date: Monday, 15 April, 2019, 2:56 AM
 
Also, in current definition of function 'stopifnot' in R 3.6.0 beta or R devel, 
for 'cl' if 'exprs' is specified, there a case with comment "the *name* of an 
expression". The intent is allowing
stopifnot(exprs = ee) ,
where variable 'ee' holds an expression object, to work on the expression 
object.

It is not quite right to use eval(exprs) . It fails when 'stopifnot' is called 
inside a function, like
f <- function(ee) stopifnot(exprs = ee)
f(expression())

But, how about local=FALSE case? Should the following work?
f <- function(ee) stopifnot(exprs = ee, local = FALSE)
f(expression())

But, why bother making it work, while it is undocumented that 'exprs' argument 
in 'stopifnot' can be an expression? Well, yes, expectation may be set from the 
name "exprs" itself or from argument 'exprs' in function 'source' or 
'withAutoprint'. Function 'withAutoprint' may be the closest match.

Function 'withAutoprint' has 'evaluated' argument that controls whether work is 
on value of  'exprs' or on 'exprs' as given. I like the approach.

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


Re: [Rd] use of buffers in sprintf and snprintf

2019-05-30 Thread jing hua zhao
Hi again,

I realised it is useful to replicate the warnings locally without relying on 
CRAN automatic check; instead of R(-devel)  CMD check --as-cran 
package_version.tar.gz one can use

R CMD check --configure-args=""

and in my case the WARNINGS were initially given with 
https://www.stats.ox.ac.uk/pub/bdr/gcc9/README.txt and those specification 
might as well used in --configure-args above.

Besst regards,


Jing Hua


From: R-devel  on behalf of jing hua zhao 

Sent: 29 May 2019 15:49
To: r-devel@r-project.org
Subject: [Rd] use of buffers in sprintf and snprintf

Dear R-developers,

I am struggling with packaging with sprintf and snprintf() as the following 
WARNINGS from gcc 9.x,

  hap_c.c:380:46: warning: �%d� directive output may be truncated writing 
between 1 and 10 bytes into a region of size between 0 and 127 
[-Wformat-truncation=]
  hap_c.c:392:46: warning: �%d� directive output may be truncated writing 
between 1 and 10 bytes into a region of size between 0 and 127 
[-Wformat-truncation=]

Essentially, I have

#define MAX_FILENAME_LEN 128
char of1name[MAX_FILENAME_LEN],of2name[MAX_FILENAME_LEN], 
tempname[MAX_FILENAME_LEN];

...

 snprintf(tempname,sizeof(tempname),"%s.%d", of1name, j);

It looks I could get around with


#define MAX_FILENAME_LEN 128

#define MAX_FILENAME_LEN2 256

char of1name[MAX_FILENAME_LEN],of2name[MAX_FILENAME_LEN], 
tempname[MAX_FILENAME_LEN2];

...
snprintf(tempname,2*sizeof(tempname)+1,"%s.%d", of1name, j)

It looks a bit waste of resources to me.


Any idea will be greatly appreciated,



Jing Hua

[[alternative HTML version deleted]]


[[alternative HTML version deleted]]

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


Re: [Rd] Converting non-32-bit integers from python to R to use bit64: reticulate

2019-05-30 Thread Juan Telleria Ruiz de Aguirre
Thank you Gabriel for valuable insights on the 64-bit integers topic.

In addition, my statement was wrong, as Python3 seems to have unlimited
(and variable) size integers. Here is related CPython Code:

https://github.com/python/cpython/blob/master/Objects/longobject.c

Division between Int-32 and Int-64 seems to only happen in Python2.

Best,
Juan

El miércoles, 29 de mayo de 2019, Gabriel Becker 
escribió:

> Hi Juan,
>
> Comments inline.
>
> On Wed, May 29, 2019 at 12:48 PM Juan Telleria Ruiz de Aguirre <
> jtelleria.rproj...@gmail.com> wrote:
>
>> Dear R Developers,
>>
>> There is an interesting issue related to "reticulate" R package which
>> discusses how to convert Python's non-32 bit integers to R, which has had
>> quite an exhaustive discussion:
>>
>> https://github.com/rstudio/reticulate/issues/323
>>
>> Python seems to handle integers differently from R, and is dependant on
>> the
>> system arquitecture: On 32 bit systems uses 32-bit integers, and on 64-bit
>> systems uses 64-bit integers.
>>
>> So my question is:
>>
>> As regards R's C Interface, how costly would it be to convert INTSXP from
>> 32 bits to 64 bits using C, on 64 bits Systems? Do the benefits surpass
>> the
>> costs? And should such development be handled from within R Core /
>> Ordinary
>> Members , or it shall be left to package maintainers?
>>
>
> Well, I am not an R-core member, but I can mention a few things:
>
> 1. This seems like it would make the results of R code non-reproducible
> between 32 and 64bit versions of R; at least some code would give different
> results (at the very least in terms of when integer values overflow to NA,
> which is documented behavior).
> 2. Obviously all integer data would take twice as much memory, memory
> bandwidth, space in caches, etc, even when it doesn't need it.
> 3. Various places treat data /data pointers coming out of INTSXP and
> LGLSXP objects the same within the internal R sources (as currently they're
> both int/int*). Catching and fixing all those wouldn't be impossible, but
> it would take at least some doing.
>
> For me personally 1 seems like a big problem, and 3 makes the conversion
> more work than it might have seemed initially.
>
> As a related side note, as far as I understand what I've heard from R-core
> members directly, the choice to not have multiple types of integers is
> intentional and unlikely to change.
>
> Best,
> ~G
>
>
>
>
>>
>> Thank you! :)
>>
>> [[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


Re: [Rd] R pkg install should fail for unsuccessful DLL copy on windows?

2019-05-30 Thread Toby Hocking
thanks for the tip Jan.

However it would be nice if I didn't have to handle this myself for all of
my packages. (and teach my students how to do that)

BTW I tried to disable staged installation, and the issue still happens:

th798@cmp2986 MINGW64 ~/projects/max-generalized-auc (master)
$ R_INSTALL_STAGED=FALSE R --vanilla -e
".libPaths('~/R/library');.libPaths();options(repos='
https://cloud.r-project.org',
warn=2);library(penaltyLearning);install.packages('penaltyLearning',
type='source');getOption('warn');sessionInfo()"

R version 3.6.0 (2019-04-26) -- "Planting of a Tree"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

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.

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.

> .libPaths('~/R/library');.libPaths();options(repos='
https://cloud.r-project.org',
warn=2);library(penaltyLearning);install.packages('penaltyLearning',
type='source');getOption('warn');sessionInfo()
[1] "C:/Users/th798/R/library"   "C:/Program
Files/R/R-3.6.0/library"
Loading required package: data.table
Registered S3 methods overwritten by 'ggplot2':
  method from
  [.quosures rlang
  c.quosures rlang
  print.quosures rlang
Installing package into 'C:/Users/th798/R/library'
(as 'lib' is unspecified)
trying URL '
https://cloud.r-project.org/src/contrib/penaltyLearning_2018.09.04.tar.gz'
Content type 'application/x-gzip' length 2837289 bytes (2.7 MB)
==
downloaded 2.7 MB

* installing *source* package 'penaltyLearning' ...
** package 'penaltyLearning' successfully unpacked and MD5 sums checked
** using non-staged installation
** libs
c:/Rtools/mingw_64/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.0/include"
-DNDEBUG  -O2 -Wall  -mtune=generic -c interface.cpp -o interface.o
c:/Rtools/mingw_64/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.0/include"
-DNDEBUG  -O2 -Wall  -mtune=generic -c largestContinuousMinimum.cpp
-o largestContinuousMinimum.o
largestContinuousMinimum.cpp: In function 'int
largestContinuousMinimum(int, double*, double*, int*)':
largestContinuousMinimum.cpp:38:27: warning: 'start' may be used
uninitialized in this function [-Wmaybe-uninitialized]
   index_vec[0] = start;
   ^
c:/Rtools/mingw_64/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.0/include"
-DNDEBUG  -O2 -Wall  -mtune=generic -c modelSelection.cpp -o
modelSelection.o
/usr/bin/sed: -e expression #1, char 1: unknown command: `C'
c:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o penaltyLearning.dll
tmp.def interface.o largestContinuousMinimum.o modelSelection.o
-LC:/PROGRA~1/R/R-36~1.0/bin/x64 -lR
installing to C:/Users/th798/R/library/penaltyLearning/libs/x64
Warning in file.copy(files, dest, overwrite = TRUE) :
  problem copying .\penaltyLearning.dll to
C:\Users\th798\R\library\penaltyLearning\libs\x64\penaltyLearning.dll:
Permission denied
** R
** data
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
  converting help for package 'penaltyLearning'
finding HTML links ... done
GeomTallRecthtml
IntervalRegressionCVhtml
IntervalRegressionCVmargin  html
IntervalRegressionInternal  html
IntervalRegressionRegularized   html
IntervalRegressionUnregularized html
ROChangehtml
change.colors   html
change.labels   html
changeLabel html
check_features_targets  html
check_target_pred   html
coef.IntervalRegression html
demo8   html
featureMatrix   html
featureVector   html
geom_tallrect   html
labelError  html
largestContinuousMinimumC   html
largestContinuousMinimumR   html
modelSelection  html
modelSelectionC html
modelSelectionR html
neuroblastomaProcessed  html
oneSkip html
plot.IntervalRegression html
predict.IntervalRegression  html
print.IntervalRegressionhtml
squared.hinge   html
targetIntervalROC   ht

Re: [Rd] R pkg install should fail for unsuccessful DLL copy on windows?

2019-05-30 Thread Pages, Herve
Also note that this can lead to people not being able to load the
package if the set of .Call entry points has changed between the old
and new versions of the package. We strongly suspect that this is what
happened to this Bioconductor user:

   https://support.bioconductor.org/p/121228/

Note that she's installing the binary and in this case no warning
is issued. All we see is:

   package ‘S4Vectors’ successfully unpacked and MD5 sums checked

but the old DLL apparently didn't get replaced with the new one.
Hence the

   error: "make_RAW_from_NA_LLINT" not available for .Call() for package 
"S4Vectors"

later on when trying to load the package.

Cheers,
H.


On 5/30/19 16:31, Toby Hocking wrote:
> thanks for the tip Jan.
> 
> However it would be nice if I didn't have to handle this myself for all of
> my packages. (and teach my students how to do that)
> 
> BTW I tried to disable staged installation, and the issue still happens:
> 
> th798@cmp2986 MINGW64 ~/projects/max-generalized-auc (master)
> $ R_INSTALL_STAGED=FALSE R --vanilla -e
> ".libPaths('~/R/library');.libPaths();options(repos='
> https://urldefense.proofpoint.com/v2/url?u=https-3A__cloud.r-2Dproject.org&d=DwICAg&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=zldJhdavBFtHDHr08_HFRAi9MY2WBkTiDn1ggbog4cA&s=7X00xNRObhT9O68YU8m-IBkt38N5p_GP-UV77XEnKZw&e=
>  ',
> warn=2);library(penaltyLearning);install.packages('penaltyLearning',
> type='source');getOption('warn');sessionInfo()"
> 
> R version 3.6.0 (2019-04-26) -- "Planting of a Tree"
> Copyright (C) 2019 The R Foundation for Statistical Computing
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> 
> 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.
> 
> 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.
> 
>> .libPaths('~/R/library');.libPaths();options(repos='
> https://urldefense.proofpoint.com/v2/url?u=https-3A__cloud.r-2Dproject.org&d=DwICAg&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=zldJhdavBFtHDHr08_HFRAi9MY2WBkTiDn1ggbog4cA&s=7X00xNRObhT9O68YU8m-IBkt38N5p_GP-UV77XEnKZw&e=
>  ',
> warn=2);library(penaltyLearning);install.packages('penaltyLearning',
> type='source');getOption('warn');sessionInfo()
> [1] "C:/Users/th798/R/library"   "C:/Program
> Files/R/R-3.6.0/library"
> Loading required package: data.table
> Registered S3 methods overwritten by 'ggplot2':
>method from
>[.quosures rlang
>c.quosures rlang
>print.quosures rlang
> Installing package into 'C:/Users/th798/R/library'
> (as 'lib' is unspecified)
> trying URL '
> https://urldefense.proofpoint.com/v2/url?u=https-3A__cloud.r-2Dproject.org_src_contrib_penaltyLearning-5F2018.09.04.tar.gz&d=DwICAg&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=zldJhdavBFtHDHr08_HFRAi9MY2WBkTiDn1ggbog4cA&s=o34c6BnD4LvJv-00tYn5M2TqO_IjH5qtaKnnhI4ph50&e=
>  '
> Content type 'application/x-gzip' length 2837289 bytes (2.7 MB)
> ==
> downloaded 2.7 MB
> 
> * installing *source* package 'penaltyLearning' ...
> ** package 'penaltyLearning' successfully unpacked and MD5 sums checked
> ** using non-staged installation
> ** libs
> c:/Rtools/mingw_64/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.0/include"
> -DNDEBUG  -O2 -Wall  -mtune=generic -c interface.cpp -o interface.o
> c:/Rtools/mingw_64/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.0/include"
> -DNDEBUG  -O2 -Wall  -mtune=generic -c largestContinuousMinimum.cpp
> -o largestContinuousMinimum.o
> largestContinuousMinimum.cpp: In function 'int
> largestContinuousMinimum(int, double*, double*, int*)':
> largestContinuousMinimum.cpp:38:27: warning: 'start' may be used
> uninitialized in this function [-Wmaybe-uninitialized]
> index_vec[0] = start;
> ^
> c:/Rtools/mingw_64/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.0/include"
> -DNDEBUG  -O2 -Wall  -mtune=generic -c modelSelection.cpp -o
> modelSelection.o
> /usr/bin/sed: -e expression #1, char 1: unknown command: `C'
> c:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o penaltyLearning.dll
> tmp.def interface.o largestContinuousMinimum.o modelSelection.o
> -LC:/PROGRA~1/R/R-36~1.0/bin/x64 -lR
> installing to C:/Users/th798/R/library/penaltyLearning/libs/x64
> Warning in file.copy(files, dest, overwrite = TRUE) :
>problem copying .\penaltyLearning.dll to
> C:\Users\th798\R\library\penaltyLearning\libs\x64\penaltyLearning.dll:
> Permission denied
> ** R
> ** data
> ** byte-compile and prepare package for lazy loading
> ** help
> *** installing hel

Re: [Rd] use of buffers in sprintf and snprintf

2019-05-30 Thread Simon Urbanek
No, that will make it even worse since you'll be declaring a lot more memory 
that you actually have.

The real problem is that you're ignoring the truncation, so you probably want 
to use something like

if (snprintf(tempname, sizeof(tempname), "%s.%d", of1name, j) >= 
sizeof(tempname)) Rf_error("file name is too long");

BTW: most OSes systems have a path limits that are no lower than 256 so you 
should allow at least as much.

Cheers,
Simon




> On May 29, 2019, at 11:49 AM, jing hua zhao  wrote:
> 
> Dear R-developers,
> 
> I am struggling with packaging with sprintf and snprintf() as the following 
> WARNINGS from gcc 9.x,
> 
>  hap_c.c:380:46: warning: �%d� directive output may be truncated writing 
> between 1 and 10 bytes into a region of size between 0 and 127 
> [-Wformat-truncation=]
>  hap_c.c:392:46: warning: �%d� directive output may be truncated writing 
> between 1 and 10 bytes into a region of size between 0 and 127 
> [-Wformat-truncation=]
> 
> Essentially, I have
> 
> #define MAX_FILENAME_LEN 128
> char of1name[MAX_FILENAME_LEN],of2name[MAX_FILENAME_LEN], 
> tempname[MAX_FILENAME_LEN];
> 
> ...
> 
> snprintf(tempname,sizeof(tempname),"%s.%d", of1name, j);
> 
> It looks I could get around with
> 
> 
> #define MAX_FILENAME_LEN 128
> 
> #define MAX_FILENAME_LEN2 256
> 
> char of1name[MAX_FILENAME_LEN],of2name[MAX_FILENAME_LEN], 
> tempname[MAX_FILENAME_LEN2];
> 
> ...
> snprintf(tempname,2*sizeof(tempname)+1,"%s.%d", of1name, j)
> 
> It looks a bit waste of resources to me.
> 
> 
> Any idea will be greatly appreciated,
> 
> 
> 
> Jing Hua
> 
>   [[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] use of buffers in sprintf and snprintf

2019-05-30 Thread Henrik Bengtsson
On Thu, May 30, 2019 at 7:21 PM Simon Urbanek
 wrote:
>
> No, that will make it even worse since you'll be declaring a lot more memory 
> that you actually have.
>
> The real problem is that you're ignoring the truncation, so you probably want 
> to use something like
>
> if (snprintf(tempname, sizeof(tempname), "%s.%d", of1name, j) >= 
> sizeof(tempname)) Rf_error("file name is too long");
>
> BTW: most OSes systems have a path limits that are no lower than 256 so you 
> should allow at least as much.

On MS Windows, there's actually a limit of 255 characters, cf.
http://www.aroma-project.org/howtos/UseLongFilenamesOnWindows/
(disclaimer: I'm the author).  Note particularly the comment at the
end:

"Unfortunately it is not a solution to try to use relative instead of
absolute pathnames. The limitation is deep down in the file system
itself and it is the absolute pathname that counts."

Admittedly, it's been several years when I last looked into it, but at
the time when I wrote that I spent lots of time investigating it.

/Henrik

>
> Cheers,
> Simon
>
>
>
>
> > On May 29, 2019, at 11:49 AM, jing hua zhao  wrote:
> >
> > Dear R-developers,
> >
> > I am struggling with packaging with sprintf and snprintf() as the following 
> > WARNINGS from gcc 9.x,
> >
> >  hap_c.c:380:46: warning: �%d� directive output may be truncated writing 
> > between 1 and 10 bytes into a region of size between 0 and 127 
> > [-Wformat-truncation=]
> >  hap_c.c:392:46: warning: �%d� directive output may be truncated writing 
> > between 1 and 10 bytes into a region of size between 0 and 127 
> > [-Wformat-truncation=]
> >
> > Essentially, I have
> >
> > #define MAX_FILENAME_LEN 128
> > char of1name[MAX_FILENAME_LEN],of2name[MAX_FILENAME_LEN], 
> > tempname[MAX_FILENAME_LEN];
> >
> > ...
> >
> > snprintf(tempname,sizeof(tempname),"%s.%d", of1name, j);
> >
> > It looks I could get around with
> >
> >
> > #define MAX_FILENAME_LEN 128
> >
> > #define MAX_FILENAME_LEN2 256
> >
> > char of1name[MAX_FILENAME_LEN],of2name[MAX_FILENAME_LEN], 
> > tempname[MAX_FILENAME_LEN2];
> >
> > ...
> > snprintf(tempname,2*sizeof(tempname)+1,"%s.%d", of1name, j)
> >
> > It looks a bit waste of resources to me.
> >
> >
> > Any idea will be greatly appreciated,
> >
> >
> >
> > Jing Hua
> >
> >   [[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

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


[Rd] [patch] add sanity checks to quantile()

2019-05-30 Thread Scott Kostyshak
The attached patch adds some sanity checks to the "type" argument of
quantile(). Output from the following commands show the change of
behavior with the current patch:

  vec <- 1:10
  quantile(vec, type = c(1, 2))
  quantile(vec, type = 10)
  quantile(vec, type = "aaa")
  quantile(vec, type = NA_real_)
  quantile(vec, type = 4.3)
  quantile(vec, type = -1)

Current behavior (i.e., without the patch):

  > vec <- 1:10
  > quantile(vec, type = c(1, 2))
  Error in switch(type, (nppm > j), ((nppm > j) + 1)/2, (nppm != j) | ((j%%2L) 
==  : 
EXPR must be a length 1 vector
  In addition: Warning messages:
  1: In if (type == 7) { :
the condition has length > 1 and only the first element will be used
  2: In if (type <= 3) { :
the condition has length > 1 and only the first element will be used
  3: In if (type == 3) n * probs - 0.5 else n * probs :
the condition has length > 1 and only the first element will be used
  > quantile(vec, type = 10)
  Error in quantile.default(vec, type = 10) : object 'a' not found
  > quantile(vec, type = "aaa")
  Error in type - 3 : non-numeric argument to binary operator
  > quantile(vec, type = NA_real_)
  Error in if (type == 7) { : missing value where TRUE/FALSE needed
  > quantile(vec, type = 4.3)
0%  25%  50%  75% 100% 
   1.0  2.5  5.0  7.5 10.0 
  > quantile(vec, type = -1)
0%  25%  50%  75% 100% 
 1257   10 


Behavior with the patch:

  > vec <- 1:10
  > quantile(vec, type = c(1, 2))
  Error in quantile.default(vec, type = c(1, 2)) : 
'type' must be of length 1
  > quantile(vec, type = 10)
  Error in quantile.default(vec, type = 10) : 
'type' must be an integer between 1 and 9
  > quantile(vec, type = "aaa")
  Error in quantile.default(vec, type = "aaa") : 
'type' must be an integer between 1 and 9
  > quantile(vec, type = NA_real_)
  Error in quantile.default(vec, type = NA_real_) : 
'type' must be an integer between 1 and 9
  > quantile(vec, type = 4.3)
  Error in quantile.default(vec, type = 4.3) : 
'type' must be an integer between 1 and 9
  > quantile(vec, type = -1)
  Error in quantile.default(vec, type = -1) : 
'type' must be an integer between 1 and 9


Note that with the patch, quantile() gives an error in some cases where
the current code does not. Specifically, the following two calls to
quantile() do not give an error without the patch:

  quantile(vec, type = 4.3)
  quantile(vec, type = -1)

Thus, this patch could cause current code to give an error. If it is
desired, I could change the patch such that it only gives an error when
current R gives an error (i.e., the only benefit of the patch would be
better error messages), or I can change the patch to give a warning in
these cases.

Scott


-- 
Scott Kostyshak
Assistant Professor of Economics
University of Florida
https://people.clas.ufl.edu/skostyshak/

Index: src/library/stats/R/quantile.R
===
--- src/library/stats/R/quantile.R	(revision 76528)
+++ src/library/stats/R/quantile.R	(working copy)
@@ -25,6 +25,12 @@
 function(x, probs = seq(0, 1, 0.25), na.rm = FALSE, names = TRUE,
  type = 7, ...)
 {
+if (length(type) != 1L) {
+stop("'type' must be of length 1")
+}
+if (is.na(type) || !is.numeric(type) || !any(type == 1:9)) {
+stop("'type' must be an integer between 1 and 9")
+}
 if(is.factor(x)) {
 	if(is.ordered(x)) {
 	   if(!any(type == c(1L, 3L)))
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel