Re: [Rd] Strange behaviour of the ':' operator
>From the help page ?':' we can read: "Value ‘to’ will be included if it differs from ‘from’ by an integer up to a numeric fuzz of about ‘1e-7’." So it looks like it is the intended behavior. On Sun, Apr 27, 2014 at 5:38 AM, Hans W Borchers wrote: > Is the following really intended behaviour of the ':' operator, > > > s <- pi - 3.0 + 1e-07 > > x <- s:pi > > x > [1] 0.1415928 1.1415928 2.1415928 3.1415928 > > though the last entry in the range vector is greater than pi? > > > x[4] > pi; x[4] - pi > [1] TRUE > [1] 1e-07 > > and the same, of course, for the seq() function. > I would understand this behaviour for 1e-14 or so, but it seems > unexpected for such a distinct difference as 1e-07. > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Strange behaviour of the ':' operator
Is the following really intended behaviour of the ':' operator, > s <- pi - 3.0 + 1e-07 > x <- s:pi > x [1] 0.1415928 1.1415928 2.1415928 3.1415928 though the last entry in the range vector is greater than pi? > x[4] > pi; x[4] - pi [1] TRUE [1] 1e-07 and the same, of course, for the seq() function. I would understand this behaviour for 1e-14 or so, but it seems unexpected for such a distinct difference as 1e-07. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Strange behaviour of the [[ operator
On 9/30/2006 10:39 AM, Martin Maechler wrote: >> "Herve" == Herve Pages <[EMAIL PROTECTED]> >> on Fri, 29 Sep 2006 18:06:41 -0700 writes: > > Herve> Hi, > Herve> This looks like a bug: > hmm, maybe... > or maybe not; I vaguely recall that this is documented somewhere... > > >> a <- list(b=5) > >> a[['b']] > Herve> [1] 5 > >> a[[t<-'b']] > > Herve> Nothing gets printed! > > Yes, but that is not really much related to "[[" > but rather to "<-" which momentarily turns off auto-printing. I think this is probably not intentional, because the behaviour is so inconsistent. In names.c, the "eval" entry for "[" and "[[" is 0, which is supposed to indicate R_Visible is on. It's the same as for c(), substitute(), quote(), interactive(), expression(), nargs(), and those return a visible result. On the other hand, dim(), dimnames(), as.character(), call(), rep(), seq.int(), seq_along() also have eval=0, and they give an invisible result. Among the eval=10 functions, I see visible results from unlist(), cbind(), rbind(), and invisible ones from sys.parent(), sys.call() etc., parent.frame(), and so on (I gave up testing at this point). I suspect the problem is that these are low level functions where the evaluator does almost nothing automatically, and handling R_Visible was just overlooked. Duncan Murdoch > > Similar things happen in many similar circumstances. > > Herve> I need to use parenthesis to see the expected result: > > >> a[[(t<-'b')]] > Herve> [1] 5 > > Herve> Cheers, > Herve> H. > > Martin > > __ > 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] Strange behaviour of the [[ operator
True, re name matching, but I think we might want to consider a warning if they are supplied as the user may not be getting what they expect, regardless of the documentation Peter Dalgaard wrote: > Seth Falcon <[EMAIL PROTECTED]> writes: > >>> Similar things happen in many similar circumstances. >> Here's a similar thing: > > Not really, no? > >>> v <- 1:5 >>> v >> [1] 1 2 3 4 5 >>> v[mustBeDocumentedSomewhere=3] >> [1] 3 >> >> And this can be confusing if one thinks that subsetting is really a >> function and behaves like other R functions w.r.t. to treatment of >> named arguments: >> >>> m <- matrix(1:4, nrow=2) >>> m >> [,1] [,2] >> [1,]13 >> [2,]24 >>> m[j=2] >> [1] 2 > > Or even >> m[j=2,i=] > [1] 2 4 > > However, what would the argument names be in the >2-dim case? i, j are > used only in help("[") and that page is quite specific about > explaining that named matching doesn't work. > -- Robert Gentleman, PhD Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M2-B876 PO Box 19024 Seattle, Washington 98109-1024 206-667-7700 [EMAIL PROTECTED] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Strange behaviour of the [[ operator
Seth Falcon <[EMAIL PROTECTED]> writes: > > Similar things happen in many similar circumstances. > > Here's a similar thing: Not really, no? > > v <- 1:5 > > v > [1] 1 2 3 4 5 > > v[mustBeDocumentedSomewhere=3] > [1] 3 > > And this can be confusing if one thinks that subsetting is really a > function and behaves like other R functions w.r.t. to treatment of > named arguments: > > > m <- matrix(1:4, nrow=2) > > m > [,1] [,2] > [1,]13 > [2,]24 > > m[j=2] > [1] 2 Or even > m[j=2,i=] [1] 2 4 However, what would the argument names be in the >2-dim case? i, j are used only in help("[") and that page is quite specific about explaining that named matching doesn't work. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Strange behaviour of the [[ operator
Martin Maechler <[EMAIL PROTECTED]> writes: > >> a <- list(b=5) > >> a[['b']] > Herve> [1] 5 > >> a[[t<-'b']] > > Herve> Nothing gets printed! > > Yes, but that is not really much related to "[[" > but rather to "<-" which momentarily turns off auto-printing. Yes, not being related to "[[" is exactly why it is surprising. I would expect vv[[f(x)]] to print regardless of f's auto-printing behavior. f1 <- function(x) x f2 <- function(x) return(invisible(x)) a <- list(b=5) a[[f1("a")]] a[[f2("a")]] > Similar things happen in many similar circumstances. Here's a similar thing: > v <- 1:5 > v [1] 1 2 3 4 5 > v[mustBeDocumentedSomewhere=3] [1] 3 And this can be confusing if one thinks that subsetting is really a function and behaves like other R functions w.r.t. to treatment of named arguments: > m <- matrix(1:4, nrow=2) > m [,1] [,2] [1,]13 [2,]24 > m[j=2] [1] 2 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Strange behaviour of the [[ operator (PR#9263)
Hi Duncan, This is even more confusing with a matrix: > x <- matrix(5:-6, 3) > x [,1] [,2] [,3] [,4] [1,]52 -1 -4 [2,]41 -2 -5 [3,]30 -3 -6 > x[invisible(2),3] [1] -2 > x[2,invisible(3)] > .Last.value [1] -2 Thanks, H. Quoting [EMAIL PROTECTED]: > On 9/29/2006 9:06 PM, Herve Pages wrote: > > Hi, > > > > This looks like a bug: > > > > > a <- list(b=5) > > > a[['b']] > > [1] 5 > > > a[[t<-'b']] > > > > Nothing gets printed! > > > > I need to use parenthesis to see the expected result: > > > > > a[[(t<-'b')]] > > [1] 5 > > Yes, I agree it looks like a bug, and it's still there in R-devel. The > problem is that the assignment sets the R_Visible flag to false, and the > indexing never sets it to true. The same problem happens with a[t <- > 'b'], whether a is a list or not: > > > a <- c(b=5, c=6, d=7) > > a[t <- 'b'] > > .Last.value > b > 5 > > Duncan Murdoch > > __ > 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] Strange behaviour of the [[ operator
> "Herve" == Herve Pages <[EMAIL PROTECTED]> > on Fri, 29 Sep 2006 18:06:41 -0700 writes: Herve> Hi, Herve> This looks like a bug: hmm, maybe... or maybe not; I vaguely recall that this is documented somewhere... >> a <- list(b=5) >> a[['b']] Herve> [1] 5 >> a[[t<-'b']] Herve> Nothing gets printed! Yes, but that is not really much related to "[[" but rather to "<-" which momentarily turns off auto-printing. Similar things happen in many similar circumstances. Herve> I need to use parenthesis to see the expected result: >> a[[(t<-'b')]] Herve> [1] 5 Herve> Cheers, Herve> H. Martin __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Strange behaviour of the [[ operator (PR#9263)
On 9/29/2006 9:06 PM, Herve Pages wrote: > Hi, > > This looks like a bug: > > > a <- list(b=5) > > a[['b']] > [1] 5 > > a[[t<-'b']] > > Nothing gets printed! > > I need to use parenthesis to see the expected result: > > > a[[(t<-'b')]] > [1] 5 Yes, I agree it looks like a bug, and it's still there in R-devel. The problem is that the assignment sets the R_Visible flag to false, and the indexing never sets it to true. The same problem happens with a[t <- 'b'], whether a is a list or not: > a <- c(b=5, c=6, d=7) > a[t <- 'b'] > .Last.value b 5 Duncan Murdoch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Strange behaviour of the [[ operator
Hi, This looks like a bug: > a <- list(b=5) > a[['b']] [1] 5 > a[[t<-'b']] Nothing gets printed! I need to use parenthesis to see the expected result: > a[[(t<-'b')]] [1] 5 Cheers, H. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel