Re: [R] How to use ifelse without invoking warnings

2021-10-09 Thread Leonard Mada via R-help
Dear Ravi, I have uploaded on GitHub a version which handles also constant values instead of functions. Regarding named arguments: this is actually handled automatically as well: eval.by.formula((x > 5 & x %% 2) ~ (x <= 5) ~ ., FUN, y=2, x) # [1]  1  4  9 16 25  6 14  8 18 10

Re: [R] How to use ifelse without invoking warnings

2021-10-09 Thread Leonard Mada via R-help
Dear Ravi, I wrote a small replacement for ifelse() which avoids such unnecessary evaluations (it bothered me a few times as well - so I decided to try a small replacement). ### Example: x = 1:10 FUN = list(); FUN[[1]] = function(x, y) x*y; FUN[[2]] = function(x, y) x^2; FUN[[3]] =

Re: [R] How to use ifelse without invoking warnings

2021-10-08 Thread Deepayan Sarkar
yes; tmp[!test] <- no[!test]; tmp) , possibly extended to handle missing values in 'test'. Best, -Deepayan > Thanks & Best regards, > Ravi > > From: John Fox > Sent: Thursday, October 7, 2021 2:00 PM > To: Ravi Varadhan > Cc:

Re: [R] How to use ifelse without invoking warnings

2021-10-08 Thread Jeff Newmiller
his behavior. > >Thanks & Best regards, >Ravi > >From: John Fox >Sent: Thursday, October 7, 2021 2:00 PM >To: Ravi Varadhan >Cc: R-Help >Subject: Re: [R] How to use ifelse without invoking warnings > > > External Email

Re: [R] How to use ifelse without invoking warnings

2021-10-08 Thread Avi Gross via R-help
i Varadhan via R-help Sent: Friday, October 8, 2021 8:22 AMiu To: John Fox l Cc: R-Help Subject: Re: [R] How to use ifelse without invoking warnings Thank you to Bert, Sarah, and John. I did consider suppressing warnings, but I felt that there must be a more principled approach. While John's so

Re: [R] How to use ifelse without invoking warnings

2021-10-08 Thread Ravi Varadhan via R-help
Ravi From: John Fox Sent: Thursday, October 7, 2021 2:00 PM To: Ravi Varadhan Cc: R-Help Subject: Re: [R] How to use ifelse without invoking warnings External Email - Use Caution Dear Ravi, It's already been suggested that you could disable warnings, but th

Re: [R] How to use ifelse without invoking warnings

2021-10-08 Thread John Fox
arguments. Best, John Thanks & Best regards, Ravi *From:* John Fox *Sent:* Thursday, October 7, 2021 2:00 PM *To:* Ravi Varadhan *Cc:* R-Help *Subject:* Re: [R] How to use ifelse without invoking warn

Re: [R] How to use ifelse without invoking warnings

2021-10-07 Thread John Fox
Dear Ravi, It's already been suggested that you could disable warnings, but that's risky in case there's a warning that you didn't anticipate. Here's a different approach: > kk <- k[k >= -1 & k <= n] > ans <- numeric(length(k)) > ans[k > n] <- 1 > ans[k >= -1 & k <= n] <- pbeta(p, kk + 1, n

Re: [R] How to use ifelse without invoking warnings

2021-10-07 Thread Sarah Goslee
Bert's approach is much less risky! On Thu, Oct 7, 2021 at 1:37 PM Bert Gunter wrote: > > ?suppressWarnings > > > p <- .05 > > k <- c(-1.2,-0.5, 1.5, 10.4) > > n <- 10 > > > > ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), > ifelse (k < -1, 0, 1) ) > Warning message: > In

Re: [R] How to use ifelse without invoking warnings

2021-10-07 Thread Sarah Goslee
If you are positive the warnings don't matter for your application, you can disable them: see ?options for details of warn. But that can be dangerous, so be careful! Sarah On Thu, Oct 7, 2021 at 1:21 PM Ravi Varadhan via R-help wrote: > > Hi, > I would like to execute the following vectorized

Re: [R] How to use ifelse without invoking warnings

2021-10-07 Thread Bert Gunter
?suppressWarnings > p <- .05 > k <- c(-1.2,-0.5, 1.5, 10.4) > n <- 10 > > ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), ifelse (k < -1, 0, 1) ) Warning message: In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced > > suppressWarnings(ans <- ifelse (k >= -1 & k <=

[R] How to use ifelse without invoking warnings

2021-10-07 Thread Ravi Varadhan via R-help
Hi, I would like to execute the following vectorized calculation: ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE), ifelse (k < -1, 0, 1) ) For example: > k <- c(-1.2,-0.5, 1.5, 10.4) > n <- 10 > ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE),