[Rd] bug in approx crashes R
Vadim Ogranovich
vogranovich at jumptrading.com
Mon Jul 27 19:47:47 CEST 2009
Thank you Bill.
The original motivation for my experiments with setting yleft to NULL was to see if I could get more flexibility that that allowed by the 'rule' argument. To recall:
rule: an integer describing how interpolation is to take place
outside the interval ['min(x)', 'max(x)']. If 'rule' is '1'
then 'NA's are returned for such points and if it is '2', the
value at the closest data extreme is used.
What I wanted is to interpolate at the left end, but not at the right end. Still don't know how to do that.
I agree that having a clear error message when yleft, yright, and f are set to non-scalars is better than silently returning NA.
Thanks,
Vadim
-----Original Message-----
From: William Dunlap [mailto:wdunlap at tibco.com]
Sent: Monday, July 27, 2009 12:14 PM
To: Vadim Ogranovich; r-devel at r-project.org
Subject: RE: [Rd] bug in approx crashes R
The C code called by approx (via .C, not .Call), following the help
file,
assumes that yleft and yright are scalars but NULL is not scalar.
The following change would let your example work (returning NA)
--- R/approx.R (revision 48911)
+++ R/approx.R (working copy)
@@ -61,8 +61,8 @@
}
y <- .C("R_approx", as.double(x), as.double(y), as.integer(nx),
xout = as.double(xout), as.integer(length(xout)),
- as.integer(method), as.double(yleft), as.double(yright),
- as.double(f), NAOK = TRUE, PACKAGE = "stats")$xout
+ as.integer(method), as.double(yleft)[1],
as.double(yright)[1],
+ as.double(f)[1], NAOK = TRUE, PACKAGE = "stats")$xout
list(x = xout, y = y)
}
but I think it would be better to get an error message that yleft,
yright, and f are expected to be scalar:
--- R/approx.R (revision 48911)
+++ R/approx.R (working copy)
@@ -59,6 +59,7 @@
stop("'approx' requires n >= 1")
xout <- seq.int(x[1L], x[nx], length.out = n)
}
+ stopifnot(length(yleft)==1, length(yright)==1, length(f)==1)
y <- .C("R_approx", as.double(x), as.double(y), as.integer(nx),
xout = as.double(xout), as.integer(length(xout)),
as.integer(method), as.double(yleft), as.double(yright),
Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com
> -----Original Message-----
> From: r-devel-bounces at r-project.org
> [mailto:r-devel-bounces at r-project.org] On Behalf Of Vadim Ogranovich
> Sent: Tuesday, July 21, 2009 12:24 PM
> To: 'r-devel at r-project.org'
> Subject: [Rd] bug in approx crashes R
>
> Dear R-devel,
>
> The following line crashes R
> > approx(1, 1, 0, method='const', rule=2, f=0, yleft=NULL,
> ties='ordered')$y
>
> Process R:2 exited abnormally with code 5 at Tue Jul 21 14:18:09 2009
>
>
> > version
> _
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status
> major 2
> minor 9.1
> year 2009
> month 06
> day 26
> svn rev 48839
> language R
> version.string R version 2.9.1 (2009-06-26)
>
> Thanks,
> Vadim
>
> Note: This email is for the confidential use of the named
> addressee(s) only and may contain proprietary, confidential
> or privileged information. If you are not the intended
> recipient, you are hereby notified that any review,
> dissemination or copying of this email is strictly
> prohibited, and to please notify the sender immediately and
> destroy this email and any attachments. Email transmission
> cannot be guaranteed to be secure or error-free. Jump
> Trading, therefore, does not make any guarantees as to the
> completeness or accuracy of this email or any attachments.
> This email is for informational purposes only and does not
> constitute a recommendation, offer, request or solicitation
> of any kind to buy, sell, subscribe, redeem or perform any
> type of transaction of a financial product.
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
Note: This email is for the confidential use of the named addressee(s) only and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you are hereby notified that any review, dissemination or copying of this email is strictly prohibited, and to please notify the sender immediately and destroy this email and any attachments. Email transmission cannot be guaranteed to be secure or error-free. Jump Trading, therefore, does not make any guarantees as to the completeness or accuracy of this email or any attachments. This email is for informational purposes only and does not constitute a recommendation, offer, request or solicitation of any kind to buy, sell, subscribe, redeem or perform any type of transaction of a financial product.
More information about the R-devel
mailing list