similar to: Extending suggestion for stopifnot

Displaying 20 results from an estimated 8000 matches similar to: "Extending suggestion for stopifnot"

2013 Feb 04
2
Contract Syntactic Sugar
## the following is a dream: add some sugar syntax to allow for contracts with teeth (in and out checking) > is.positive <- function(x) (all(x>0)) > exponentiate <- function( x ::is.data.frame , exponent ::is.numeric is.positive) :: is.vector is.numeric { x$base :: is.positive ## error also if base does not exist in x; may need some special IQ x$base^exponent }
2004 May 14
3
type checking --- just a thought
hi: would it be useful to build into R an optional mechanism that typechecks arguments? for example, sum.across <- function ( inpmatrix : matrixtype( dim[1]>1, dim[2]>3 ) ) : vector { } # this would define a sum.across function that can take matrices or data sets, but not vectors, # and which indicates that it will return a vector. xsum <- sum.across( 1:10
2010 Oct 24
1
more errors (behavior)
quick programming question. I am not making enough errors in my programs, so I want to trigger a few more. ;-) [1] undefined variable behavior: > d=data.frame( x=rnorm(1:10), y=rnorm(1:10)) > z Error: object 'z' not found > d$z NULL is this consistent? I thought that z is the same as .GlobalEnv$z, but apparently it is not. something here is smart enough to trigger an error.
2013 Feb 06
5
First R Package --- Advice?
Dear R experts--- after many years, I am planning to give in and write my first R package. I want to combine my collection of collected useful utility routines. as my guide, I am planning to use Friedrich Leisch's "Creating R Packages: A Tutorial" from Sep 2009. Is there a newer or better tutorial? this one is 4 years old. I also plan on one change---given that the
2011 Apr 02
1
uniroot speed and vectorization?
curiosity---given that vector operations are so much faster than scalar operations, would it make sense to make uniroot vectorized? if I read the uniroot docs correctly, uniroot() calls an external C routine which seems to be a scalar function. that must be slow. I am thinking a vectorized version would be useful for an example such as of <- function(x,a) ( log(x)+x+a ) uniroot( of, c(
2012 Mar 15
1
how to assign "writeLines" function
hi, what I want to do is assigning following code to any object. k<-paste("thank") writeLines(strwrap(k, width = 80,indent = 7,exdent = 6)) To assign the "writeLines" code, I try this a<-writeLines(strwrap(k, width = 80,indent = 7,exdent = 6)) or assign(a,writeLines(strwrap(k, width = 80,indent = 7,exdent = 6))) but it doesn't work. is there any way to solve
2010 Sep 23
1
Newey West and Singular Matrix + library(sandwich)
thank you, achim. I will try chol2inv. sandwich is a very nice package, but let me make some short suggestions. I am not a good econometrician, so I do not know what prewhitening is, and the vignette did not explain it. "?coeftest" did not work after I loaded the library. automatic bandwidth selection can be a good thing, but is not always. as to my own little function, I like the
2006 Mar 01
1
stopifnot() suggestion
If an expression is passed to stopifnot() which contains missing values, then the resulting error message is somewhat baffling until you are used to it, e.g. > x <- y <- rep(TRUE, 10) > y[7] <- NA > stopifnot(x, y) Error in if (!(is.logical(r <- eval(ll[[i]])) && all(r))) stop(paste(deparse(mc[[i + : missing value where TRUE/FALSE needed A minor change to
2019 Feb 24
1
stopifnot
>From https://github.com/HenrikBengtsson/Wishlist-for-R/issues/70 : ... and follow up note from 2018-03-15: Ouch... in R-devel, stopifnot() has become yet 4-5 times slower; ... which is due to a complete rewrite using tryCatch() and withCallingHandlers(). >From https://stat.ethz.ch/pipermail/r-devel/2017-May/074256.html , it seems that 'tryCatch' was used to avoid the following
2017 May 15
3
stopifnot() does not stop at first non-TRUE argument
I think Herv?'s idea was just that if switch can evaluate arguments selectively, so can stopifnot(). But switch() is .Primitive, so does it from C. I think it is almost a no-brainer to implement a sequential stopifnot if dropping to C code is allowed. In R it gets trickier, but how about this: Stopifnot <- function(...) { n <- length(match.call()) - 1 for (i in 1:n) { nm
2019 May 30
2
stopifnot
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 +0000 +++ stop_new.R 2019-05-30 14:01:51.372187466 +0000 @@ -31,7 +31,7 @@ .Internal(stop(call., .makeMessage(..., domain = domain))) }
2018 Mar 12
0
Bug report: override stopifnot() ?
Why don't you use stopifnot( all(m1 == m2) ) ? Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Mar 12, 2018 at 8:15 AM, Stepan Kasal <kasal at ucw.cz> wrote: > Hello, > I stumbled over a problem: > stopifnot(m1 == m2) > > It works with vector or matrix, but does not work for classes from Matrix > package. > > In the source of stopifnot(), there is
2017 May 16
3
stopifnot() does not stop at first non-TRUE argument
switch(i, ...) extracts 'i'-th argument in '...'. It is like eval(as.name(paste0("..", i))) . Just mentioning other things: - For 'n', n <- nargs() can be used. - sys.call() can be used in place of match.call() . --------------------------- >>>>> peter dalgaard <pdalgd at gmail.com> >>>>> on Mon, 15 May 2017 16:28:42
2018 Mar 12
2
Bug report: override stopifnot() ?
Hello, I stumbled over a problem: stopifnot(m1 == m2) It works with vector or matrix, but does not work for classes from Matrix package. In the source of stopifnot(), there is all(m1 == m2) that would just work, but there is also is.logical(m1 == m2) that id FALSE. Would it be possible if Matrix package redefined stopifnot() ? (If there is a bug tracking database for package Matrix, I would
2017 May 03
2
stopifnot() does not stop at first non-TRUE argument
Hi, It's surprising that stopifnot() keeps evaluating its arguments after it reaches the first one that is not TRUE: > stopifnot(3 == 5, as.integer(2^32), a <- 12) Error: 3 == 5 is not TRUE In addition: Warning message: In stopifnot(3 == 5, as.integer(2^32), a <- 12) : NAs introduced by coercion to integer range > a [1] 12 The details section in its man
2018 Mar 12
0
Bug report: override stopifnot() ?
Please stop this line of queries/"suggestions/speculations and read the relevant docs **carefully**. For example, from ?"==" "Note Do not use == and != for tests, such as in if expressions, where you must get a single TRUE or FALSE. Unless you are absolutely sure that nothing unusual can happen, you should use the identical
2017 May 19
1
stopifnot() does not stop at first non-TRUE argument
While you are fiddling with stopifnot(), please consider changing the form of the error thrown so that it includes the caller's call. The change would be from something like stop( <<the message>> ) to stop(simpleError( <<the message>>, sys.call(-1))) For the following code f <- function(x, y) { stopifnot(x > y) x - y } g <- function(x,
2017 May 03
2
stopifnot() does not stop at first non-TRUE argument
Not sure why the performance penalty of nonstandard evaluation would be more of a concern here than for something like switch(). If that can't/won't be fixed, what about fixing the man page so it's in sync with the current behavior? Thanks, H. On 05/03/2017 02:26 AM, peter dalgaard wrote: > The first line of stopifnot is > > n <- length(ll <- list(...)) > >
2019 Mar 31
3
stopifnot
Ah, with R 3.5.0 or R 3.4.2, but not with R 3.3.1, 'eval' inside 'for' makes compiled version behave like non-compiled version. options(error = expression(NULL)) library(compiler) enableJIT(0) f <- function(x) for (i in 1) {x; eval(expression(i))} f(is.numeric(y)) # Error: object 'y' not found fc <- cmpfun(f) fc(is.numeric(y)) # Error: object 'y' not found
2019 Jan 03
2
Compiler + stopifnot bug
Hi, I found the following issue in r-devel (2019-01-02 r75945): `foo<-` <- function(x, value) { bar(x) <- value * x x } `bar<-` <- function(x, value) { stopifnot(all(value / x == 1)) x + value } `foo<-` <- compiler::cmpfun(`foo<-`) `bar<-` <- compiler::cmpfun(`bar<-`) x <- c(2, 2) foo(x) <- 1 x # should be c(4, 4) #> [1] 3 3 If the functions