Displaying 20 results from an estimated 20000 matches similar to: "Misinformative error message for vector()"
2018 Jan 25
2
sum() returns NA on a long *logical* vector when nb of TRUE values exceeds 2^31
Just following up on this old thread since matrixStats 0.53.0 is now
out, which supports this use case:
> x <- rep(TRUE, times = 2^31)
> y <- sum(x)
> y
[1] NA
Warning message:
In sum(x) : integer overflow - use sum(as.numeric(.))
> y <- matrixStats::sum2(x, mode = "double")
> y
[1] 2147483648
> str(y)
num 2.15e+09
No coercion is taking place, so the
2015 May 04
4
Shouldn't vector indexing with negative out-of-range index give an error?
In Section 'Indexing by vectors' of 'R Language Definition'
(http://cran.r-project.org/doc/manuals/r-release/R-lang.html#Indexing-by-vectors)
it says:
"Integer. All elements of i must have the same sign. If they are
positive, the elements of x with those index numbers are selected. If
i contains negative elements, all elements except those indicated are
selected.
If i is
2018 Mar 15
2
clusterApply arguments
Thank you for your answer!
I agree with you except for the 3 (Error) example and
I realize now I should have started with that in the explanation.
>From my point of view
parLapply(cl = clu, X = 1:2, fun = fun, c = 1)
shouldn't give an error.
This could be easily avoided by using all the argument
names in the custerApply call of parLapply which means changing,
parLapply <-
2016 May 04
4
Is it possible to retrieve the last error? (not error *message*)
Hi,
at the R prompt, is it possible to retrieve the last error (as in
condition object of class "error")?
I'm not asking for geterrmessage(), which only returns the error
message (as a character string). I'm basically looking for a
.Last.error or .Last.condition, analogously to .Last.value for values,
which can be used when it is "too late" (not possible) to go back
2002 Jun 27
2
Fastest way to find the last index k such that x[k] < y in a sorted vector x?
Hi, I am trying to find the fastest way to
"find the last index k such that x[k] < y in a *sorted* vector x"
These are my two alternatives:
x <- sort(rnorm(1e4))
y <- 0.2
# Alt 1
k <- max(1, sum(x < y))
# Alt 2 "divide and conquer"
lastIndexLessThan <- function(x, y) {
k0 <- 1; k1 <- length(x)
while ((dk <- (k1 - k0)) >
2018 Jan 30
2
sum() returns NA on a long *logical* vector when nb of TRUE values exceeds 2^31
Hi Martin, Henrik,
Thanks for the follow up.
@Martin: I vote for 2) without *any* hesitation :-)
(and uniformity could be restored at some point in the
future by having prod(), rowSums(), colSums(), and others
align with the behavior of length() and sum())
Cheers,
H.
On 01/27/2018 03:06 AM, Martin Maechler wrote:
>>>>>> Henrik Bengtsson <henrik.bengtsson at gmail.com>
2015 May 06
1
Shouldn't vector indexing with negative out-of-range index give an error?
On Wed, May 6, 2015 at 1:33 AM, Martin Maechler
<maechler at lynne.stat.math.ethz.ch> wrote:
>>>>>> John Chambers <jmc at stat.stanford.edu>
>>>>>> on Tue, 5 May 2015 08:39:46 -0700 writes:
>
> > When someone suggests that we "might have had a reason" for some peculiarity in the original S, my usual reaction is "Or
2018 Mar 15
1
clusterApply arguments
On 03/15/2018 05:25 PM, Henrik Bengtsson wrote:
> On Thu, Mar 15, 2018 at 3:39 AM, <FlorianSchwendinger at gmx.at> wrote:
>> Thank you for your answer!
>> I agree with you except for the 3 (Error) example and
>> I realize now I should have started with that in the explanation.
>>
>> From my point of view
>> parLapply(cl = clu, X = 1:2, fun = fun, c =
2002 Jan 24
3
Best way to check/assert a certain version of or a package
When loading a package with library(APkg) or require(APkg) I would like to
make sure that (1) the correct version of [R] is installed. If not an
informative error message should be given. I would also like to make sure
that (2) another required package which is loaded from within the APkg
package (by require(OtherPkg)) is of a certain version or later.
First of all, I believe that the check
Suggestion for exception handling: More informative error message for "no applicable method..." (S3)
2009 Oct 20
1
Suggestion for exception handling: More informative error message for "no applicable method..." (S3)
I'd like to suggest that whenever there is no S3 method implementation
available for a particular class, that the error message would also
report the class structure of the object dispatched on.
Example:
foo <- function(...) UseMethod("foo")
foo.ClassA <- function(object, ...) { cat("foo() for ClassA called.\n") }
> foo(structure(1, class="ClassA"))
2014 Oct 24
1
No error when assigning values to an "empty" vector/matrix/array
Assigning one or more values to a vector/matrix/array x for which
length(x) == 0 gives no error, e.g.
> x <- integer(0)
> x[] <- 1:2
> x <- matrix(nrow=0, ncol=1)
> x[] <- 1:2
> x[,1] <- 1:2
> x <- array(dim=c(0,1,1))
> x[] <- 1:2
> x[,1,1] <- 1:2
whereas
> x <- integer(1)
> x[] <- 1:2
Warning message:
In x[] <- 1:2 :
number of
2015 Sep 20
2
Long vectors: Missing values and R_xlen_t?
Is there a missing value constant defined for R_xlen_t, cf. NA_INTEGER
(== R_NaInt == INT_MIN) for int(eger)? If not, is it correct to
assume that missing values should be taken care/tested for before
coercing from int or double?
Thank you,
Henrik
2011 May 12
3
Reproducible use case for R crash after updating R
This might have been discussed before, but below is a
"not-so-unlikely" use case where the user follows normal procedures,
updates R to a major release version, and then R crashes:
1. Use runs R stable (e.g. v2.13.0).
2. User installs a package with a namespace, e.g. install.packages("fortunes").
3. User uses the package and one of the package's objects are assigned
to the
2010 Nov 23
1
Possibility for memory improvement: x <- as.vector(x) always(?) duplicates
Hi,
I've noticed that as.vector() always allocates a new object, e.g.
> x <- 1:10;
> x <- as.vector(x);
> tracemem(x);
[1] "<0x0000000005622db8"
> x <- as.vector(x);
tracemem[0x0000000005622db8 -> 0x0000000005622ec0]: as.vector
> x <- as.vector(x);
tracemem[0x0000000005622ec0 -> 0x0000000005622f18]: as.vector
> x <- as.vector(x);
2015 May 26
2
MetaCran website v1.0.0-alpha
On Tue, May 26, 2015 at 12:45 AM, G?bor Cs?rdi <csardi.gabor at gmail.com> wrote:
> On Mon, May 25, 2015 at 8:28 PM, Simon Urbanek <simon.urbanek at r-project.org>
> wrote:
>
>> One issue I have with this is that it doesn't point to the original GitHub
>> repositories of the packages, so you end up with additional repositories on
>> Github in Gabor's
2009 Jan 12
1
x <- 1:2; dim(x) <- 2? A vector or not?
Ran into the follow intermediate case in an external package (w/
recent R v2.8.1 patched and R v2.9.0 devel):
> x <- 1:2
> dim(x) <- 2
> dim(x)
[1] 2
> x
[1] 1 2
> str(x)
int [, 1:2] 1 2
> nrow(x)
[1] 2
> ncol(x)
[1] NA
> is.vector(x)
[1] FALSE
> is.matrix(x)
[1] FALSE
> is.array(x)
[1] TRUE
> x[1]
[1] 1
> x[,1]
Error in x[, 1] : incorrect number of
2019 Dec 06
2
long vector support
All,
At first glance, a recent commit to R-devel (
https://github.com/wch/r-source/commit/2c182014ecc8c2407a89092c9162d86046bd18da)
appears to be related to long vector support. But as Henrik Bengtsson
points out at
https://github.com/HenrikBengtsson/Wishlist-for-R/issues/97#issuecomment-562659134,
writeBin() still prohibits long vectors. Are there any plans to add long
vector support to R
2006 May 05
4
str() with attr(*, "names") is extremely slow for long vectors
Hi,
I noticed some time ago that, for instance, named vectors that are
really makes str() really slow when displaying the names attribute. I
don't know exactly when this started, but it wasn't the case say 1-2
years ago. Example (on a WinXP 1.8GHz):
> s <- 1:1000; names(s) <- s
> system.time(str(s))
Named int [1:1000] 1 2 3 4 5 6 7 8 9 10 ...
- attr(*, "names")=
2018 May 07
2
download.file does not process gz files correctly (truncates them?)
Thanks for the comments, feedback, and improvements.
I still argue that the current behavior cause more harm than it helps.
First of all, it increases the risk for code that does not work on all
platforms, which I'd say is one of the strengths and design goals of
R. To write cross-platform code, a developer basically needs to
specify argument 'mode'.
A second problem is that people
2017 Jun 02
4
sum() returns NA on a long *logical* vector when nb of TRUE values exceeds 2^31
Hi,
I have a long numeric vector 'xx' and I want to use sum() to count
the number of elements that satisfy some criteria like non-zero
values or values lower than a certain threshold etc...
The problem is: sum() returns an NA (with a warning) if the count
is greater than 2^31. For example:
> xx <- runif(3e9)
> sum(xx < 0.9)
[1] NA
Warning message:
In sum(xx